From b249f4b8a1c7cd1a729f364b3c74b4a0c112605f Mon Sep 17 00:00:00 2001 From: Anthony van Winkle Date: Fri, 11 Oct 2024 20:50:30 -0700 Subject: [PATCH 1/2] Always send speed to FASTStepper, including an explicit default speed --- mpf/platforms/fast/fast_stepper.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mpf/platforms/fast/fast_stepper.py b/mpf/platforms/fast/fast_stepper.py index eadf6b5cf..f13f3e7be 100644 --- a/mpf/platforms/fast/fast_stepper.py +++ b/mpf/platforms/fast/fast_stepper.py @@ -7,6 +7,7 @@ from mpf.platforms.interfaces.stepper_platform_interface import StepperPlatformInterface POLL_MS = 100 +DEFAULT_SPEED = Util.int_to_hex_string(600, True) class FastStepper(StepperPlatformInterface): @@ -51,7 +52,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: @@ -60,10 +60,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 = 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 @@ -81,5 +82,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) From f9cb10b007bc60c53da6687e8ed4f79b27b58c1c Mon Sep 17 00:00:00 2001 From: Anthony van Winkle Date: Fri, 11 Oct 2024 20:58:33 -0700 Subject: [PATCH 2/2] Use platform_settings to determine default stepper speed --- mpf/config_spec.yaml | 4 ++-- mpf/platforms/fast/fast.py | 9 +++++---- mpf/platforms/fast/fast_stepper.py | 7 +++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mpf/config_spec.yaml b/mpf/config_spec.yaml index be6cb966a..7528e8f81 100644 --- a/mpf/config_spec.yaml +++ b/mpf/config_spec.yaml @@ -748,9 +748,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 diff --git a/mpf/platforms/fast/fast.py b/mpf/platforms/fast/fast.py index d4080a3d0..a9c99633e 100644 --- a/mpf/platforms/fast/fast.py +++ b/mpf/platforms/fast/fast.py @@ -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("-") diff --git a/mpf/platforms/fast/fast_stepper.py b/mpf/platforms/fast/fast_stepper.py index f13f3e7be..b1f2d7564 100644 --- a/mpf/platforms/fast/fast_stepper.py +++ b/mpf/platforms/fast/fast_stepper.py @@ -7,14 +7,13 @@ from mpf.platforms.interfaces.stepper_platform_interface import StepperPlatformInterface POLL_MS = 100 -DEFAULT_SPEED = Util.int_to_hex_string(600, True) 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.""" @@ -27,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': @@ -61,7 +60,7 @@ def move_rel_pos(self, position, speed=None): 2, self.__class__.__name__) speed = Util.int_to_hex_string(speed, True) else: - speed = DEFAULT_SPEED + speed = self._default_speed self._is_moving = True self._send_command(base_command, [hex_position, speed])