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 170e54a + f9cb10b commit df1b7ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions mpf/config_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,9 @@ fast_servos:
min_us: single|int|1000
home_us: single|int|1500
max_runtime: single|ms|2000 # 65535 max
fast_steppers:
fast_stepper_settings:
__valid_in__: machine # todo add to validator
__allow_others__:
default_speed: single|int|600
file_shows:
__valid_in__: machine, mode # todo add to validator
__type__: config_dict
Expand Down
9 changes: 5 additions & 4 deletions mpf/platforms/fast/fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,13 @@ async def configure_stepper(self, number: str, config: dict) -> FastStepper:
# verify this board support servos
assert int(port) <= int(brk_board.features['stepper_ports']) # TODO should this be stored as an int?

if 'platform_settings' in config:
config.update(self.machine.config_validator.validate_config('fast_steppers', config['platform_settings']))
del config['platform_settings']

return FastStepper(brk_board, port, config)

@classmethod
def get_stepper_config_section(cls):
"""Return config section."""
return "fast_stepper_settings"

def _parse_switch_number(self, number):
try:
board_str, switch_str = number.split("-")
Expand Down
17 changes: 11 additions & 6 deletions mpf/platforms/fast/fast_stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FastStepper(StepperPlatformInterface):
"""A stepper in the FAST platform connected to a FAST Expansion Board."""

__slots__ = ["base_address", "config", "exp_connection", "log", "stepper_index",
"_is_moving"]
"_is_moving", "_default_speed"]

def __init__(self, breakout_board, port, config):
"""Initialize servo."""
Expand All @@ -26,7 +26,7 @@ def __init__(self, breakout_board, port, config):

self.exp_connection.register_processor('MS:', self.base_address, self.stepper_index, self._process_ms)
self._is_moving = False

self._default_speed = Util.int_to_hex_string(self.config['default_speed'], True)

def home(self, direction):
if direction != 'counterclockwise':
Expand All @@ -51,7 +51,6 @@ def move_rel_pos(self, position, speed=None):

base_command = "MF" if position > 0 else "MR"
hex_position = Util.int_to_hex_string(position, True)
cmd_args = [hex_position]
self.log.debug("Moving stepper index %s: %s steps with speed %s", self.stepper_index, position, speed)

if speed:
Expand All @@ -60,10 +59,11 @@ def move_rel_pos(self, position, speed=None):
f"but received value of {speed}.",
2, self.__class__.__name__)
speed = Util.int_to_hex_string(speed, True)
cmd_args.append(speed)
else:
speed = self._default_speed

self._is_moving = True
self._send_command(base_command, cmd_args)
self._send_command(base_command, [hex_position, speed])

def move_vel_mode(self, _velocity):
pass
Expand All @@ -81,5 +81,10 @@ def _send_command(self, base_command, payload=[]):

def _process_ms(self, message):
_index, state = message.split(",")
state_flags = Util.hex_string_to_int(state)
state_flags = int(state, 16)
self._is_moving = state_flags & 1
## Unused
# self._is_reversed = state_flags & (1 << 1)
# self._is_home = state_flags & (1 << 2)
# self._is_limit = state_flags & (1 << 3)
# self.is_braked = state_flags & (1 << 4)

0 comments on commit df1b7ca

Please sign in to comment.