LucidVR / lucidgloves

Arduino/ESP32 based DIY VR Haptic gloves. Compatible with SteamVR via OpenGloves.
MIT License
2.04k stars 259 forks source link

Median filtering, and analog value clamping #27

Closed TwidgeVR closed 3 years ago

TwidgeVR commented 3 years ago

I've added an optional median filter using the RunningMedian library (https://github.com/RobTillaart/RunningMedian), which can help filtering noisy sensors like bend/flex sensors or hall sensors. Default disabled, and the library only needs to be installed if enabled.

I've also added clamps to the values produced by mapping the analogRead() output against the 0 .. ANALOG_MAX range, which helps when constant calibration is disabled to prevent under or overflow. Defaults enabled.

Additionally I've added clamps to the possible flexion min and max values, which helps with my bend and hall sensor gloves which can occasionally produce spurious output that reach past the normal min/max values. This lets you tune the possible range of calibration values and prevents the min/max used in the map from going out of control. Defaults disabled.

Finally, I've replaced the math being done to calibrate across the 0 .. ANALOG_MAX range with the arduino map() function, for simplicity. I've verified that the values produced by the original equation and those produced by the map() function are identical, so this should not produce a functional change.

lucas-vrtech commented 3 years ago

Great, thanks! Can you go ahead and merge LucidVR:main into your fork to resolve the merge conflicts?