Step sequence optimized
This commit is contained in:
@@ -917,20 +917,20 @@ 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
|
||||||
|
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)
|
utime.sleep_us(delay_us)
|
||||||
else:
|
else:
|
||||||
if was_moving:
|
if was_moving:
|
||||||
|
|||||||
Reference in New Issue
Block a user