Skip to content

Commit

Permalink
Merge branch 'fast-0061-stepper' into fast-0061-stepper-0.80
Browse files Browse the repository at this point in the history
  • Loading branch information
avanwinkle committed Oct 12, 2024
2 parents df1b7ca + 628c8c9 commit a3d27a8
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions mpf/platforms/fast/fast_stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from mpf.platforms.interfaces.stepper_platform_interface import StepperPlatformInterface

POLL_MS = 100
MIN_SPEED = 350
MAX_SPEED = 1650

class FastStepper(StepperPlatformInterface):

Expand Down Expand Up @@ -37,11 +39,14 @@ def home(self, direction):
self._send_command("MH")

async def wait_for_move_completed(self):
# return
# If not moving, return immediately
if not self._is_moving:
return
while True:
await asyncio.sleep(POLL_MS / 1000)
# We may have stopped since the last poll, so check again
if not self._is_moving:
return
await asyncio.sleep(1 / POLL_MS)
self._send_command('MS')

def move_rel_pos(self, position, speed=None):
Expand All @@ -54,7 +59,7 @@ def move_rel_pos(self, position, speed=None):
self.log.debug("Moving stepper index %s: %s steps with speed %s", self.stepper_index, position, speed)

if speed:
if speed < 350 or speed > 1650:
if speed < MIN_SPEED or speed > MAX_SPEED:
raise ConfigFileError("FAST Stepper only supports speeds between 350-1650, "
f"but received value of {speed}.",
2, self.__class__.__name__)
Expand All @@ -65,8 +70,18 @@ def move_rel_pos(self, position, speed=None):
self._is_moving = True
self._send_command(base_command, [hex_position, speed])

def move_vel_mode(self, _velocity):
pass
def move_vel_mode(self, velocity):
"""Move the motor indefinitely in either direction.
FAST does not support this, so instead send the longest possible move time."""
base_command = "MR" if velocity < 0 else "MF"
# The only place in MPF code that uses move_vel_mode is the software-based
# homing, which sends 1/-1 as values. Interpret that as slowest possible
# speed.
speed = MIN_SPEED if abs(velocity) == 1 else abs(velocity)
self._is_moving = True
# Maximum supported move time is FFFF
self._send_command(base_command, ["FFFF", speed])

def stop(self):
"""Called during shutdown."""
Expand Down

0 comments on commit a3d27a8

Please sign in to comment.