An fully working IMU-Filter and Sensor drivers for the 10DOF-Board over I2C. All in one simple class. Include, calibrate sensors, call read, get angles. (3D Visualisation code for Python also included) Sensors: L3G4200D, ADXL345, HMC5883, BMP085

Dependencies:   mbed

Committer:
maetugr
Date:
Tue Aug 27 22:01:10 2013 +0000
Revision:
1:798db5deb8b9
Parent:
0:3e7450f1a938
Child:
3:6dbefedce7fe
All in an IMU_10DOF class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maetugr 0:3e7450f1a938 1 #include "mbed.h"
maetugr 0:3e7450f1a938 2 #include "LED.h" // LEDs framework for blinking ;)
maetugr 1:798db5deb8b9 3 #include "IMU_10DOF.h" // Complete IMU class for 10DOF-Board (L3G4200D, ADXL345, HMC5883, BMP085)
maetugr 0:3e7450f1a938 4 #include "PC.h" // Serial Port via USB by Roland Elmiger for debugging with Terminal (driver needed: https://mbed.org/media/downloads/drivers/mbedWinSerial_16466.exe)
maetugr 0:3e7450f1a938 5
maetugr 0:3e7450f1a938 6 #define RATE 0.002 // speed of the interrupt for Sensors and PID
maetugr 0:3e7450f1a938 7
maetugr 0:3e7450f1a938 8 LED LEDs;
maetugr 0:3e7450f1a938 9 PC pc(USBTX, USBRX, 921600); // USB
maetugr 1:798db5deb8b9 10 IMU_10DOF IMU(p28, p27);
maetugr 0:3e7450f1a938 11
maetugr 0:3e7450f1a938 12 Ticker Dutycycler; // timecontrolled interrupt for exact timed control loop
maetugr 0:3e7450f1a938 13
maetugr 0:3e7450f1a938 14 void dutycycle() { // method which is called by the Ticker Dutycycler every RATE seconds
maetugr 1:798db5deb8b9 15 IMU.read();
maetugr 0:3e7450f1a938 16 }
maetugr 0:3e7450f1a938 17
maetugr 0:3e7450f1a938 18 void executer() {
maetugr 0:3e7450f1a938 19 pc.putc(pc.getc());
maetugr 0:3e7450f1a938 20 LEDs.tilt(2);
maetugr 0:3e7450f1a938 21 }
maetugr 0:3e7450f1a938 22
maetugr 0:3e7450f1a938 23 int main() {
maetugr 0:3e7450f1a938 24 Dutycycler.attach(&dutycycle, RATE); // start to process all RATE seconds
maetugr 0:3e7450f1a938 25 pc.attach(&executer);
maetugr 0:3e7450f1a938 26 while(1) {
maetugr 0:3e7450f1a938 27 //pc.printf("G: X:%6.1f Y:%6.1f Z:%6.1f A: X:%6.1f Y:%6.1f Z:%6.1f dt:%1.2f\r\n", Gyro.data[0], Gyro.data[1], Gyro.data[2], Acc.data[0], Acc.data[1], Acc.data[2], dt_sensors*1000);
maetugr 0:3e7450f1a938 28 //pc.printf("Offset: X:%6.1f Y:%6.1f Z:%6.1f dt:%1.2f\r\n", Acc.offset[0], Acc.offset[1], Acc.offset[2], dt_sensors*1000);
maetugr 0:3e7450f1a938 29 //pc.printf("M: X:%6.1f Y:%6.1f Z:%6.1f dt:%1.2f\r\n", Comp.data[0], Comp.data[1], Comp.data[2], dt_sensors*1000);
maetugr 1:798db5deb8b9 30 pc.printf("%f,%f,%f,%3.5fs,%3.5fs\r\n", IMU.angle[0], IMU.angle[1], IMU.angle[2], IMU.dt, IMU.dt_sensors); // Output for Python
maetugr 0:3e7450f1a938 31 wait(0.01);
maetugr 0:3e7450f1a938 32
maetugr 0:3e7450f1a938 33 LEDs.tilt(1);
maetugr 0:3e7450f1a938 34 }
maetugr 0:3e7450f1a938 35 }