@@ -54,6 +54,14 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
5454 zHistory++;
5555 zHistory[0 ] = z;
5656
57+ // Update accumulated speed
58+ // Currently polling at 10Hz, if this ever goes faster scalar and EMA might need adjusting
59+ int32_t speed = std::abs (zHistory[0 ] - zHistory[histSize - 1 ] + ((yHistory[0 ] - yHistory[histSize - 1 ]) / 2 ) +
60+ ((xHistory[0 ] - xHistory[histSize - 1 ]) / 4 )) *
61+ 100 / (time - lastTime);
62+ // integer version of (.2 * speed) + ((1 - .2) * accumulatedSpeed);
63+ accumulatedSpeed = speed / 5 + accumulatedSpeed * 4 / 5 ;
64+
5765 stats = GetAccelStats ();
5866
5967 int32_t deltaSteps = nbSteps - this ->nbSteps ;
@@ -111,17 +119,6 @@ bool MotionController::ShouldRaiseWake() const {
111119 return DegreesRolled (stats.yMean , stats.zMean , stats.prevYMean , stats.prevZMean ) < rollDegreesThresh;
112120}
113121
114- bool MotionController::ShouldShakeWake (uint16_t thresh) {
115- /* Currently Polling at 10hz, If this ever goes faster scalar and EMA might need adjusting */
116- int32_t speed = std::abs (zHistory[0 ] - zHistory[histSize - 1 ] + (yHistory[0 ] - yHistory[histSize - 1 ]) / 2 +
117- (xHistory[0 ] - xHistory[histSize - 1 ]) / 4 ) *
118- 100 / (time - lastTime);
119- // (.2 * speed) + ((1 - .2) * accumulatedSpeed);
120- accumulatedSpeed = speed / 5 + accumulatedSpeed * 4 / 5 ;
121-
122- return accumulatedSpeed > thresh;
123- }
124-
125122bool MotionController::ShouldLowerSleep () const {
126123 if ((stats.xMean > 887 && DegreesRolled (stats.xMean , stats.zMean , stats.prevXMean , stats.prevZMean ) > 30 ) ||
127124 (stats.xMean < -887 && DegreesRolled (stats.xMean , stats.zMean , stats.prevXMean , stats.prevZMean ) < -30 )) {
0 commit comments