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:
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):
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.