Implemented ShakeDetection

This commit is contained in:
hhaupt 2024-06-12 00:03:29 +02:00
parent 080563f6cc
commit 4a6a58e35f
3 changed files with 39 additions and 3 deletions

View File

@ -0,0 +1,19 @@
#include "Dezibot.h"
Dezibot dezibot = Dezibot();
void setup() {
// put your setup code here, to run once:
dezibot.begin();
dezibot.multiColorLight.turnOffLed();
}
void loop() {
// put your main code here, to run repeatedly:
if(dezibot.motionDetection.isShaken(1000,zAxis)){
dezibot.multiColorLight.setTopLeds(0xFF0000);
} else if(dezibot.motionDetection.isShaken(1000,xAxis|yAxis)) {
dezibot.multiColorLight.setTopLeds(0x00FF00);
}
}

View File

@ -64,7 +64,24 @@ int8_t MotionDetection::getWhoAmI(){
};
bool MotionDetection::isShaken(uint32_t threshold ,uint8_t axis){
IMUResult measurment1 = this->getAcceleration();
delayMicroseconds(10);
IMUResult measurment2 = this->getAcceleration();
uint count = 0;
for(uint i = 0;i<20;i++){
measurment1 = this->getAcceleration();
delayMicroseconds(10);
measurment2 = this->getAcceleration();
if(
(((axis && xAxis) > 0) && (abs(abs(measurment1.x)-abs(measurment2.x))>threshold)) ||
(((axis && yAxis) > 0) && (abs(abs(measurment1.y)-abs(measurment2.y))>threshold)) ||
(((axis && zAxis) > 0) && (abs(abs(measurment1.z)-abs(measurment2.z))>threshold))){
count++;
}
delayMicroseconds(15);
}
Serial.println(count);
return (count > 6);
};
void MotionDetection::calibrateZAxis(uint gforceValue){

View File

@ -67,7 +67,7 @@ protected:
static const uint8_t WHO_AM_I = 0x75;
static const uint frequency = 10000000;
static const uint16_t defaultShakeThreshold = 500;
static const uint16_t defaultShakeThreshold = 1000;
uint16_t cmdRead(uint8_t regHigh,uint8_t regLow);
uint16_t cmdWrite(uint8_t regHigh,uint8_t regLow);
@ -151,7 +151,7 @@ public:
* 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(uint).
* 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.
*
*/