Dezibot 4
Loading...
Searching...
No Matches
MotionDetection.h
Go to the documentation of this file.
1
11#ifndef MotionDetection_h
12#define MotionDetection_h
13#include <SPI.h>
14#include <Arduino.h>
15#include "IMU_CMDs.h"
16struct IMUResult{
17 int16_t x;
18 int16_t y;
19 int16_t z;
20};
21enum Axis{
22 xAxis = 0x01,
23 yAxis = 0x02,
24 zAxis = 0x04
25};
26
30};
31
41
49
50
52protected:
54 static const uint frequency = 24000000;
55 static const uint16_t defaultShakeThreshold = 500;
56 const uint bufferLength = 64*16;
57 int8_t* buf = new int8_t[bufferLength];
58 uint8_t readFromRegisterBank(registerBank bank,uint8_t reg);
59 void writeToRegisterBank(registerBank bank, uint8_t reg, uint8_t value);
61
62 uint16_t cmdRead(uint8_t regHigh,uint8_t regLow);
63 uint16_t cmdWrite(uint8_t regHigh,uint8_t regLow);
64 uint8_t cmdRead(uint8_t reg);
65 uint8_t cmdWrite(uint8_t reg);
66
67 uint8_t readRegister(uint8_t reg);
68 int16_t readDoubleRegister(uint8_t lowerReg);
69 void writeRegister(uint8_t reg, uint8_t value);
70 void initFIFO();
71
72 SPIClass * handler = NULL;
73
74 uint gForceCalib = 4050;
75
76
77public:
79
86 void begin(void);
87
93 void end(void);
94
101
108
114 float getTemperature(void);
115
122 int8_t getWhoAmI(void);
123
135 bool isShaken(uint32_t threshold = defaultShakeThreshold,uint8_t axis = xAxis|yAxis|zAxis);
136
151
152
166 Direction getTiltDirection(uint tolerance = 10);
167
176 void calibrateZAxis(uint gforceValue);
177
185 uint getDataFromFIFO(FIFO_Package* buffer);
186};
187#endif //MotionDetection
Direction
@ Front
@ Neutral
@ Back
@ Error
@ Left
@ Flipped
@ Right
@ yAxis
@ zAxis
@ xAxis
uint getDataFromFIFO(FIFO_Package *buffer)
will read all availible packages from fifo, after 40ms Fifo is full
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)
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 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
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.
IMUResult accel
int16_t temperature