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
main.cpp@3:6dbefedce7fe, 2013-08-27 (annotated)
- Committer:
- maetugr
- Date:
- Tue Aug 27 22:18:25 2013 +0000
- Revision:
- 3:6dbefedce7fe
- Parent:
- 1:798db5deb8b9
- Child:
- 4:f62337b907e5
MODSERIAL and unneeded outputs deleted
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:6dbefedce7fe | 27 | // just putting out the angle on console |
maetugr | 1:798db5deb8b9 | 28 | 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 | 29 | wait(0.01); |
maetugr | 0:3e7450f1a938 | 30 | |
maetugr | 0:3e7450f1a938 | 31 | LEDs.tilt(1); |
maetugr | 0:3e7450f1a938 | 32 | } |
maetugr | 0:3e7450f1a938 | 33 | } |