-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
caliberateAccelerometer() results in an error! #2
Comments
Hi Patrick, 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 ("Accel x: {0} ; Accel y : {1} ; Accel z : {2}".format(imu.AccelVals[0], imu.AccelVals[1], imu.AccelVals[2]))
time.sleep(0.1) Use the above code to see the acceleration value in all directions. If you get roughly equal to 9.8 or close to it, that tells that the accelerometer has been properly calibrated at the factory itself, you might not need any change. import smbus
import numpy as np
import sys
import os
import time
from imusensor.MPU9250 import MPU9250
address = 0x68
bus = smbus.SMBus(1)
imu = MPU9250.MPU9250(bus, address)
imu.begin()
print ("Gyro caliberation starting")
imu.caliberateGyro()
print ("Gyro caliberation finished")
print ("Accel caliberation starting")
imu.caliberateAccelerometer()
print ("Accel caliberation Finisehd")
print (imu.AccelBias)
print (imu.Accels)
imu.saveCalibDataToFile("/your_path/calib.json") Make sure to give your path and also make sure it has .json at the end for the function imu.saveCalibDataToFile() Once you have all the calibration saved, you can directly call the calibration file using imu.loadCalibDataFromFile and check the accelerometer values again. 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("/your_path/calib.json")
while True:
imu.readSensor()
imu.computeOrientation()
print ("Accel x: {0} ; Accel y : {1} ; Accel z : {2}".format(imu.AccelVals[0], imu.AccelVals[1], imu.AccelVals[2]))
print ("roll: {0} ; pitch : {1} ; yaw : {2}".format(imu.roll, imu.pitch, imu.yaw))
time.sleep(0.1) You can also have a look at the orientation computed as well. However, yaw might not be accurate until the magnetometer calibration is not done. I have tested the above code once and I get the following axes values I felt most variations are around 8 to 11, but below 7, I felt it could be due to other external forces as well and hence put a check for it. I hope if the sensor properly placed should be able to calibrate. If you still face a problem or the above error, let me know. I hope the above steps help. If your curious understand the calibration process for accelerometer, it is as follows -> In ideal conditions, the raw_sensor_val should read +-g when its axis is parallel to Earth's g. This is isn't always the case and hence we get two more parameters scale and bias. sensor_val = (scale)*raw_sensor_val + bias From the above two equations we can find scale and bias In the code, I find raw_sensor_val_1 and raw_sensor_val_2 by averaging over 100 values in that respective position. |
Hi, I have updated the package with a small change in the calibration of accelerometer. Note: |
Thx, after updating ; error solved |
It is strange to see such drastic changes. Were the values any better after calibration? About accessing DMP and a lot of its features, I will be working on it and update you when we release it. However, It could take a while, in the mean time, you can use the code of underlying commands like _write_register and _read_registers to your advantage. These functions are undocumented but you can get an idea when you see the code. They are present in imusensor/MPU9250/MPU9250.py Thanks |
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
The text was updated successfully, but these errors were encountered: