LRT13  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
IMU.h
1 #ifndef IMU_H_
2 #define IMU_H_
3 
4 #include <WPILib.h>
5 #include <I2C.h>
6 #include <DigitalModule.h>
7 
8 #include "../Utils/AsyncPrinter.h"
9 #include "../Process/AsyncProcess.h"
10 #include "../ComponentData/ComponentData.h"
11 #include "../Utils/Defines.h"
12 
13 class IMU : public AsyncProcess
14 {
15  enum IMU_Axis
16  {
17  ACCELEROMETER_X = 0,
18  ACCELEROMETER_Y = 1,
19  ACCELEROMETER_Z = 2,
20  GYROSCOPE_X = 3,
21  GYROSCOPE_Y = 4,
22  GYROSCOPE_Z = 5,
23  };
24 
25  enum IMU_Rotational_Axis
26  {
27  GYROSCOPE_PITCH = 0,
28  GYROSCOPE_ROLL = 1,
29  GYROSCOPE_YAW = 2,
30  };
31 
32 public:
33  static IMU* Instance();
34  static void Finalize();
35 
36  IMU();
37  IMU(UINT8 address, UINT8 module);
38 
39  ~IMU();
40 
41  void construct(UINT8 address, UINT8 moduleNum);
42 
43  INT16 Get(IMU_Axis axis);
44  double GetAngle(IMU_Rotational_Axis axis);
45 
46 private:
47  static IMU* m_me;
48 
49  const static UINT8 kDefaultAddress = 0x29;
50  const static UINT8 kNumPacketsPerGroup = 4;
51  const static UINT8 kPayloadBytesPerPacket = 7 - 1; // -1 for header
52 
53  bool m_enabled;
54  INT16 m_accelerometerGyroscopeValues[6]; // indices correspond to those defined in IMU_Axis
55  double m_gyroscopeAngles[3];
56 
57  UINT8 m_bufferIndex;
58  UINT8 ReadUInt8();
59  INT16 ReadInt16();
60 
61  I2C* m_i2c; // the heart of this code!
62  UINT8 m_internalBuffer[kNumPacketsPerGroup*kPayloadBytesPerPacket];
63 
64  INT8 m_lastPacketID;
65 
66  INT32 Tick();
67 };
68 
69 #endif