RTIMULib Sensor Fusion Library

Right as mentioned in my last post I have decided not to stick to Polulu’s quite unreliable Arduino sketch that I assembled into a library, because of the significant drift in the results.

Rather, I’ve now (for the time being) settled on richards-tech’s RTIMULib-Arduino library which is a very complex but highly functional library designed specifically for use with the IMU board I’m using (and some others). What this means for me is that I can include the library in my sketch and not have to worry about the inner workings of it for now – although I’d like to produce my own algorithm at some point in the future.

The drawback is that the library comes with very limited documentation: just one readme file in the repository root, as far as I can ascertain, which gives some basic information about how to set it up but not much at all about implementation. The example sketch is even less heplful – lots of references to deeply nested functions and pointers from library files I don’t even know where are, and no explanation. It seems that the library wasn’t designed for ease of use.

Anyway, I’ve had a look through the example sketch, which just prints off the fused Euler angles over serial, and have just about got my head around it. Although I can’t commend the design of the library, I have isolated the variables that I think provide me the information that I need.

For example, in the example file the line that seems to actually print off the results is:

RTMath::displayRollPitchYaw("Pose:", (RTVector3&)fusion.getFusionPose());

Who knows what that means, for lack of any useful comments? With the help of lots of find and replace windows, I found the referenced function inside the library files, and here’s my version of what it does:

Serial.print(" X: ");
Serial.print(((RTVector3&)fusion.getFusionPose()).x()*180/3.1415926535);
Serial.print(" Y: ");
Serial.print(((RTVector3&)fusion.getFusionPose()).y()*180/3.1415926535);
Serial.print(" Z: ");
Serial.print(((RTVector3&)fusion.getFusionPose()).z()*180/3.1415926535);

It seems that `fusion.getFusionPose` is a vector of type `RTVector3&` containing floats `x`, `y` and `z` which are the corresponding Euler angles in radians. So I’ve just converted them to degrees and printed them.

The output of the above looks something like this (there’s some extra pressure/temperature stuff on the end and other lines in the middle from the rest of the code):

Serial print from customised example sketch
Serial print from customised example sketch

Now I need to implement this into a function that can actually integrate with the rest of my main sketch to provide the needed variables when I want them. I’ll also need to go through the library settings to find and, if necessary adjust, sample frequency and other settings like that – or I could redelegate them to my own sketch.

One other point is that I haven’t actually tested the values produced above yet, and probably should – also I will have to figure out a way of zeroing them as this will need to be done for the quadcopter.

3 thoughts to “RTIMULib Sensor Fusion Library”

  1. Thanks for taking the time to share this. I was struggling with this library also. This was the only useful data I could find on the web so far.

  2. I see your blog is in the same niche like my page. Do you allow guest posts?
    I can write unique and interesting posts for you.
    Let me know if you are interested.

  3. Good day I am so excited I found your blog page, I really
    found you by mistake, while I was researching on Google
    for something else, Anyhow I am here now and would just like to say thanks a lot for a incredible post and a all round thrilling blog (I also love the
    theme/design), I don’t have time to read through it all at the minute but I have saved it and also added in your RSS feeds, so when I
    have time I will be back to read a lot more, Please
    do keep up the excellent b.

Leave a Reply

Your email address will not be published. Required fields are marked *