Dfift correction attempts
This commit is contained in:
BIN
3d_model/Pointer.stl
Normal file
BIN
3d_model/Pointer.stl
Normal file
Binary file not shown.
@@ -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):
|
||||||
|
|||||||
Reference in New Issue
Block a user