For my project i need a way to determine correct orientation of the rocket.
I took code for Madgwick filter from here
https://github.com/morgil/madgwick_py
for collecting data i used Arduino Nano + MPU9250 sensor. This setup sends packets every 12ms to my PC via Serial.
I calibrated magnetometer by calculating biases to "align" axis origin and center of sphere, created by set of measurements.
Then i drew coordinate axis with blender:
and coded some script for it - quaternion.py It just reads values from serial, feeds them into Filter, and then rotates my axis object using quaternion rotation mode.
I screwed up with orientation of model's X axis a little bit, so when i rotate my board clockwise, axis on the screen rotates counter-clockwise. I flipped signs of all X components, and it became fine.
According to this picture
i flipped X and Y axis and sign of Z axis, to align axis of magnetometer with gyroscope + accelerometer
And it almost works with one small exception - when after "stabilization" i tilt i.e. X axis downwards (or Y axis, doesnt matter) this axis starts drifting toward global X-Y plane. If i tilt axis upwards, remaining axis starts drifting around global O-Z axis, like this
X axis downwards
And when x axis upwards
Speed of that drift depends on Beta of Madgwick filter - the more beta the more drift.
What can be done there?