GithubHelp home page GithubHelp logo

niru-5 / imusensor Goto Github PK

View Code? Open in Web Editor NEW
98.0 6.0 32.0 126 KB

Python library for communication between raspberry pi and MPU9250 imu

License: MIT License

Python 100.00%
rpi mpu9250 kalman-filter kalman madgwick imu-sensor imu raspberry-pi-3 raspberry-pi python3

imusensor's Introduction

Update

Adding blog links to provide more information about the math behind the code.
IMU Intro - It gives an introduction into IMU working and the math behind calibration and basic idea behind finding roll, pitch and yaw.
Sensor Fusion - This blog goes into math behind kalman filter, Madgwick filter and how they are applied here.
Hands-on Intro - A general overview of getting started.

imusensor

The repo provides a bridge between MPU9250 and raspberry pi. It also lists various caliberation code and filters for getting an accurate orientation from MPU9250 This repo mostly concentrates on the problem of connecting IMU(MPU9250) to raspberry pi through I2C communication.

Pre-requisites

Some of the requirements are to enable I2C in rpi. Installing I2C tools and smbus

sudo apt-get install i2c-tools
sudo pip install smbus

Connect the MPU9250 with rpi using the below connections

Rpi pin MPU9250 pins
pin 3 -> SDA pin
pin 5 -> SCL pin
pin 6 -> Ground(GND)
pin 1 -> VCC

After you have made the connections, type the following command -

sudo i2cdetect -y 1

If you see 68 in the output, then that means the sensor is connected to the rpi and 68 is the address of the sensor.

Basic Usage

The below code is a basic starter for the library

import os
import sys
import time
import smbus

from imusensor.MPU9250 import MPU9250

address = 0x68
bus = smbus.SMBus(1)
imu = MPU9250.MPU9250(bus, address)
imu.begin()
# imu.caliberateGyro()
# imu.caliberateAccelerometer()
# or load your own caliberation file
#imu.loadCalibDataFromFile("/home/pi/calib_real_bolder.json")

while True:
	imu.readSensor()
	imu.computeOrientation()

	print ("roll: {0} ; pitch : {1} ; yaw : {2}".format(imu.roll, imu.pitch, imu.yaw))
	time.sleep(0.1)

Other Functionalities

Setting Accelerometer Range

The accelerometer in MPU9250 has the following ranges of +-2g, +-4g, +-8g and +-16g
You can set this setting by the below command

imu.setAccelRange("AccelRangeSelect2G")

Simiarly for 4g use "AccelRangeSelect4G" and follow similary for 8g and 16g ranges.

Setting Gyroscope Range

Gyroscope sensor in MPU9250 has the following ranges +-250DPS, +-500DPS, +-1000DPS and +-2000DPS
You can set this setting by the below command

imu.setGyroRange("GyroRangeSelect250DPS")

Simiarly for 500DPS use "GyroRangeSelect500DPS" and follow similary for 1000DPS and 2000DPS ranges.
Note: DPS means degrees per second

Setting internal low pass filter frequency

The sensor has an internal low pass filter to remove some basic noise in the values generated by accelerometer and gyrscope.
Use the following command

imu.setLowPassFilterFrequency("AccelLowPassFilter184")
frequency str
5Hz AccelLowPassFilter5
10Hz AccelLowPassFilter10
20Hz AccelLowPassFilter20
41Hz AccelLowPassFilter41
92Hz AccelLowPassFilter92
184Hz AccelLowPassFilter184

Gyroscope Caliberation

Though most sensors are caliberated during manufacturing, however, there still could be a need for caliberation due to various cahnges like being soldered to a breakout board. Gyroscope normally comes with a bias. This can be found by averaging the values when it is kept still and then subtract those values to get the appropriate values.

imu.caliberateGyro()

This will calculate the bias and it is stored in imu.GyroBias You can also set its value, but make sure you give 3x1 numpy array.

Accelerometer Caliberation

This caliberation includes an extra parameter called scale apart from bias. Use the below command

imu.caliberateAccelerometer()

The above function will store the scale and bias in the following variables imu.Accels and imu.AccelBias respectively.

Magnometer Caliberation

This has two types of caliberation

  • imu.caliberateMagApprox() : As the name suggests, this is a near approximation of scale and bias parameters. It saves time however, might not be always accurate. In this the scale and bias are stored in imu.Mags and imu.MagBias respectively.
  • imu.caliberateMagPrecise() : It tries to fit the data to an ellipsoid and is more complicated and time consuming. It gives a 3x3 symmetric transformation matrix(imu.Magtransform) instead of a common 3x1 scale values. The bias variable is imu.MagBias
    For more details on this, have a look at mag_caliberation folder in examples.

IMU Orientation

The computed orientation is in terms of eurler angles. roll for x axis, pitch for y axis and yaw for z axis. We use NED format which basically means, the sensor's x-axis is aligned with north, sensor's y-axis is aligned with east and sensor's x-axis is aligned with down. imu.computeOrientation() The roll, pitch and yaw can be accessed by imu.roll, imu.pitch and imu.yaw. Note: The euler angles will only make sense when all the sensors are properly caliberated.

Filters for sensorfusion

Orientation from accelerometer and magnetometer are noisy, while estimating orientation from gyroscope is noise free but accumulates drift over time. We will combining both of these to obtain more stable orientation. There are multiple ways to do it and we have given two options of kalman and madgwick. You are free to write your own algorithms.

Kalman

It uses gyroscope to estimate the new state. Accelerometer and magnetometer provide the new measured state. The kalman filter aims to find a corrected state from the above two by assuming that both are forms of gaussian distributions. look at kalmanExample.py in examples

import os
import sys
import time
import smbus
import numpy as np

from imusensor.MPU9250 import MPU9250
from imusensor.filters import kalman 

address = 0x68
bus = smbus.SMBus(1)
imu = MPU9250.MPU9250(bus, address)
imu.begin()
# imu.caliberateAccelerometer()
# print ("Acceleration calib successful")
# imu.caliberateMag()
# print ("Mag calib successful")
# or load your caliberation file
# imu.loadCalibDataFromFile("/home/pi/calib_real_bolder.json")

sensorfusion = kalman.Kalman()

imu.readSensor()
imu.computeOrientation()
sensorfusion.roll = imu.roll
sensorfusion.pitch = imu.pitch
sensorfusion.yaw = imu.yaw

count = 0
currTime = time.time()
while True:
	imu.readSensor()
	imu.computeOrientation()
	newTime = time.time()
	dt = newTime - currTime
	currTime = newTime

	sensorfusion.computeAndUpdateRollPitchYaw(imu.AccelVals[0], imu.AccelVals[1], imu.AccelVals[2], imu.GyroVals[0], imu.GyroVals[1], imu.GyroVals[2],\
												imu.MagVals[0], imu.MagVals[1], imu.MagVals[2], dt)

	print("Kalmanroll:{0} KalmanPitch:{1} KalmanYaw:{2} ".format(sensorfusion.roll, sensorfusion.pitch, sensorfusion.yaw))

	time.sleep(0.01)

Madgwick

This is slightly better than kalman and more smooth in giving out the orientation. However, for this to work properly, the sensor fusion needs to run at least 10 times faster frequency than the sensor sampling frequency. look at madgwickExample.py in examples

import os
import sys
import time
import smbus


from imusensor.MPU9250 import MPU9250
from imusensor.filters import madgwick

sensorfusion = madgwick.Madgwick(0.5)

address = 0x68
bus = smbus.SMBus(1)
imu = MPU9250.MPU9250(bus, address)
imu.begin()

# imu.caliberateGyro()
# imu.caliberateAccelerometer()
# or load your own caliberation file
#imu.loadCalibDataFromFile("/home/pi/calib_real4.json")

currTime = time.time()
print_count = 0
while True:
	imu.readSensor()
	for i in range(10):
		newTime = time.time()
		dt = newTime - currTime
		currTime = newTime

		sensorfusion.updateRollPitchYaw(imu.AccelVals[0], imu.AccelVals[1], imu.AccelVals[2], imu.GyroVals[0], \
									imu.GyroVals[1], imu.GyroVals[2], imu.MagVals[0], imu.MagVals[1], imu.MagVals[2], dt)

	if print_count == 2:
		print ("mad roll: {0} ; mad pitch : {1} ; mad yaw : {2}".format(sensorfusion.roll, sensorfusion.pitch, sensorfusion.yaw))
		print_count = 0

	print_count = print_count + 1
	time.sleep(0.01)

For the detailed explanation -> link

Filter comparison

We have also done a small filter comparison of all the filters. This data can be streamed to your computer using zmq and also you can visualize the imu orientation using pygame_viz.py in examples/filters_comparison.

Acknowledgments

Most of the documentation for interfacing MPU9250 with arduino is present. Our work has been inspired by the following works.

  1. bolderflight/MPU9250: This is a nice library for interfacing MPU9250 with arduino.
  2. kriswiner/MPU9250: This is a library for getting some accurate orientation from MPU9250. The author has answered a lot of questions in the issues and most of them are very enlightening for anybody working with IMUs. Highly recommend it.
  3. TKJElectronics/KalmanFilter : This is an implementation of second order kalman filter for IMU when using with arduino.

imusensor's People

Contributors

jdgalviss avatar niru-5 avatar olliewalsh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

imusensor's Issues

[Errno 121] i2c adresses messed up

I'm using your code on a raspberry pi zero with python 3.7 and the board MPU-9250.

the problems :

  • the demonstration code leads to [Errno 121] Remote I/O error
  • the register of the sensor is messed up after the demonstration code

I installed some modules

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install i2c-tools
sudo pip install smbus
pip3 install easydict
pip3 install imusensor

(easydict was not included in the Pre-requisites)

before the demonstration code I probed the i2c. The sensor react as expected.

pi@raspberrypi:~ $ sudo i2cdetect -y 1
0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- 0c -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

then I get the demonstration code from https://pypi.org/project/imusensor/#description

import os
import sys
import time
import smbus

from imusensor.MPU9250 import MPU9250

address = 0x68
bus = smbus.SMBus(1)
imu = MPU9250.MPU9250(bus, address)
imu.begin()
# imu.caliberateGyro()
# imu.caliberateAccelerometer()
# or load your own caliberation file
#imu.loadCalibDataFromFile("/home/pi/calib_real_bolder.json")

while True:
	imu.readSensor()
	imu.computeOrientation()

	print ("roll: {0} ; pitch : {1} ; yaw : {2}".format(imu.roll, imu.pitch, imu.yaw))
	time.sleep(0.1)

run it

pi@raspberrypi:~/Desktop/IMU/02_imusensor $ python3 Check_Instal_imusensor.py 

get the [Errno 121]

Traceback (most recent call last):
  File "Check_Instal_imusensor.py", line 11, in <module>
    imu.begin()
  File "/home/pi/.local/lib/python3.7/site-packages/imusensor/MPU9250/MPU9250.py", line 48, in begin
    self.__writeAK8963Register(self.cfg.Ak8963CNTL1, self.cfg.Ak8963PowerDown)
  File "/home/pi/.local/lib/python3.7/site-packages/imusensor/MPU9250/MPU9250.py", line 551, in __writeAK8963Register
    self.__writeRegister(self.cfg.I2CSlave0Control, self.cfg.I2CSlave0Enable | 1)
  File "/home/pi/.local/lib/python3.7/site-packages/imusensor/MPU9250/MPU9250.py", line 535, in __writeRegister
    val = self.__readRegisters(subaddress,1)
  File "/home/pi/.local/lib/python3.7/site-packages/imusensor/MPU9250/MPU9250.py", line 543, in __readRegisters
    data = self.Bus.read_i2c_block_data(self.cfg.Address, subaddress, count)
OSError: [Errno 121] Remote I/O error

Then checked the i2c

pi@raspberrypi:~/Desktop/IMU/02_imusensor $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 -- -- -- 07 08 09 -- -- -- 0d 0e 0f 
10: -- -- -- -- 14 15 16 -- 18 -- 1a 1b 1c 1d -- -- 
20: -- -- -- -- -- -- -- -- 28 29 2a 2b 2c 2d -- -- 
30: 30 31 -- 33 34 35 36 -- -- 39 3a 3b 3c 3d 3e 3f 
40: -- 41 42 43 44 45 46 -- -- 49 4a -- -- -- -- 4f 
50: -- -- 52 -- 54 55 56 57 -- -- -- -- -- 5d -- 5f 
60: -- -- -- -- -- -- -- -- 68 -- 6a -- -- -- 6e 6f 
70: 70 71 72 -- 74 75 76 77                         

could not believe it so rechecked :

pi@raspberrypi:~/Desktop/IMU/02_imusensor $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 04 -- 06 -- -- -- 0a -- 0c -- 0e -- 
10: -- -- 12 13 14 15 -- 17 -- 19 -- 1b -- -- 1e 1f 
20: 20 -- -- -- -- 25 -- -- -- 29 2a 2b 2c -- 2e -- 
30: -- 31 32 -- 34 -- -- 37 -- 39 -- -- -- -- -- -- 
40: -- -- -- -- -- -- 46 -- -- -- -- -- 4c -- 4e 4f 
50: -- -- -- 53 54 55 -- 57 58 -- -- -- -- -- -- -- 
60: -- 61 -- -- -- 65 66 67 68 69 6a 6b 6c 6d 6e 6f 
70: -- 71 72 73 -- 75 -- --     

with disconnected MPU9250:

pi@raspberrypi:~/Desktop/IMU/02_imusensor $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --     

It seems that the sensor register is not responding as expected :

  • addresses changes from call to call
  • to much addresses

Because there are not many questions about [Errno 121]. I think I'm missing something, there is a high probability the error is on my side.

To investigate this I used piscope from pigpio. http://abyz.me.uk/rpi/pigpio/piscope.html

sudo pigpiod
piscope &

This way I could see the activity on the SDA and SCL pins :
i2C
The SCL doesn't seams to have a constant frequency. Knowing the limitation in the acquisition frequency of pigpio.
Getting back to the first line (line 48) in the error message of the demo code links to power management and clock.
https://cdn.sparkfun.com/assets/learn_tutorials/5/5/0/MPU-9250-Register-Map.pdf

PWR_MGMT_1 : cfg.PowerManagement1 = 0x6B
CLKSEL : cfg.ClockPLL = 0x01

So my questions are:

  • What am I missing?
  • What do I have to do to get my sensor register back?

Does anyone has a working temperatur compensation?

Hi,

MEMS sensors have major issues with changing temperatures.
The MPU9250 fails heavily when the temperature even changes slightly.
Does anyone have a compensation for it that works?

Thanks,
Bjarne

caliberatate results in an "Nan" error

I caliberatate my mpu9250, it's result as follows, but when run kalman by .json file, the yawl info return Nan,why?
%Run complete_caliberation.py
Accel calibration starting
Acceleration calibration is starting and keep placing the IMU in 6 different directions based on the instructions below
Put the IMU in 1 position. Press enter to continue..
[-0.28412242 1.1355439 10.50506506]
[]
[]
[10.505065058365755]
Put the IMU in 2 position. Press enter to continue..
[ 1.13468195 -1.13422702 -8.98501074]
[]
[]
[10.505065058365755, -8.985010735637445]
Put the IMU in 3 position. Press enter to continue..
[ 0.5851727 -9.76096913 1.58245638]
[]
[-9.760969127946899]
[10.505065058365755, -8.985010735637445]
Put the IMU in 4 position. Press enter to continue..
[-0.30771249 9.53003063 -0.44961807]
[]
[-9.760969127946899, 9.53003062668803]
[10.505065058365755, -8.985010735637445]
Put the IMU in 5 position. Press enter to continue..
[-9.43546681 -0.34059852 0.18578156]
[-9.435466814373997]
[-9.760969127946899, 9.53003062668803]
[10.505065058365755, -8.985010735637445]
Put the IMU in 6 position. Press enter to continue..
[9.90379053 0.32024079 1.38590037]
[-9.435466814373997, 9.903790533302814]
[-9.760969127946899, 9.53003062668803]
[10.505065058365755, -8.985010735637445]
Accel calibration Finisehd
[ 0.23748847 -0.11740262 0.76485966]
[1.01420647 1.01674357 1.00635832]
Mag calibration starting
/usr/local/lib/python3.7/dist-packages/imusensor-1.0.1-py3.7.egg/imusensor/MPU9250/MPU9250.py:400: RuntimeWarning: invalid value encountered in double_scalars
Mag calibration Finished
[-4.11800666 25.14775067 5.39850273]
[[nan nan nan]
[nan nan nan]
[nan nan nan]]
[1. 1. 1.]

Gimbal lock may be?

Hi, thank you for the good work.
While working with Kalman filter for orientation, I have noticed that if the pitch value goes to 90 degrees, the angular measurements go crazy afterward. I can see many unwanted spikes in the readings after the pitch=90 condition. I think it is due to gimbal lock.
Any thoughts? Please look at the roll and yaw after the suspected gimbal lock.

gimbal_lock

Can´t read the magnetometer

Hello, I am trying this code for the MPU9250 and I am able to obtain the pitch and roll orientations, but I am not able to read the magnetometer for the yaw estimation. This is what I get when running the script:
image

It seems that the script is not able to configure the magnetometer, when looking into its registers this is what I found:

image

Neither the Id and the name of the sensor seems right, do you have any advice on how to fix it?

Thanks in advance

Josué

async I2C enhancement

I have been looking for an asynchronous implementation of I2C to interface with an MPU9250. I think this would be great to counter the extra overhead we'd get with the normal I2C polling on limited raspberry pi hardware.

Maybe this should be handled in a separate repo, but I think this library would plug in nicely. https://github.com/jabdoa2/smbus2_asyncio

I haven't tried imusensor yet but it seems like it would be straight forward to convert your smbus calls to async. This library could run the asynchronous task internally and raster or record the results, appearing synchronous to the user.

Unfortunately I'm currently in a bit of a rush to finish something, so I think I'm going to use threads to start but wanted to share this idea :)

Error in Magnetometer precise Calibration

I am getting the following error and invalid value of yaw-

mag precise is claibrating
/home/pi/.pyenv/versions/instalimb/lib/python3.8/site-packages/imusensor/MPU9250/MPU9250.py:400: RuntimeWarning: invalid value encountered in double_scalars
r = (a * b * c) ** (1. / 3.)
Done Calibrating MAG
roll: -176.23316858291108 ; pitch : -0.9488874320033538 ; yaw : nan
roll: -176.11579914390077 ; pitch : -0.9432215036079428 ; yaw : nan
roll: -176.1911116954199 ; pitch : -0.9515163948412073 ; yaw : nan

P.S. without using calibration I am getting valid values of yaw.

Can't install smbus

I'm not able to install smbus, it doesn't find it packages. Is the only way installing it from source?

Yaw changes when roll and/or pitch change

I have noticed that when using the IMU with the madgwick filter, the yaw changes when the IMU is tilted either in its roll or pitch axis even if there is no movement in the yaw axis. This error is significant enough to be 20 degrees or more in some cases. I understand that this error can happen when the values from the IMU are not fed into the filter in the NED space but from what I understand, that has been implemented in the MPU9250.py file already, so what gives? Is this happening with anyone else and what are the possible fixes for this?

Wrong message being displayed

You have done a good job with the library. Thank you!
But I have a problem/question with the code in lines 54-56 of the MPU9250 module.
The code which you have written is:

		name = self.__whoAmI()
		if not `(name[0] == 113 | name[0] == 115 ):`
			print ("The name is wrong {0}".format(name))

So the returning value from sensor is 0x71 which is value equals 113.
If the code is the (name[0] == 113) is True; the (name[0] == 115) is False so the full condition (name[0] == 113 | name[0] == 115 ): is False. if not gives the True value and as a results the print line is executed and in my opinion the line should not be executed (because the sensor has proper value read by __whoAmI function.
So my question is it is some mistake or I don't understand something properly?
Thank You for work, help and explanation.

PyPi claims v1.0.1 but has old files - Git repo installs as same v1.0.1 but has newer files

PyPi claims imusensor is v1.0.1 but does not contain the latest files, e.g. "replaced name test with logical or ('|')"
github latest installs as same version v1.0.1 but is clearly later than PyPi v1.0.1

installed from pypi (then removed) with:

pip3 install imusensor
..
The name is wrong [113]
..
pip3 uninstall imusensor
  • =======
    Installed from git (to Ubuntu 22.04 on Raspberry Pi4) with:
git clone https://github.com/niru-5/imusensor.git
cd imusensor
python3 setup.py build
sudo python3 setup.py install
..
Installed /usr/local/lib/python3.10/dist-packages/imusensor-1.0.1-py3.10.egg
Processing dependencies for imusensor==1.0.1
Finished processing dependencies for imusensor==1.0.1

Magnetometer Calibration Procedure Inquiry

Hello @niru-5,

I hope you are doing well!
I have a few questions regarding the Magnetometer calibration process - how exactly does one properly calibrate the Magnetometer?
Your blog post states to rotate the sensor in a "figure 8" shape but how exactly is this done? Would you be able to demonstrate this using pictures or video for further clarity?

After calibration of the Magnetometer, when the sensor is stationary and I run the Jupyter Notebook script, three separate ellipsoids appear in separate regions in the plot. Is that a result of a good calibration or does that show remaining undesired magnetic effects?

Thank you so much for your help!

caliberateAccelerometer() results in an error!

Whenever I activate calibrateAccelerometer() and after the 6 obligate positions, I get IndexError: list index out of range
see below

"..
Put the IMU in 6 position
[-3.65328894 9.16576421 3.43421432]
[9.416180537422752, -10.05599768734264]
[8.000009931792171, 9.165764213321125]
[-7.225422289768825]
Traceback (most recent call last):
File "kalman.py", line 29, in
imu.caliberateAccelerometer()
File "/home/pi/.local/lib/python3.7/site-packages/imusensor/MPU9250/MPU9250.py", line 307, in caliberateAccelerometer
self.AccelBias[2] = -1*(zscale[0] + zscale[1])/(abs(zscale[0]) + abs(zscale[1]))
IndexError: list index out of range
"
Can you help?
I need calibration, the values are going too much up and down. Trying to use the 9250 for a 2 wheel balancing robot.
Kp me informed

caliberateMag

Hi niru ,
After uploading the checkingSavingAndLoadingCalibInfo.py in the rpi , the acceleration calibration is done successfully. I m facing issue with caliberatemag() function , the error is that 'MPU9250' object has no attribute 'caliberatemag'.

Thanks

Madwick filter computation

Hi - when i apply the madgwick filter, the values seem to be out of sync with the base case values or those that of the K filter. While going through Kris Winer's code, he has commented the below quoted points while computing the Quaternions. Is this something that you have considered?

"Sensors x (y)-axis of the accelerometer/gyro is aligned with the y (x)-axis of the magnetometer;
the magnetometer z-axis (+ down) is misaligned with z-axis (+ up) of accelerometer and gyro!
We have to make some allowance for this orientation mismatch in feeding the output to the quaternion filter.
For the MPU9250+MS5637 Mini breakout the +x accel/gyro is North, then -y accel/gyro is East. So if we want te quaternions properly aligned we need to feed into the Madgwick function Ax, -Ay, -Az, Gx, -Gy, -Gz, My, -Mx, and Mz. But because gravity is by convention positive down, we need to invert the accel data, so we pass -Ax, Ay, Az, Gx, -Gy, -Gz, My, -Mx, and Mz into the Madgwick function to get North along the accel +x-axis, East along the accel -y-axis, and Down along the accel -z-axis.
This orientation choice can be modified to allow any convenient (non-NED) orientation convention. Pass gyro rate as rad/s"

'name is wrong [113]'

hello,
this is not particularly an error but when i initially run the kalman filter code, it 'prints' on the console <The name is wrong [113]> after which it takes about a second and then starts giving the roll,pitch,yaw value. Is it something to be concerned about? Also how to remove this message?

Thanks in advance

Couple questions and issues...

Line 93: Is there a reason for running self.caliberateGyro() on every begin()?

Lines 44, 52, 89: PowerManagement1 is written with ClockPLL three times. Is there a reason this is necessary that isn't evident to me?

About the default orientation

Thanks for the great work.

I am a newbie with IMUs.

when I run the Basic Usage code, I get Orientation output like:

roll: 178.8470066832591 ; pitch : 0.10481996839275354 ; yaw : 123.34091836135526

My MPU9250 board is placed horizontally on the desktop, my question is, how do I reset these values to zeros
at the beginning or these values are based on the world coordinate system which will change only when the direction of the board changes ?

Thanks.

Kalman Example Issues

Installing this on a mobile robot but am having issues when running the Kalman example:

kalmanExample.py
AccelRangeSelect2G is not a proper value for accelerometer range
{0} is not a proper value for gyroscope range
AccelLowPassFilter184 is not a proper value forlow pass filter
Traceback (most recent call last):
File "kalmanExample.py", line 20, in
imu.begin()
File "/home/pi/adeept_rasptankpro/testCode/imusensor/imusensor/MPU9250/MPU9250.py", line 97, in begin
self.caliberateGyro()
File "/home/pi/adeept_rasptankpro/testCode/imusensor/imusensor/MPU9250/MPU9250.py", line 253, in caliberateGyro
currentGyroRange = self.GyroRange
AttributeError: 'MPU9250' object has no attribute 'GyroRange'

IMU basic_starter.py runtime errors

Raspberry Pi 4/4G Ubuntu 22.04/ROS 2 Humble with PyPi imusensor library installed. mpu9250 correctly connected to i2C 1 address 68.

Running a ros2 package it has calibration data for acceleration_bias, gyro_bias magnetometer_bias and successfully publishes orientation, angular velocity, Linear acceleration data

However, as I would like the calibrate the mpu9250, I ran these scripts from this repository with these logs with IMU fixed in position.
basic_starter.py

ubuntu@rp4-ub22h-mt:~/imu$ python3 basic_starter.py
The name is wrong [112]
The mag name is different and it is [0]
looks like it did not write properly
looks like it did not write properly
looks like it did not write properly
looks like it did not write properly
looks like it did not write properly
/home/ubuntu/.local/lib/python3.10/site-packages/imusensor/MPU9250/MPU9250.py:521: RuntimeWarning: invalid value encountered in divide
normMagVals = self.MagVals/magLength
roll: 179.4388073106308 ; pitch : -6.540237823437541 ; yaw : nan
roll: 178.84802350813396 ; pitch : -2.457731262926437 ; yaw : nan
.
.
.

identical log with imuExtraction.py

Could you suggest troubleshooting to enable adjusting calibration?

Connecting i2c to EDA/ECL

Hi niru-5

Thank you for working on this library! It has made working on my project much easier.

Just wanted to double check if there is a need to connect ECA/ECL lines on the MPU9250 to the SCL/SDA of my RPI as that contains information of the magnetometer? I've seen some other tutorials that requires us to do this but in the README it doesn't say that.

Found this from here: https://makersportal.com/blog/2019/11/11/raspberry-pi-python-accelerometer-gyroscope-magnetometer

calibration procedure

Hello, When calibrating Accelerometer, it asks for placing it in 6 direction. I know that the 6 directions are for positive and negative X,Y and Z axes but i get a message saying 'an external force might be acting upon it'.
What am i doing wrong? Also, what is the particular order for placement in 6 directions?
Also i believe, for calibrating Mag, i have to rotate in the 'shape' of 8 or more like in the shape of infinity symbol . Am i correct?
And it's my understanding that i should keep the IMU still for Gyro calibration. Is this correct?

It would be really great if you could provide a guide for calibration along with the package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.