I am using matrix creator and I am working with microphones in HAL. I wanted to include compass into my project and I am facing issue with compass demo (matrix-creator-hal/demos/compass_demo.cpp). I tried to rotate with matrix-c and at some point the leds are going crazy (because data in imu_data.yaw are wrong). I know that this problem description is nonsense so I have made a video to better understand what’s the problem
Do you have any tips how to solve this?
Thanks.
Rosta
You might be experiencing a compass calibration problem. First check here about Soft and Hard Iron Effect and the basics of calibration. Simple explanation:
Hard Iron: A hard-iron distortion can be visibly identified by an offset of the origin of the ideal circle from 0,0. Like below:
Soft Iron: Unlike hard-iron distortion where the magnetic field is additive to the earth’s field, soft-iron distortion is the result of material that influences, or distorts, a magnetic field—but does not necessarily generate a magnetic field itself. Like this:
Following that guide should not be hard to implement a Hard iron calibraiton. This is the simplest one and you should get pretty good result after this. For more precise measurements you can try to implement the Soft Iron calibraiton.
You can also see here for implementation reference.
yc/compass calib is even better implemented as it writes the calibration data to the chip itself and uses more fancy other stuff, but the branch is a little bit outdated and needs to be rebased to the latest master branch. and i’m not sure if it works with the current mcu firmware.
I have merged the code from yc/compasscalib to current driver source code on my r-pi and succesfully run the calibration. But it didn’t change anything. Compass-demo was still showing same results.
So I’ve been looking at the variables during running/debugging the calibration. In xy_angle_index variable there was ± correct angle aroung Z axis. So based on this code I have deleted things which I don’t need and I have compass which is showing north on LEDs. Bad thing on this code is that before every run I have to turn the device at least once around Z axis to initialize min/max etc. If someone is interested there is code https://pastebin.com/UAK09GAc
It is not 100% accurate, accuracy is bad when the device is not 100% in horizontal position. But for my usage (I have R-pi with matrix-c on chassis - so it is still in horizontal position) its good enough.
@rostidlo
you could try to adept my tilt correction in the python example using the accel. and be aware on the sensor the the x and z is flipped to the accel. so it’s better to use -mx and not mx int calculating the heading.