Step sequence optimized

This commit is contained in:
2026-04-13 21:24:50 +02:00
parent 41cd7bd24f
commit 93d9591624

View File

@@ -917,21 +917,21 @@ def main():
client_ref.check_msg() client_ref.check_msg()
moved_any = False pending = []
for i, g in enumerate(gauge_objects): for i, g in enumerate(gauge_objects):
current_target = g._val_to_step(gauge_targets[i]) delta = g._val_to_step(gauge_targets[i]) - g._current_step
if current_target != g._current_step: steps = max(-5, min(5, delta))
direction = 1 if current_target > g._current_step else -1 pending.append(steps)
steps_to_move = current_target - g._current_step
steps_to_move = max(-5, min(5, steps_to_move))
for _ in range(abs(steps_to_move)):
g.step(direction)
moved_any = True
was_moving = True
moved_any = any(s != 0 for s in pending)
if moved_any: if moved_any:
was_moving = True
delay_us = 1_000_000 // MICROSTEPS_PER_SECOND delay_us = 1_000_000 // MICROSTEPS_PER_SECOND
utime.sleep_us(delay_us) for tick in range(max(abs(s) for s in pending)):
for i, g in enumerate(gauge_objects):
if tick < abs(pending[i]):
g.step(1 if pending[i] > 0 else -1)
utime.sleep_us(delay_us)
else: else:
if was_moving: if was_moving:
publish_state(client_ref) publish_state(client_ref)