Skip to content

Commit

Permalink
make some const definitions more cohesive
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoster1 committed Dec 17, 2020
1 parent 8de9359 commit 19b2b1b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
25 changes: 24 additions & 1 deletion api/src/opentrons/drivers/smoothie_drivers/__init__.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -13,7 +27,6 @@ def __init__(self):
class SimulatingDriver:
def __init__(self):
self._steps_per_mm = {}
self.homed_position = {}

def home(self, axis):
pass
Expand Down Expand Up @@ -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
15 changes: 3 additions & 12 deletions api/src/opentrons/drivers/smoothie_drivers/driver_3_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
23 changes: 9 additions & 14 deletions api/src/opentrons/hardware_control/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)\
Expand All @@ -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()
Expand Down Expand Up @@ -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})
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 19b2b1b

Please sign in to comment.