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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "LED.h"        // LEDs framework for blinking ;)
00003 #include "IMU_10DOF.h"  // Complete IMU class for 10DOF-Board (L3G4200D, ADXL345, HMC5883, BMP085)
00004 #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)
00005 
00006 #define RATE            0.002                               // speed of the interrupt for Sensors and PID
00007 
00008 LED         LEDs;
00009 PC          pc(USBTX, USBRX, 921600);   // USB
00010 IMU_10DOF   IMU(p28, p27);
00011 
00012 Ticker Dutycycler;                      // timecontrolled interrupt for exact timed control loop
00013 
00014 void dutycycle() { // method which is called by the Ticker Dutycycler every RATE seconds
00015     IMU.readAngles();
00016 }
00017 
00018 void executer() {
00019     pc.putc(pc.getc());
00020     LEDs.tilt(2);
00021 }
00022 
00023 int main() {
00024     Dutycycler.attach(&dutycycle, RATE);     // start to process all RATE seconds
00025     pc.attach(&executer);
00026     while(1) {
00027         #warning The current version has some hardcoded calibration values, change them in order to get high precision, to find them look out for_ warnings (sorry for_ that hope to get time to develop autocalibration)
00028         // just putting out the angle on console
00029         IMU.readAltitude(); // reading altitude takes much more time than the angles -> don't do this in your fast loop
00030         pc.printf("%.1f,%.1f,%.1f,%.1f'C,%.1fhPa,%.1fmaS,%.5fs,%.5fs\r\n", IMU.angle[0], IMU.angle[1], IMU.angle[2], IMU.temperature, IMU.pressure, IMU.altitude, IMU.dt, IMU.dt_sensors); // Output for Python
00031         
00032         wait(0.01); // this is to avoid buffer overflow in the Computers UART-Controller
00033 
00034         LEDs.tilt(1);
00035     }
00036 }