From 7ada49cb5b1fdfe01ec632dfd24a04df42fea694 Mon Sep 17 00:00:00 2001 From: Youen Toupin Date: Thu, 31 Mar 2022 22:47:54 +0200 Subject: [PATCH] Improved speed sensor filter Excluding bounces that are incoherent, if the resulting acceleration would exceed 10m/s/s --- ESP32/src/vehicle-monitor.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ESP32/src/vehicle-monitor.cpp b/ESP32/src/vehicle-monitor.cpp index 458ae58..b37c892 100644 --- a/ESP32/src/vehicle-monitor.cpp +++ b/ESP32/src/vehicle-monitor.cpp @@ -69,7 +69,11 @@ void IRAM_ATTR onSpeedSensorChange(bool newState) if(impulseDuration > 500) return; // impulse was too long, ignore it (maybe magnet stopped near the sensor) unsigned long timeSinceLastImpulse = utils::elapsed(speedSensorLastImpulseTime, now); - if(timeSinceLastImpulse < 30) + + // TODO: find a simple formula that works for any wheel diameter and number of magnets + unsigned long minInterval = speedSensorLastImpulseInterval == (unsigned long)-1 ? 200 : std::min((unsigned long)200, (unsigned long)30 + speedSensorLastImpulseInterval / 2); + + if(timeSinceLastImpulse < minInterval) { // too little time between impulses, probably some bouncing, ignore it }