Improved speed sensor filter

Excluding bounces that are incoherent, if the resulting acceleration
would exceed 10m/s/s
This commit is contained in:
Youen Toupin 2022-03-31 22:47:54 +02:00
parent 9700b9f9e1
commit 7ada49cb5b

View File

@ -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
}