4

I have an MPU9250 on my PCB and I use an AHRS system with a Madgwick filter to get yaw angle. I took source code from here: https://github.com/sonphambk/MPU9250/tree/master/Src and changed there MadgwickAHRSupdate function as someone said here: Madgwick sensor fusion on LSM9DS0. Now yaw angle is quite accurate, but there is a problem. When I move my PCB, without rotating it, the yaw angle changes like that: enter image description here

Why does the yaw angle changes if I don't rotate my PCB? What I have to change in my code?

crackanddie
  • 688
  • 1
  • 6
  • 20

1 Answers1

2

You have to keep in mind that AHRS is a mathematically super complex problem. A small error at the start of data processing may cause a huge deviation sometime later. If you know for sure, that provided code was used by others and they did not have drifts, then I would suggest checking the raw data stream of the sensor. If MPU9250 was bought from Chinese vendors or Ebay it is a good chance they are non-usable. Checking voltages, the output signal to noise ratio, sample rate consistencies is a must.

If you think that the hardware part works perfectly, try Kalman filters or filtering the input data. Also, ambient conditions might affect sensor reads - magnetic fields, heat, etc.

P.S. Moving PCB without rotation is not as innocent as you may guess. Human hands are constantly shaking and generating noise.

Aplamis
  • 136
  • 5
  • 1
    Thanks for the answer. I used IMU system before AHRS and it worked as expected. I checked every sensor - gyro, accelerometer and magnetometer, and they also work as expected. "P.S. Moving PCB without rotation is not as innocent as you may guess. Human hands are constantly shaking and generating noise." - I moved it in a straight and level surface, so it couldn't be rotated. " try Kalman filters" - I can't find kalman filter for gyro, accel and magnetometer – crackanddie Dec 12 '21 at 11:19
  • 1
    Kalman filter also didn't help me. https://github.com/suhetao/stm32f4_mpu9250 - I took code code blocks from here and used *miniAHRS.h* header. The result is the same, yaw angle goes away when I move controller. – crackanddie Dec 15 '21 at 11:42
  • Could you provide graphs of raw accelerometer and gyro output data in time vs error rate? – Aplamis Dec 16 '21 at 16:30
  • I understood that it is because of magnetometer. See the question here: https://electronics.stackexchange.com/questions/600577/why-do-magnetometer-values-change-when-i-move-pcb – crackanddie Dec 16 '21 at 17:32