Skip to content

Commit

Permalink
Cleanup print and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
avanwinkle committed Oct 12, 2024
1 parent 354484b commit 414ae54
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
4 changes: 1 addition & 3 deletions mpf/devices/stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@ async def _initialize(self):
def validate_and_parse_config(self, config, is_mode_config, debug_prefix: str = None):
"""Validate stepper config."""
# If positions are just strings, expand them into strings and speeds
print(f"Initial stepper config: {config}")
# TODO: Figure out how to use express_config() to map this
for cfg in ('named_positions', 'relative_positions'):
if cfg in config:
for pos, value in config[cfg].items():
print(f"Checking key {pos} with value {value}")
if isinstance(value, str):
config[cfg][pos] = { 'event': value }
print(f"Reworked stepper config: {config}")
config = super().validate_and_parse_config(config, is_mode_config, debug_prefix)
platform = self.machine.get_platform_sections(
'stepper_controllers', getattr(config, "platform", None))
Expand Down
2 changes: 0 additions & 2 deletions mpf/platforms/fast/communicators/exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ def register_processor(self, message_prefix, board_address, device_id, callback)
self._device_processors[message_prefix][board_address][device_id] = callback

def _process_device_msg(self, message_prefix, message):
print(f"Processing '{message_prefix}'message for devices: '{message}'")
print(f"Available processors: {self._device_processors[message_prefix]}")
# Commands like MS: currently don't include the EXP board in the response,
# so there's no way to know which board needs to be informed. Inform them
# all? If multiple boards are running concurrently, it'll get ugly.
Expand Down
29 changes: 7 additions & 22 deletions mpf/platforms/fast/fast_stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,21 @@ class FastStepper(StepperPlatformInterface):

"""A stepper in the FAST platform connected to a FAST Expansion Board."""

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

def __init__(self, breakout_board, port, config):
"""Initialize servo."""
self.config = config
self.exp_connection = breakout_board.communicator

self.base_address = breakout_board.address
# Try this
self.base_address = '90'
#
self.stepper_index = Util.int_to_hex_string(int(port) - 1) # Steppers are 0-indexed
self.base_address = breakout_board.address
self.log = breakout_board.log

self.exp_connection.register_processor('MS:', self.base_address, self.stepper_index, self._process_ms)
self._is_moving = False
# self.max_runtime = f"{config['max_runtime']:02X}"

# self.write_config_to_servo()

# def write_config_to_servo(self):
# """Send the servo configuration to the platform."""
# min_us = f"{self.config['min_us']:02X}"
# max_us = f"{self.config['max_us']:02X}"
# home_us = f"{self.config['home_us']:02X}"

# # EM:<INDEX>,1,<MAX_TIME_MS>,<MIN>,<MAX>,<NEUTRAL><CR>
# self.exp_connection.send_with_confirmation(
# f"EM@{self.base_address}:{self.stepper_index},1,{self.max_runtime},{min_us},{max_us},{home_us}",
# 'EM:P')

def home(self, direction):
if direction != 'counterclockwise':
Expand All @@ -66,7 +52,7 @@ 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]
print(f"Moving stepper {self.stepper_index} with speed {speed}")
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:
Expand Down Expand Up @@ -94,7 +80,6 @@ def _send_command(self, base_command, payload=[]):
f'{base_command}@{self.base_address}:{self.stepper_index}', *payload]))

def _process_ms(self, message):
print(f"FASTStepper {self.stepper_index} has an MS message! '{message}'")
index, state = message.split(",")
_index, state = message.split(",")
state_flags = Util.hex_string_to_int(state)
self._is_moving = state_flags & 1
self._is_moving = state_flags & 1

0 comments on commit 414ae54

Please sign in to comment.