Skip to content

Commit

Permalink
Use platform_settings to determine default stepper speed
Browse files Browse the repository at this point in the history
  • Loading branch information
avanwinkle committed Oct 12, 2024
1 parent b249f4b commit f9cb10b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions mpf/config_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
7 changes: 3 additions & 4 deletions mpf/platforms/fast/fast_stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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':
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit f9cb10b

Please sign in to comment.