Kalman filter and MinIMU-9 V3

Hello,

For my project (building an autopilot for my small boat) I am using an Arduino and the MinIMU-9 V3 for directional input. The only sensors I use are the compass (magnetometer) and one of the gyros. I am using a Kalman filter to get a steady heading signal and to calculate the gyro bias.

After some study I still only partly understand the Kalman filter but it I’ve managed to implement it into my project. There is one problem:

When I turn through heading North, the heading changes from 359 to 000. Obviously the Kalman filter needs a little time to stabilize again after this, which would be a problem if I would use my autopilot to steer heading North (000). Simply adding or substracting 360 degrees confuses the filter. Does anyone have any suggestion how to cope with this problem?

Best regards,
Thomas

Hello, Thomas.

We do not have any experience implementing a Kalman filter for the MinIMU-9 v3, but it seems like it might be better if you applied the filter to some other representation of the heading instead of the angle. For example, you could store the sine and the cosine of the heading, and apply the Kalman filter to those values. Converting from the sine and cosine into an actual angle would just be the last step and the angle wouldn’t be fed back into the filter.

You might look at how the extended Kalman filter is implemented in the UM6-LT Orientation Sensor, although it is much more complicated than what you would need because it is calculating the entire orientation of the board and it is using more sensors. The firmware source code is available here:

sourceforge.net/p/um6firmware/co … 0Firmware/

–David

One trick used with PID controllers is to set the desired heading to be zero (always) and pass the error in the actual heading to the controller. See this thread: forum.arduino.cc/index.php?topic=272298.0

I am not looking closely at what you asked, but I’d take a moment to consider whether you need a Kalman filter, and whether a complementary filter might be enough.

Google “Complementary filter vs Kalman” and you’ll find plenty of conversation about this

I just remember enough about Kalman filters that I don’t want to revisit them unless there is clear benefit :). Not super easy for someone not focused on that field to use well. And if you can’t use the best tool well, sometimes it’s better to use the 2nd best tool well than the best tool poorly.

I’m not using a Kalman filter myself, but I guess the same 360-0 crossing should apply to most any filters. The thing is to allow values > 360 or <0 at the filter input but compensate after the filter output. I have an example here:
https://forum.pololu.com/t/lsm303d-a-star-32u4-nmea-0183-compass/7838/1