aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/motion/MotionController.cpp
diff options
context:
space:
mode:
authormark9064 <30447455+mark9064@users.noreply.github.com>2025-06-28 20:07:25 +0100
committermark9064 <30447455+mark9064@users.noreply.github.com>2025-10-15 17:36:02 +0100
commit7ea36e8cacaab1406809851c6234cae61287fc17 (patch)
tree0c53b33ff34c97a6a012a0c787559f031473649d /src/components/motion/MotionController.cpp
parent90e458b00075955f5fe459f4f9f965d9ddf9d11c (diff)
Unconditionally calculate shake speed
Diffstat (limited to 'src/components/motion/MotionController.cpp')
-rw-r--r--src/components/motion/MotionController.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp
index 72507ac5..6cfff61f 100644
--- a/src/components/motion/MotionController.cpp
+++ b/src/components/motion/MotionController.cpp
@@ -54,6 +54,14 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
zHistory++;
zHistory[0] = z;
+ // Update accumulated speed
+ // Currently polling at 10Hz, if this ever goes faster scalar and EMA might need adjusting
+ int32_t speed = std::abs(zHistory[0] - zHistory[histSize - 1] + ((yHistory[0] - yHistory[histSize - 1]) / 2) +
+ ((xHistory[0] - xHistory[histSize - 1]) / 4)) *
+ 100 / (time - lastTime);
+ // integer version of (.2 * speed) + ((1 - .2) * accumulatedSpeed);
+ accumulatedSpeed = speed / 5 + accumulatedSpeed * 4 / 5;
+
stats = GetAccelStats();
int32_t deltaSteps = nbSteps - this->nbSteps;
@@ -111,17 +119,6 @@ bool MotionController::ShouldRaiseWake() const {
return DegreesRolled(stats.yMean, stats.zMean, stats.prevYMean, stats.prevZMean) < rollDegreesThresh;
}
-bool MotionController::ShouldShakeWake(uint16_t thresh) {
- /* Currently Polling at 10hz, If this ever goes faster scalar and EMA might need adjusting */
- int32_t speed = std::abs(zHistory[0] - zHistory[histSize - 1] + (yHistory[0] - yHistory[histSize - 1]) / 2 +
- (xHistory[0] - xHistory[histSize - 1]) / 4) *
- 100 / (time - lastTime);
- // (.2 * speed) + ((1 - .2) * accumulatedSpeed);
- accumulatedSpeed = speed / 5 + accumulatedSpeed * 4 / 5;
-
- return accumulatedSpeed > thresh;
-}
-
bool MotionController::ShouldLowerSleep() const {
if ((stats.xMean > 887 && DegreesRolled(stats.xMean, stats.zMean, stats.prevXMean, stats.prevZMean) > 30) ||
(stats.xMean < -887 && DegreesRolled(stats.xMean, stats.zMean, stats.prevXMean, stats.prevZMean) < -30)) {