Dezibot 4
MotionDetection.h
Go to the documentation of this file.
1 
13 #ifndef MotionDetection_h
14 #define MotionDetection_h
15 #include <SPI.h>
16 #include <Arduino.h>
17 #include "IMU_CMDs.h"
18 struct IMUResult{
19  int16_t x;
20  int16_t y;
21  int16_t z;
22 };
23 enum Axis{
24  xAxis = 0x01,
25  yAxis = 0x02,
26  zAxis = 0x04
27 };
28 
29 struct Orientation{
30  int xRotation;
31  int yRotation;
32 };
33 
34 enum Direction{
41  Error
42 };
43 
44 struct FIFO_Package{
45  int8_t header;
48  int16_t temperature;
49  int16_t timestamp;
50 };
51 
52 
54 protected:
56  static const uint frequency = 24000000;
57  static const uint16_t defaultShakeThreshold = 500;
58  const uint bufferLength = 64*16;
59  int8_t* buf = new int8_t[bufferLength];
60  uint8_t readFromRegisterBank(registerBank bank,uint8_t reg);
61  void writeToRegisterBank(registerBank bank, uint8_t reg, uint8_t value);
63 
64  uint16_t cmdRead(uint8_t regHigh,uint8_t regLow);
65  uint16_t cmdWrite(uint8_t regHigh,uint8_t regLow);
66  uint8_t cmdRead(uint8_t reg);
67  uint8_t cmdWrite(uint8_t reg);
68 
69  uint8_t readRegister(uint8_t reg);
70  int16_t readDoubleRegister(uint8_t lowerReg);
71  void writeRegister(uint8_t reg, uint8_t value);
77  void initFIFO(void);
83  void startFIFO(void);
89  void stopFIFO(void);
90 
91  SPIClass * handler = NULL;
92 
93  uint gForceCalib = 2050;
94 
95 
96 public:
98 
105  void begin(void);
106 
112  void end(void);
113 
120 
126  IMUResult getRotation(void);
127 
133  float getTemperature(void);
134 
141  int8_t getWhoAmI(void);
142 
154  bool isShaken(uint32_t threshold = defaultShakeThreshold,uint8_t axis = xAxis|yAxis|zAxis);
155 
170 
171 
185  Direction getTiltDirection(uint tolerance = 10);
186 
195  void calibrateZAxis(uint gforceValue);
196 
205  uint getDataFromFIFO(FIFO_Package* buffer);
206 
212  friend class Motion;
213 };
214 #endif //MotionDetection
Direction
@ Front
@ Neutral
@ Back
@ Error
@ Left
@ Flipped
@ Right
Axis
@ yAxis
@ zAxis
@ xAxis
void stopFIFO(void)
stops writing results to FIFO-Storage needs to be called before Data Registers (such as GYRO_DATA_*,...
uint getDataFromFIFO(FIFO_Package *buffer)
will read all availible packages from fifo, after 40ms Fifo is full Only works when startFIFO was cal...
uint16_t cmdWrite(uint8_t regHigh, uint8_t regLow)
const uint bufferLength
static const uint16_t defaultShakeThreshold
bool isShaken(uint32_t threshold=defaultShakeThreshold, uint8_t axis=xAxis|yAxis|zAxis)
Detects if at the time of calling is shaken. Therefore the sum over all accelerationvalues is calcula...
uint8_t readFromRegisterBank(registerBank bank, uint8_t reg)
uint16_t cmdRead(uint8_t regHigh, uint8_t regLow)
uint8_t readRegister(uint8_t reg)
void resetRegisterBankAccess()
Orientation getTilt()
calculates how the robot is tilted. It is set, that when the robot is placed normally on a flat table...
int8_t getWhoAmI(void)
Returns the value of reading the whoAmI register When IMU working correctly, value should be 0x67.
static const uint frequency
IMUResult getRotation(void)
Triggers a new reading of the gyroscope and reads the values from the imu.
Direction getTiltDirection(uint tolerance=10)
Checks in which direction (Front, Left, Right, Back) the robot is tilted.
void calibrateZAxis(uint gforceValue)
void startFIFO(void)
starts writing the measurment results to the FIFO-Storage
void end(void)
stops the component Sets the IMU to Low-Power-Mode
void writeRegister(uint8_t reg, uint8_t value)
void writeToRegisterBank(registerBank bank, uint8_t reg, uint8_t value)
int16_t readDoubleRegister(uint8_t lowerReg)
void begin(void)
initialized the IMU Component. Wakes the IMU from Standby Set configuration
SPIClass * handler
void initFIFO(void)
makes all settings necessary so it is possible to use the FIFO, but does not actually start writing p...
IMUResult getAcceleration(void)
Triggers a new Reading of the accelerationvalues and reads them from the IMU.
float getTemperature(void)
Reads the current On Chip temperature of the IMU.
Definition: Motion.h:59
IMUResult accel
int16_t timestamp
IMUResult gyro
int16_t temperature