Porting MinIMU-9 v3 code to mbed

Hello all,

I am in the process of porting the Arduino code for the MinIMU-9 v3 to mbed. I have been able to get the code to talk and get data from the devices, but am still working on getting the calculations correct for the drift corrected angles (yaw, pitch, roll). In the main loop in the Arduino code, it should look something like the following. Could someone tell me what ‘normal’ values are for the sensor lying still and flat right before all the calculations? The raw data should be in gyro_x, gyro_y, gyro_z, magnetom_x, magnetom_y, magnetom_z, accel_x, accel_y, accel_z after Read_Gyro(), Read_Accel(), Read_Compass().

  Read_Gyro();   // This read gyro data
  Read_Accel();     // Read I2C accelerometer

  if (counter > 5)  // Read compass data at 10Hz... (5 loop runs)
  {
    counter=0;
    Read_Compass();    // Read I2C magnetometer
    Compass_Heading(); // Calculate magnetic heading  
  }

  //I'm looking for the values of gyro_x, gyro_y, gyro_z, magnetom_x, magnetom_y, magnetom_z, accel_x, accel_y, accel_z here to see if the data is being read properly before the calculations.

  // Calculations...
  Matrix_update();
  Normalize();
  Drift_correction();
  Euler_angles();

Hello.

I just ran our AHRS code on a MinIMU-9 that I plugged into a breadboard on my desk (so the board was sitting relatively flat and still), and modified the Output.ino and MinIMU9AHRS.ino files to output the specific values you mentioned. The code already applies a zero rate offset correction to each of the raw readings from the gyroscope and accelerometer, so most values are basically centered around zero, with the exception of the Z axis accelerometer reading (which should be around 256, indicating an acceleration due to gravity of 1 g) and the magnetometer readings.

G: -2,1,-2 A: 0,1,254 M: -3514,-39,-1132
G: 0,1,-2 A: 0,1,256 M: -3514,-39,-1132
G: -1,0,-1 A: 0,1,256 M: -3514,-39,-1132
G: -1,0,-3 A: 0,1,256 M: -3514,-39,-1132
G: -1,0,0 A: 0,1,257 M: -3514,-39,-1132
G: 1,-2,-1 A: 2,1,256 M: -3514,-39,-1132
G: -1,0,-2 A: 1,1,255 M: -3514,-39,-1132
G: -1,4,1 A: 1,1,256 M: -3514,-39,-1132

(The sample values are basically arranged in the order you listed them, with X, Y, Z values of each sensor from left to right.)

-Jon

Thanks so much! Now to check my values and see where my bug lies!

Josh

My Accelerometer values are right on. But my Gyro readings look too big as it is sitting still. I’m not sure what type of readings the Magnometer should read, obviously it depends on its orientation and I would assume long/lat as well.

I got:
G -36 -2 -65 A 0 1 256 M 521 -1163 -1856

I’ll keep looking into it, but if anyone can confirm that the Gyro and Mag numbers are in the ballpark or way off, let me know.

Josh

It seems like your magnetometer and accelerometer values are fine since they are in the same ballpark. As for the gyroscope, are you making sure the IMU is stationary when the AHRS program is starting up? If you are, there might be an issue with your gyro initialization/calibration code.

-Jon

Exactly. I thought that I was keeping the board stable during startup, but I think it was picking up subtle vibrations. When I lengthened the delay before calibrating, the gyro values went to near zero. So that is fixed.

So all the values I am reading from the board look good. It’s just that the calculations aren’t working and I can’t get yaw, pitch, and roll. I would have thought that the calculations would be the most portable part of the code. Anyway, I’ll dig deeper and see where the error lies. For now, I at least can see that Compass_Heading() isn’t working. When I try to print MAG_Heading I get nan…

Josh

I finally got it working. Turns out I ported the code to get the time wrong… Watch those units!

Josh

That’s great! If you are willing to share here, it could make it a good resource for anyone else using the MinIMU-9 with an mbed.

-Jon