From 19b2b1b733f7d760a2cfe061753d99bf74422418 Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Thu, 17 Dec 2020 12:47:13 -0500 Subject: [PATCH] make some const definitions more cohesive --- .../drivers/smoothie_drivers/__init__.py | 25 ++++++++++++++++++- .../drivers/smoothie_drivers/driver_3_0.py | 15 +++-------- .../opentrons/hardware_control/simulator.py | 23 +++++++---------- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/api/src/opentrons/drivers/smoothie_drivers/__init__.py b/api/src/opentrons/drivers/smoothie_drivers/__init__.py index cf2eccd42bd..ae360338af2 100644 --- a/api/src/opentrons/drivers/smoothie_drivers/__init__.py +++ b/api/src/opentrons/drivers/smoothie_drivers/__init__.py @@ -1,3 +1,17 @@ +from typing_extensions import Final + + +HOMED_POSITION: Final = { + 'X': 418.0, + 'Y': 353.0, + 'Z': 218.0, + 'A': 218.0, + 'B': 19.0, + 'C': 19.0 +} +Y_BOUND_OVERRIDE: Final = 370 + + class SmoothieDriver(object): def __init__(self): @@ -13,7 +27,6 @@ def __init__(self): class SimulatingDriver: def __init__(self): self._steps_per_mm = {} - self.homed_position = {} def home(self, axis): pass @@ -81,3 +94,13 @@ def set_dwelling_current(self, settings): def set_acceleration(self, settings): pass + + @property + def homed_position(self): + return HOMED_POSITION.copy() + + @property + def axis_bounds(self): + position = HOMED_POSITION.copy() + position['Y'] = Y_BOUND_OVERRIDE + return position diff --git a/api/src/opentrons/drivers/smoothie_drivers/driver_3_0.py b/api/src/opentrons/drivers/smoothie_drivers/driver_3_0.py index e08b64bbbbd..06932d35f87 100755 --- a/api/src/opentrons/drivers/smoothie_drivers/driver_3_0.py +++ b/api/src/opentrons/drivers/smoothie_drivers/driver_3_0.py @@ -5,7 +5,6 @@ from time import sleep, time from threading import Event, RLock from typing import Any, Dict, Optional, Union, List, Tuple -from typing_extensions import Final from math import isclose from serial.serialutil import SerialException # type: ignore @@ -16,6 +15,9 @@ AxisMoveTimestamp, parse_key_from_substring, parse_number_from_substring) from opentrons.drivers.rpi_drivers.gpio_simulator import SimulatingGPIOCharDev from opentrons.system import smoothie_update +from . import HOMED_POSITION, Y_BOUND_OVERRIDE + + """ - Driver is responsible for providing an interface for motion control - Driver is the only system component that knows about GCODES or how smoothie @@ -30,17 +32,6 @@ ERROR_KEYWORD = 'error' ALARM_KEYWORD = 'alarm' -# TODO (artyom, ben 20171026): move to config -HOMED_POSITION: Final = { - 'X': 418.0, - 'Y': 353.0, - 'Z': 218.0, - 'A': 218.0, - 'B': 19.0, - 'C': 19.0 -} -Y_BOUND_OVERRIDE: Final = 370 - PLUNGER_BACKLASH_MM = 0.3 LOW_CURRENT_Z_SPEED = 30 diff --git a/api/src/opentrons/hardware_control/simulator.py b/api/src/opentrons/hardware_control/simulator.py index 0422bba103b..b0f6b741c6a 100644 --- a/api/src/opentrons/hardware_control/simulator.py +++ b/api/src/opentrons/hardware_control/simulator.py @@ -5,7 +5,6 @@ from threading import Event from typing import (Dict, Optional, List, Tuple, TYPE_CHECKING, Sequence) -from typing_extensions import Final from contextlib import contextmanager from opentrons_shared_data.pipette import dummy_model_for_name @@ -16,6 +15,7 @@ configs, load) from opentrons.drivers.smoothie_drivers import SimulatingDriver + from opentrons.drivers.rpi_drivers.gpio_simulator import SimulatingGPIOCharDev from . import modules @@ -35,13 +35,6 @@ MODULE_LOG = logging.getLogger(__name__) -_HOME_POSITION: Final = {'X': 418.0, 'Y': 353.0, 'Z': 218.0, - 'A': 218.0, 'B': 19.0, 'C': 19.0} - -_BOUNDS: Final = {'X': 418.0, 'Y': 370.0, 'Z': 218.0, - 'A': 218.0, 'B': 19.0, 'C': 19.0} - - class Simulator: """ This is a subclass of hardware_control that only simulates the hardware actions. It is suitable for use on a dev machine or on @@ -90,6 +83,7 @@ def __init__( """ self.config = config self._loop = loop + self._smoothie_driver = SimulatingDriver() def _sanitize_attached_instrument( passed_ai: Dict[str, Optional[str]] = None)\ @@ -112,13 +106,13 @@ def _sanitize_attached_instrument( m: _sanitize_attached_instrument(attached_instruments.get(m)) for m in types.Mount} self._stubbed_attached_modules = attached_modules - self._position = copy.copy(_HOME_POSITION) + self._position = copy.copy(self._smoothie_driver.homed_position) # Engaged axes start all true in smoothie for some reason so we # imitate that here # TODO(LC2642019) Create a simulating driver for smoothie instead of # using a flag - self._smoothie_driver = SimulatingDriver() - self._engaged_axes = {ax: True for ax in _HOME_POSITION} + + self._engaged_axes = {ax: True for ax in self._smoothie_driver.homed_position} self._lights = {'button': False, 'rails': False} self._run_flag = Event() self._run_flag.set() @@ -146,7 +140,7 @@ def move(self, target_position: Dict[str, float], def home(self, axes: List[str] = None) -> Dict[str, float]: # driver_3_0-> HOMED_POSITION checked_axes = axes or 'XYZABC' - self._position.update({ax: _HOME_POSITION[ax] + self._position.update({ax: self._smoothie_driver.homed_position[ax] for ax in checked_axes}) self._engaged_axes.update({ax: True for ax in checked_axes}) @@ -155,7 +149,7 @@ def home(self, axes: List[str] = None) -> Dict[str, float]: def fast_home( self, axis: Sequence[str], margin: float) -> Dict[str, float]: for ax in axis: - self._position[ax] = _HOME_POSITION[ax] + self._position[ax] = self._smoothie_driver.homed_position[ax] self._engaged_axes[ax] = True return self._position @@ -265,7 +259,8 @@ async def build_module( @property def axis_bounds(self) -> Dict[Axis, Tuple[float, float]]: """ The (minimum, maximum) bounds for each axis. """ - return {Axis[ax]: (0, pos) for ax, pos in _BOUNDS.items() + return {Axis[ax]: (0, pos) for ax, pos + in self._smoothie_driver.axis_bounds.items() if ax not in 'BC'} @property