Skip to content

Commit

Permalink
feat(api): add instrument cache to hardware control
Browse files Browse the repository at this point in the history
Closes #2236
  • Loading branch information
sanni-t committed Oct 2, 2018
1 parent 0202b53 commit db46f22
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
13 changes: 11 additions & 2 deletions api/opentrons/hardware_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def __init__(self,
# {'X': 0.0, 'Y': 0.0, 'Z': 0.0, 'A': 0.0, 'B': 0.0, 'C': 0.0}
self._current_position: dict = None

# {'LEFT': '<modelno1>', 'RIGHT': '<modelno>'}
self._attached_instruments = {}

@classmethod
def build_hardware_controller(
cls, config: dict = None,
Expand All @@ -102,13 +105,16 @@ def build_hardware_controller(
@classmethod
def build_hardware_simulator(
cls, config: dict = None,
attached_instruments: dict = None,
attached_modules=None,
loop: asyncio.AbstractEventLoop = None) -> 'API':
""" Build a simulating hardware controller.
This method may be used both on a real robot and on dev machines.
Multiple simulating hardware controllers may be active at one time.
"""
return cls(simulator.Simulator(config, loop),
return cls(simulator.Simulator(config, attached_instruments,
attached_modules, loop),
config=config, loop=loop)

# Query API
Expand Down Expand Up @@ -141,7 +147,10 @@ async def identify(self, seconds):

@_log_call
async def cache_instrument_models(self):
pass
mod_log.info("Updating instrument model cache")
for mount in types.Mount:
self._attached_instruments[mount.name] = \
self._backend.get_attached_instruments(mount.name)

@_log_call
async def update_smoothie_firmware(self, firmware_file):
Expand Down
3 changes: 3 additions & 0 deletions api/opentrons/hardware_control/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ def move(self, target_position: Dict[str, float], home_flagged_axes=True):

def home(self):
return self._smoothie_driver.home()

def get_attached_instruments(self, mount):
return self._smoothie_driver.read_pipette_model(mount)
6 changes: 5 additions & 1 deletion api/opentrons/hardware_control/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ class Simulator:
a robot with no smoothie connected.
"""

def __init__(self, config, loop):
def __init__(self, config, attached_instruments, attached_modules, loop):
self._config = config
self._loop = loop
self._attached_instruments = attached_instruments

def move(self, target_position: Dict[str, float]):
pass

def home(self):
# driver_3_0-> HOMED_POSITION
return {'X': 418, 'Y': 353, 'Z': 218, 'A': 218, 'B': 19, 'C': 19}

def get_attached_instruments(self, mount):
return self._attached_instruments[mount]
16 changes: 16 additions & 0 deletions api/tests/opentrons/hardware_control/test_instruments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest
from opentrons import types
from opentrons import hardware_control as hc

if not hc.controller:
pytest.skip('hardware controller not available (probably windows)',
allow_module_level=True)


async def test_cache_instruments(loop):
dummy_instruments_attached = {types.Mount.LEFT.name: 'model_abc',
types.Mount.RIGHT.name: None}
hw_api = hc.API.build_hardware_simulator(
attached_instruments=dummy_instruments_attached, loop=loop)
await hw_api.cache_instrument_models()
assert hw_api._attached_instruments == dummy_instruments_attached

0 comments on commit db46f22

Please sign in to comment.