Dfift correction attempts

This commit is contained in:
2026-04-14 17:42:10 +02:00
parent bd07318fe2
commit 61c62cc092
2 changed files with 13 additions and 3 deletions

BIN
3d_model/Pointer.stl Normal file

Binary file not shown.

View File

@@ -75,6 +75,7 @@ class Gauge:
self._current_step = 0 self._current_step = 0
self._zeroed = False self._zeroed = False
self._last_dir = None
def zero(self): def zero(self):
overrun = _OVERRUN_STEPS overrun = _OVERRUN_STEPS
@@ -128,9 +129,18 @@ class Gauge:
self._pin_step.value(0) self._pin_step.value(0)
utime.sleep_us(delay_us) utime.sleep_us(delay_us)
def steps_toward(self, value, limit=5): def steps_toward(self, value, limit=5, deadband=0.5):
"""Return the step delta needed to move toward value, clamped to ±limit.""" """Return the step delta needed to move toward value, clamped to ±limit.
delta = self._val_to_step(value) - self._current_step
deadband: If error is less than this fraction of one step, return 0 to prevent
micro-corrections due to floating-point rounding. Default 0.5 means
no movement if error < half a step.
"""
target_step = self._val_to_step(value)
delta = target_step - self._current_step
deadband_steps = deadband
if abs(delta) < deadband_steps:
return 0
return max(-limit, min(limit, delta)) return max(-limit, min(limit, delta))
def get(self): def get(self):