uutzinger / pyIMU

Python implementation of **Quaternion** and **Vector** math for Attitude and Heading Reference System (AHRS) as well as **motion** (acceleration, speed, position) estimation based on a Inertial Measurement Unit (IMU) (accelerometer, gyroscope and optional magnetometer).
MIT License
14 stars 2 forks source link

Sensor orientationmismatch #1

Open robbinhust opened 1 year ago

robbinhust commented 1 year ago

If I use mpu9250 sensor, do I need to adjust the magnetic sensor axis, below is the orientation of the magnetic sensor relative to the 6-axis sensor: https://imgur.com/aEbyCrC

If I am correct then when updating madgwick I would do the following: madgwick.update(gyr=(gx, gy, gz), acc=(ax, ay, az), mag=(my, mx, mz), dt=0.01)

One more thing i see your magnetometer input unit is nT, sensors usually output uT so i will have to multiply it by 1000, right

uutzinger commented 11 months ago

Your sensor axis need to follow the "right hand rule" and the axis for accelerometer, gyroscope and magnetometer need to be the same. So direction x in accelerometer needs to match with x axis in gyroscope or magnetometer. Adjustment would mean that you might need to exchange the axis by placing Y in to X etc. Don't no for your sensor. If you rotate the sensor around the x axis with the right hand rule (x is your thumb, and you rotate in the directions your fingers take when you contract the fingers) the gyroscope needs to create positive number. Otherwise you need to change the sign.

You can check my gearVRC project where I reorganize the sensor axis.

About the magnetometer values, you can check what your sensor delivers and the magnitude should be in the range of what (https://pypi.org/project/AHRS/) predicts at your location, but the units don't matter as long as the readings are calibrated so that magnitude when pointing sensor up is the same as the one when sensor is pointing down (usually not the case without calibration).

Its more important that your accelerometer creates m/s^2 values and gyroscope has correct rotation speed in radians/sec. But even if those are not accurate the fusion still produces values that might be acceptable. Since you have gravity its trivial to measure accelerometer but if you truly want to calibrate gyroscope you need turntable and set it to 45 or 33.333 rpm.