Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/motion/MotionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)

// 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);
int32_t speed = 0;
if (time != lastTime) {
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;

Expand Down