A class to receive data from the SparkFun 9DOF Razor IMU. It can be easily adapted to work with IMUs with different data formats.
imu.h@2:d8b182fbe018, 2011-11-04 (annotated)
- Committer:
- avbotz
- Date:
- Fri Nov 04 22:24:02 2011 +0000
- Revision:
- 2:d8b182fbe018
- Child:
- 3:f04d3d10d518
Appears to parse data correctly (centered around 512), but sometimes we get bad data.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
avbotz |
2:d8b182fbe018 | 1 | #pragma once |
avbotz |
2:d8b182fbe018 | 2 | |
avbotz |
2:d8b182fbe018 | 3 | #include "mbed.h" |
avbotz |
2:d8b182fbe018 | 4 | |
avbotz |
2:d8b182fbe018 | 5 | Serial PC(USBTX, USBRX); |
avbotz |
2:d8b182fbe018 | 6 | |
avbotz |
2:d8b182fbe018 | 7 | DigitalOut myled1(LED1); |
avbotz |
2:d8b182fbe018 | 8 | DigitalOut myled2(LED2); |
avbotz |
2:d8b182fbe018 | 9 | DigitalOut myled3(LED3); |
avbotz |
2:d8b182fbe018 | 10 | DigitalOut myled4(LED4); |
avbotz |
2:d8b182fbe018 | 11 | |
avbotz |
2:d8b182fbe018 | 12 | class IMU{ |
avbotz |
2:d8b182fbe018 | 13 | public: |
avbotz |
2:d8b182fbe018 | 14 | IMU(int baud, PinName tx, PinName rx, Serial* pc); |
avbotz |
2:d8b182fbe018 | 15 | ~IMU(); |
avbotz |
2:d8b182fbe018 | 16 | |
avbotz |
2:d8b182fbe018 | 17 | void getData(); |
avbotz |
2:d8b182fbe018 | 18 | void attach(void (*fptr)(void)); |
avbotz |
2:d8b182fbe018 | 19 | void putc(char c); |
avbotz |
2:d8b182fbe018 | 20 | //void readIMU(); |
avbotz |
2:d8b182fbe018 | 21 | short accX, accY, accZ, gyrX, gyrY, gyrZ, magX, magY, magZ; |
avbotz |
2:d8b182fbe018 | 22 | bool readable; |
avbotz |
2:d8b182fbe018 | 23 | |
avbotz |
2:d8b182fbe018 | 24 | private: |
avbotz |
2:d8b182fbe018 | 25 | Serial* p_device; |
avbotz |
2:d8b182fbe018 | 26 | Serial* p_pc; |
avbotz |
2:d8b182fbe018 | 27 | inline void makeCorrect(short* i); |
avbotz |
2:d8b182fbe018 | 28 | void parse(); |
avbotz |
2:d8b182fbe018 | 29 | |
avbotz |
2:d8b182fbe018 | 30 | int i_IMU; |
avbotz |
2:d8b182fbe018 | 31 | char bufIMU[21]; |
avbotz |
2:d8b182fbe018 | 32 | } imu(57600, p9, p10, &PC); |
avbotz |
2:d8b182fbe018 | 33 | |
avbotz |
2:d8b182fbe018 | 34 | void readIMU(); |