Monday, August 24, 2015

Roll/Pitch estimation with an IMU

For some reason I've been suddenly yearning to learn more about attitude estimation. So, over the last two weeks, I've spent a good part of many evenings trying to figure out the maths behind this.

Initially, I was following the A Guide To using IMU in embedded applications. At the start, the maths was ok, and I learnt a fair few things, but towards the end I was unable to understand how the yaw estimation is done (I have read that yaw estimation without a magnetometer is basically dead reckoning; lots of drift.), and simply implementing the instructions the best I could unfortunately did not yield any results.

Next, I found this other tutorial, Reading a IMU Without Kalman: The complementary filter. Based on Pieter's post, I got my roll/pitch estimation working in short order. I am still not 100% understanding how the complementary filter works, so I'm going to spend some more time looking at the values closely.

The Teensy 3.1 is a new mcu for me, but I've worked with the Teensy 2, and the way it works in the Arduino software package appears to be very similar for my newbie needs. I was having difficulty trying to get timed function calls to work with the various built-in arduino packages e.g. timerOne, but finally found IntervalTimer and it works a treat. I have my code block execute every 10 milliseconds, and the code takes less than 2 milliseconds to execute. Lots of spare time! Must be the Cortex M4 running at 96Mhz :3

The sparkfun board was very well thought out, for my needs, almost everything was setup on the board, from pullup resistors to the setting of the i2c addresses. All I had to do was connect the vcc/gnd and i2c data/clock lines, and that was it! The library provided by Sparkfun also worked with no drama. Very, very slick. I like this!

The Processing sketch was also _rather_ straightfoward. Apart from the fact that it was using the left hand co-ordinate system and confused me utterly till I went through some examples. The Teensy sends out the roll/pitch values after every timestep, and inside processing, I use the serial event handler to call a drawing function when new serial data is sent. Easy.

Now that I have a reasonably working IMU, I am going to use it to learn about PID Control before I try to figure out the Madgwick Algorithm for using the magnetometer as well.

No comments: