My blog traffic shows that a lot of the visitors are looking for information on IMUs (Inertial Measurement Units) like the MPU-6050. Understanding how to use IMUs and access the data they provide can be daunting. However, I just came across a new Arduino library for getting IMU data that looks like it will make things simpler. Written by a company named Richards-Tech, the library is called RTIMULib, and can be found at https://github.com/richards-tech/RTIMULib-Arduino.
What’s incredibly awesome, and more or less unique about this library is that it comes with well-documented sample programs. I plugged in my MPU-6050, compiled and loaded the program called “ArduinoIMU”, and got what appears to be accurate data right away. The routine provides not only pitch and roll angles, but yaw angles as well, which a complementary filter alone (see the post Gyroscopes and Acceleromters on a Chip for complementary filter information) cannot calculate. Below is a sample from my IMU output. RTIMULib treats the MPU-6050 like a MPU-9150 without a magnetometer. Looking at the output data over time, I see the yaw values drifting somewhat, even when the IMU is stationary. It will be interesting to see how the yaw drift from RTIMULib compares to that from i2cDevLib directly (see MPU-6050: DMP Data from i2cdevlib for information on obtaining data directly from i2cdevlib)
ArduinoIMU starting using device MPU-9150 No valid compass calibration data Pose: roll:115.65 pitch:71.35 yaw:0.62 Pose: roll:115.69 pitch:71.40 yaw:0.99 Pose: roll:115.65 pitch:71.40 yaw:1.16 Sample rate: 52, calculating gyro bias Pose: roll:115.61 pitch:71.40 yaw:1.25 Pose: roll:115.54 pitch:71.37 yaw:1.29 Pose: roll:115.48 pitch:71.38 yaw:1.34 Sample rate: 51, calculating gyro bias Pose: roll:115.47 pitch:71.34 yaw:1.33 Pose: roll:115.43 pitch:71.34 yaw:1.34 Pose: roll:115.39 pitch:71.36 yaw:1.37 Sample rate: 51, calculating gyro bias Pose: roll:115.39 pitch:71.36 yaw:1.36 Pose: roll:115.39 pitch:71.34 yaw:1.36 Pose: roll:115.35 pitch:71.36 yaw:1.37 Sample rate: 51, calculating gyro bias Pose: roll:115.37 pitch:71.35 yaw:1.38 Pose: roll:115.39 pitch:71.35 yaw:1.38 Pose: roll:115.38 pitch:71.35 yaw:1.38 Pose: roll:115.38 pitch:71.35 yaw:1.37 Sample rate: 51, gyro bias valid Pose: roll:115.40 pitch:71.35 yaw:1.37 Pose: roll:115.37 pitch:71.35 yaw:1.37 Pose: roll:115.36 pitch:71.36 yaw:1.38 Sample rate: 51, gyro bias valid Pose: roll:115.37 pitch:71.36 yaw:1.38 Pose: roll:115.36 pitch:71.35 yaw:1.40 Pose: roll:115.38 pitch:71.34 yaw:1.38 ...
I haven’t yet tested this feature, but RTIMULib also gives you the freedom to set the relative weight of the accelerometer and gyroscope in performing data fusion to obtain the orientation angles. All you have to do is change a single parameter that they call the “Slerp” factor. Other parameters are easily configurable, including the freedom to select which sensors (e.g. accelerometer, gyroscope, magnetometer) have their data included in the fusion algorithm to compute the orientation angle. Examples of how to do this are shown in the sample programs they provide.
I found a blog post where Richards-Tech discusses the algorithm used for sensor fusion. Apparently it’s a simplified version of a Kalman filter. They discuss the “Slerp” factor here if you’re looking for more information.
RTIMULib is set up to work with a number of different IMUs. If your IMU contains a magnetometer, RTIMULib has a straightforward-looking calibration routine, and instructions on how to use it. I’ve just ordered a MPU-9150 for my TinyDuino, and will be trying out the calibration routine once it arrives. I wonder if the addition of a magnetometer will eliminate the yaw drift I observed with the MPU-6050.
I haven’t had a chance to explore this library in depth yet, but its relative ease of use already makes it a very appealing option for obtaining IMU data with an Arduino. I’d love to hear feedback from anyone else who has tried it.