for interfacing the sparkfun boards
Dependencies: ADXL345_I2C HMC5883L IMUfilter ITG3200_HelloWorld mbed
main.cpp@0:441caaf895d8, 2014-04-29 (annotated)
- Committer:
- sandwich
- Date:
- Tue Apr 29 00:04:48 2014 +0000
- Revision:
- 0:441caaf895d8
imufilter works. 6dof
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sandwich | 0:441caaf895d8 | 1 | #include "ADXL345_I2C.h" |
sandwich | 0:441caaf895d8 | 2 | #include "ADXL345HL.h" |
sandwich | 0:441caaf895d8 | 3 | #include "ITG3200HL.h" |
sandwich | 0:441caaf895d8 | 4 | |
sandwich | 0:441caaf895d8 | 5 | #include "IMUfilter.h" |
sandwich | 0:441caaf895d8 | 6 | |
sandwich | 0:441caaf895d8 | 7 | |
sandwich | 0:441caaf895d8 | 8 | //ADXL345_I2C accelerometer(p28, p27); |
sandwich | 0:441caaf895d8 | 9 | ADXL345HL accel; |
sandwich | 0:441caaf895d8 | 10 | ITG3200HL gyro; |
sandwich | 0:441caaf895d8 | 11 | //ITG3200 gyro(p28, p27); |
sandwich | 0:441caaf895d8 | 12 | Serial pc(USBTX, USBRX); |
sandwich | 0:441caaf895d8 | 13 | IMUfilter imuFilter(0.1, 10); |
sandwich | 0:441caaf895d8 | 14 | |
sandwich | 0:441caaf895d8 | 15 | int main() |
sandwich | 0:441caaf895d8 | 16 | { |
sandwich | 0:441caaf895d8 | 17 | accel.init(20,4,0.004); |
sandwich | 0:441caaf895d8 | 18 | accel.calibrateAccelerometer(); |
sandwich | 0:441caaf895d8 | 19 | gyro.init(20,4,0.004); |
sandwich | 0:441caaf895d8 | 20 | gyro.calibrate(); |
sandwich | 0:441caaf895d8 | 21 | while (1) { |
sandwich | 0:441caaf895d8 | 22 | |
sandwich | 0:441caaf895d8 | 23 | wait(0.1); |
sandwich | 0:441caaf895d8 | 24 | double* accelreadings=accel.sampleAccelerometer(); |
sandwich | 0:441caaf895d8 | 25 | double* gyroreadings=gyro.sample(); |
sandwich | 0:441caaf895d8 | 26 | imuFilter.updateFilter(gyroreadings[0],gyroreadings[1],gyroreadings[2],accelreadings[0],accelreadings[1],accelreadings[2]); |
sandwich | 0:441caaf895d8 | 27 | imuFilter.computeEuler(); |
sandwich | 0:441caaf895d8 | 28 | pc.printf("roll: %f, pitch: %f, yaw: %f\n", imuFilter.getRoll(), imuFilter.getPitch(), imuFilter.getYaw()); |
sandwich | 0:441caaf895d8 | 29 | //pc.printf("aceelerometer: %f, %f, %f\n", readings[0], readings[1], readings[2]); |
sandwich | 0:441caaf895d8 | 30 | //pc.printf("gyro: %i, %i, %i\n", gyros[0],gyros[1],gyros[2]); |
sandwich | 0:441caaf895d8 | 31 | } |
sandwich | 0:441caaf895d8 | 32 | |
sandwich | 0:441caaf895d8 | 33 | } |