Dezibot 4
Loading...
Searching...
No Matches
MotionDetection Class Reference

#include <MotionDetection.h>

Public Member Functions

 MotionDetection ()
 
void begin (void)
 initialized the IMU Component. Wakes the IMU from Standby Set configuration
 
void end (void)
 stops the component Sets the IMU to Low-Power-Mode
 
IMUResult getAcceleration (void)
 Triggers a new Reading of the accelerationvalues and reads them from the IMU.
 
IMUResult getRotation (void)
 Triggers a new reading of the gyroscope and reads the values from the imu.
 
float getTemperature (void)
 Reads the current On Chip temperature of the IMU.
 
int8_t getWhoAmI (void)
 Returns the value of reading the whoAmI register When IMU working correctly, value should be 0x67.
 
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 calculated and checked against threshold. If sum > threshold a shake is detected, else not.
 
Orientation getTilt ()
 calculates how the robot is tilted. It is set, that when the robot is placed normally on a flat table, the result will be (0,0) Tilting the robot, so that the front leg is deeper than the other to results in an increasing degrees, tilting the front leg up will increase negativ degrees Tilting the robot to the right will increase the degrees until 180° (upside down), tilting it left will result in increasing negativ degrees (-1,-2,...,-180). On the top there is a jump of the values from 180->-180 and vice versa.
 
Direction getTiltDirection (uint tolerance=10)
 Checks in which direction (Front, Left, Right, Back) the robot is tilted.
 
void calibrateZAxis (uint gforceValue)
 
uint getDataFromFIFO (FIFO_Package *buffer)
 will read all availible packages from fifo, after 40ms Fifo is full
 

Protected Types

enum  registerBank { MREG1 , MREG2 , MREG3 }
 

Protected Member Functions

uint8_t readFromRegisterBank (registerBank bank, uint8_t reg)
 
void writeToRegisterBank (registerBank bank, uint8_t reg, uint8_t value)
 
void resetRegisterBankAccess ()
 
uint16_t cmdRead (uint8_t regHigh, uint8_t regLow)
 
uint16_t cmdWrite (uint8_t regHigh, uint8_t regLow)
 
uint8_t cmdRead (uint8_t reg)
 
uint8_t cmdWrite (uint8_t reg)
 
uint8_t readRegister (uint8_t reg)
 
int16_t readDoubleRegister (uint8_t lowerReg)
 
void writeRegister (uint8_t reg, uint8_t value)
 
void initFIFO ()
 

Protected Attributes

const uint bufferLength = 64*16
 
int8_t * buf = new int8_t[bufferLength]
 
SPIClass * handler = NULL
 
uint gForceCalib = 4050
 

Static Protected Attributes

static const uint frequency = 24000000
 
static const uint16_t defaultShakeThreshold = 500
 

Detailed Description

Definition at line 51 of file MotionDetection.h.

Member Enumeration Documentation

◆ registerBank

Enumerator
MREG1 
MREG2 
MREG3 

Definition at line 53 of file MotionDetection.h.

Constructor & Destructor Documentation

◆ MotionDetection()

MotionDetection::MotionDetection ( )

Definition at line 4 of file MotionDetection.cpp.

Member Function Documentation

◆ begin()

void MotionDetection::begin ( void )

initialized the IMU Component. Wakes the IMU from Standby Set configuration

Definition at line 8 of file MotionDetection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calibrateZAxis()

void MotionDetection::calibrateZAxis ( uint gforceValue)

can be used to set a custom value for the gforceReading of the zaxis, which will improve the getTiltFunction.

Attention
this method is not persisten, so the value is not stored when the programm is restarted / the robot is powerd off
Parameters
gforceValuethe value the IMU returns for the gravitationforce -> to get this value, place the robot on a leveled surface and read the value getAcceleration().z

Definition at line 74 of file MotionDetection.cpp.

◆ cmdRead() [1/2]

uint8_t MotionDetection::cmdRead ( uint8_t reg)
protected

Definition at line 155 of file MotionDetection.cpp.

◆ cmdRead() [2/2]

uint16_t MotionDetection::cmdRead ( uint8_t regHigh,
uint8_t regLow )
protected
+ Here is the caller graph for this function:

◆ cmdWrite() [1/2]

uint8_t MotionDetection::cmdWrite ( uint8_t reg)
protected

Definition at line 158 of file MotionDetection.cpp.

◆ cmdWrite() [2/2]

uint16_t MotionDetection::cmdWrite ( uint8_t regHigh,
uint8_t regLow )
protected

◆ end()

void MotionDetection::end ( void )

stops the component Sets the IMU to Low-Power-Mode

Definition at line 25 of file MotionDetection.cpp.

+ Here is the call graph for this function:

◆ getAcceleration()

IMUResult MotionDetection::getAcceleration ( void )

Triggers a new Reading of the accelerationvalues and reads them from the IMU.

Returns
IMUResult that contains the new read values

Definition at line 28 of file MotionDetection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDataFromFIFO()

uint MotionDetection::getDataFromFIFO ( FIFO_Package * buffer)

will read all availible packages from fifo, after 40ms Fifo is full

Parameters
bufferpointer to FIFO_Package Struct that at least must have size 64 (this is the max package count with APEX Enabled)
Returns
the amount of acutally fetched packages

Definition at line 245 of file MotionDetection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRotation()

IMUResult MotionDetection::getRotation ( void )

Triggers a new reading of the gyroscope and reads the values from the imu.

Returns
IMUResult

Definition at line 35 of file MotionDetection.cpp.

+ Here is the call graph for this function:

◆ getTemperature()

float MotionDetection::getTemperature ( void )

Reads the current On Chip temperature of the IMU.

Returns
normalized temperature in degree Centigrade

Definition at line 45 of file MotionDetection.cpp.

+ Here is the call graph for this function:

◆ getTilt()

Orientation MotionDetection::getTilt ( )

calculates how the robot is tilted. It is set, that when the robot is placed normally on a flat table, the result will be (0,0) Tilting the robot, so that the front leg is deeper than the other to results in an increasing degrees, tilting the front leg up will increase negativ degrees Tilting the robot to the right will increase the degrees until 180° (upside down), tilting it left will result in increasing negativ degrees (-1,-2,...,-180). On the top there is a jump of the values from 180->-180 and vice versa.

Precision is rounded to 1 deg steps

Attention
The results are only valid, if the robot is not moved in any way during the measurment, as the calculation is made by using the accelration values. If it's detected, that the robot is accelerated while measuring, the method will return max(int). Please note that the imu is pretty sensitiv, even walking next to the table may influcene the result.

Definition at line 78 of file MotionDetection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTiltDirection()

Direction MotionDetection::getTiltDirection ( uint tolerance = 10)

Checks in which direction (Front, Left, Right, Back) the robot is tilted.

Attention
Does only work if the robot is not moving
Parameters
tolerance(optional, default = 10) how many degrees can the robot be tilted, and still will be considerd as neutral.
Returns
Direction the direction in that the robot is tilted most. Front is onsiderd as the direction of driving. If robot is not tilted more than the tolerance in any direction, return is Neutral. If Robot is upside down, return is Flipped. If Robot is moved, return is Error

Definition at line 122 of file MotionDetection.cpp.

+ Here is the call graph for this function:

◆ getWhoAmI()

int8_t MotionDetection::getWhoAmI ( void )

Returns the value of reading the whoAmI register When IMU working correctly, value should be 0x67.

Returns
the value of the whoami register of the ICM-42670

Definition at line 51 of file MotionDetection.cpp.

+ Here is the call graph for this function:

◆ initFIFO()

void MotionDetection::initFIFO ( )
protected

Definition at line 231 of file MotionDetection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isShaken()

bool MotionDetection::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 calculated and checked against threshold. If sum > threshold a shake is detected, else not.

Parameters
threshold(optional) the level of acceleration that must be reached to detect a shake
axis(optional) select which axis should be used for detection. Possible values ar xAxis,yAxis,zAxis It's possible to combine multiple axis with the bitwise or Operator | For Example: to detect x and y axis: axis = xAxis|yAxis
Returns
true if a shake is detected, false else

Definition at line 55 of file MotionDetection.cpp.

+ Here is the call graph for this function:

◆ readDoubleRegister()

int16_t MotionDetection::readDoubleRegister ( uint8_t lowerReg)
protected

◆ readFromRegisterBank()

uint8_t MotionDetection::readFromRegisterBank ( registerBank bank,
uint8_t reg )
protected

Definition at line 173 of file MotionDetection.cpp.

+ Here is the call graph for this function:

◆ readRegister()

uint8_t MotionDetection::readRegister ( uint8_t reg)
protected

Definition at line 162 of file MotionDetection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetRegisterBankAccess()

void MotionDetection::resetRegisterBankAccess ( )
protected

Definition at line 224 of file MotionDetection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeRegister()

void MotionDetection::writeRegister ( uint8_t reg,
uint8_t value )
protected

Definition at line 279 of file MotionDetection.cpp.

+ Here is the caller graph for this function:

◆ writeToRegisterBank()

void MotionDetection::writeToRegisterBank ( registerBank bank,
uint8_t reg,
uint8_t value )
protected

Definition at line 194 of file MotionDetection.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ buf

int8_t* MotionDetection::buf = new int8_t[bufferLength]
protected

Definition at line 57 of file MotionDetection.h.

◆ bufferLength

const uint MotionDetection::bufferLength = 64*16
protected

Definition at line 56 of file MotionDetection.h.

◆ defaultShakeThreshold

const uint16_t MotionDetection::defaultShakeThreshold = 500
staticprotected

Definition at line 55 of file MotionDetection.h.

◆ frequency

const uint MotionDetection::frequency = 24000000
staticprotected

Definition at line 54 of file MotionDetection.h.

◆ gForceCalib

uint MotionDetection::gForceCalib = 4050
protected

Definition at line 74 of file MotionDetection.h.

◆ handler

SPIClass* MotionDetection::handler = NULL
protected

Definition at line 72 of file MotionDetection.h.


The documentation for this class was generated from the following files: