Skip to content
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

Quaternion Filter Drift #125

Open
Jaqos opened this issue Mar 12, 2017 · 21 comments
Open

Quaternion Filter Drift #125

Jaqos opened this issue Mar 12, 2017 · 21 comments

Comments

@Jaqos
Copy link

Jaqos commented Mar 12, 2017

Hello Kris,
Thanks for posting your code, examples and wikis online, they are awesome!

I am getting a small drift when the MPU9250 is put at rest after movements, it looks like a small 5-10° converge to magnetometer.

The filter converges from initial conditions just like the black cube on Open source IMU and AHRS algorithms
In the video when the sensor is placed flat on the desk, there is no drift, where i do see drift when i place my sensor flat on the desk.

My setup:
Original code: MPU9250BasicAHRS
Sketch uploaded to Arduino: MPU9250_Jaqos_GitHub.zip
Board: Arduino Pro Mini 8mhz
Sensor: Sparkfun MPU9250 breakout

I have learned a lot from reading the issues and questions on this GitHub, but haven't found anyone with the same results as me.

The filter is updated 5-6 times every new sensor data, Arduino sends the Quaternion to my computer which is applied visually to a cube in Unity.

The drifting effect is different with different NED orders (north, east, down).
By trial and error, the best order i found was: (ay, az, ax, gy, gz, gx, mx, -mz, my)
north east down

Drift graph: (you can see the blue line slowly moves up when sensor is at rest):
graph

The mag calibration looks good:
calibrated

A video showing the drift:
cube drift

The Questions:

  1. Did you get good results like the x-io video, what board, what sensor?
  2. How do you think i can eliminate the drift?
  3. What is the correct NED order for the Sparkfun MPU9250 breakout?

Thanks for your time ;)

board

@kriswiner
Copy link
Owner

kriswiner commented Mar 12, 2017 via email

@kriswiner
Copy link
Owner

kriswiner commented Mar 12, 2017 via email

@Jaqos
Copy link
Author

Jaqos commented Mar 12, 2017

Thanks, i have changed the Arduino sketch to send raw accelerometer, gyro, magnetometer data to computer. With the Madgwick filter iteration running much faster on my computer, and the drifting looks to be a little smaller.

At some orientations it seems to be noisy, maybe it's the MPU9250 breakout. Should i use a filter to smooth gyro or mag noise?

@kriswiner
Copy link
Owner

kriswiner commented Mar 12, 2017 via email

@Jaqos
Copy link
Author

Jaqos commented Mar 13, 2017

Thanks, I will try adding a low pass filter.

Maybe the drift is because of the NED order, which order is the best for the MPU-9250?

How good are results with the Teensy 3.2 & MPU9250 Teensy 3.X add-on shield?

@kriswiner
Copy link
Owner

The order you are using is correct.

I have done some testing just using the Madgwick filter and with the MPU9250 properly calibrated you should be able to hold +/-4 degree accuracy in heading and +/-1 accuracy in pitch and roll. I usually do not see this kind of drift.

I have always had good results with the MPU9250 using either a Teensy or a Butterfly/Ladybug.

@Jaqos
Copy link
Author

Jaqos commented May 16, 2017

It seems to be some problem related to the magnetometer. And the drift i saw was due to the orientation estimation being incorrect.

I have changed the breadboard setup: replaced the Arduino with an esp8266 for faster speeds running the same Arduino code and a different mpu-9250 breakout board (gy-9250).

I am sending raw data (which looks good) from the sensor to my computer via serial (accelerometer, gyro, mag), doing the motion fusion on the computer and directly applying the quaternion to a cube.

Any IMU code works very well.
All AHRS/MARG code gives strange results.

The motion fusion works when the sensor is rotated on an axis that does not rotate around yaw. And doesn't rotate at all around the yaw axis (relative to earth). This leads me to think that the part of the correction related to gravity works but not compass.

Here is a video, i show how it should rotate, then i turn off the gyro and show how it solves orientation with gravity and compass.

https://youtu.be/GtdHHOppNCs

Results seem to be the same with or without mag calibration, how important is calibration?

what i pass into the function: (-ax, ay, az, gx, -gy, -gz, my, -mx, mz);

What do you think and do you have any suggestions?

Thanks

mpu9250 quaternionFilters.zip

@kriswiner
Copy link
Owner

kriswiner commented May 16, 2017 via email

@Jaqos
Copy link
Author

Jaqos commented May 16, 2017

this is what the plots look like

uncalibrated
caibrated
screen shot 2017-05-16 at 5 03 41 pm

the calibrated My vs Mz plot looks ellipsoidal

the AHRS seems to be the same with and without calibration.

@kriswiner
Copy link
Owner

kriswiner commented May 16, 2017 via email

@Jaqos
Copy link
Author

Jaqos commented Jun 6, 2017

How should the accelerometer be calibrated?

I understand the concepts of mag and gyro calibration, but not accelerometer.

Gyro calibration: (rest on flat surface, read bias)
Mag calibration: (make a prefect sphere)
Accelerometer calibration ??

@kriswiner
Copy link
Owner

kriswiner commented Jun 6, 2017 via email

@myzb
Copy link

myzb commented Jun 14, 2017

I'm encountering the same issue with my Sparkfun MPU, to bad I missed this post before ordering. Basically the sample "cube" I'm rotating on the PC screen slowly moves to kind of the opposite direction after putting the sensor to rest on the table. I assume this is related to the Sparkfun bug.

Before I order the other sensor @kriswiner suggested, I wanted to know if @Jaqos did find a workaround/solution to this.

Just for completion, I'm running this on a Teensy 3.6.

@kriswiner
Copy link
Owner

kriswiner commented Jun 14, 2017 via email

@myzb
Copy link

myzb commented Jun 14, 2017

I started with 'MPU9250_MS5637_AHRS_t3.ino' from your github and #ifdef'd the barometer code. Then I changed the "Serial.send" commands to just send yaw,pitch,roll in order to be able to display the data in the serial plotter. I Also tried with the Sparkfun version. (To rotated the cube on my PC app I added the necessary USB functions to send the quaternion.)

I followed the "figure 8 instructions" during startup so I guess the sensor is 'properly' calibrated?
I'll re-check everything on Friday as I don't have my development board with me atm.

I'll start with a sphere plot of the mag field to get out of doubts. I'll get back to you. Thanks for your time.

@myzb
Copy link

myzb commented Jun 16, 2017

The 'backwards spin' of my cube after putting the sensor to rest, was related to a copy paste error in my code. It is working pretty accurate now.

The only rotation which I'm still not 100% satisfied is of course the yaw component. I guess getting good results, specially indoors will be quite challenging. I was planing to use the IMU to do some AR Headtracking.

These are my calibrated ellipsoids. I think they look quite decent within -400/+400 and centred in the origin. What do you think, any suggestions?

cal_1
cal_2
cal_3

Something else, I saw this comment of yours #152 (comment). I'm just kinda failing to understand why to update at 5-10x the sensor sample rate if the sensor values won't change.

@kriswiner
Copy link
Owner

The fusion method is iterative, it will get closer and closr to a stable answer each time the filter is iterated on a set of sample data.

@Jaqos
Copy link
Author

Jaqos commented Jun 21, 2017

@myzb - check out MagMaster, it can calibrate soft-iron and its easy to use, if the mag plot looks distorted on the Sparkfun MPU-9250, give it a try.
http://diydrones.com/profiles/blogs/advanced-hard-and-soft-iron-magnetometer-calibration-for-dummies
https://github.com/YuriMat/MagMaster

Hi Kris,
i have been researching auto mag calibration, using ellipsoid fitting.

these articles look good:
https://skotagiri.wordpress.com/2010/06/19/c-implementation-for-fitting-an-ellipse-for-a-set-of-points/
http://diydrones.com/forum/topics/magnetometer-soft-and-hard-iron-calibration
https://sites.google.com/site/sailboatinstruments1/c-language-implementation

do you know of any open source ellipsoid fitting algorithms in c# ?

thanks.

@kriswiner
Copy link
Owner

kriswiner commented Jun 21, 2017 via email

@myzb
Copy link

myzb commented Jun 27, 2017

@Jaqos I managed to get a quite decent calibration with the current mag calibration method after a few tries. As I will be using this for head orientation tracking inside of vehicles an more advanced calibration may come in handy down the road. Thanks for the links.

@arkhipenko
Copy link

I would recommend moving to Teensy 3.5 or 3.6. These babies run at 120Mhz and have a math coprocessor...

E-Leask added a commit to E-Leask/autonomousVehicle that referenced this issue Mar 4, 2020
kriswiner/MPU9250#125
Following the discussion here the arduino processor may be a cause of the issue. NodeMcuEsp8266 code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants