Skip to content

Commit

Permalink
refactor(emulation): integrated with module control (#8586)
Browse files Browse the repository at this point in the history
* Module control refactors

* new package.

* start module control integration.

* tests for module control integration.

* implement connection listener.

* module server integrated into module control.

* lint

* g-code-testing

* redo docker compose to deal with separate emulator apps.

* usb port.

* expand module emulation settings.

* update docker readme.

* format-js

* lint

* go back to threadings. I don't want to debug windows nonsense.

* fix bug.

* redo gcode testing's emulator setup.

* documentation.

* clean up.
  • Loading branch information
amitlissack committed Nov 9, 2021
1 parent bb7c966 commit 0be1cd0
Show file tree
Hide file tree
Showing 30 changed files with 834 additions and 414 deletions.
56 changes: 56 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,62 @@ For example to use a `p300_multi` on the right add:
OT_EMULATOR_smoothie: '{"right": {"model": "p300_multi"}}'
```

### Adding more emulators

#### Magdeck

To add a second mag deck emulator make a copy of the existing `magdeck` section and change the key and `serial_number`.

For example this adds a `magdeck` with the serial number `magdeck2`:

```
magdeck2:
build: .
command: python3 -m opentrons.hardware_control.emulation.scripts.run_module_emulator magdeck emulator
links:
- 'emulator'
depends_on:
- 'emulator'
environment:
OT_EMULATOR_magdeck: '{"serial_number": "magdeck2", "model":"mag_deck_v20", "version":"2.0.0"}'
```

#### Tempdeck

To add a second temp deck emulator make a copy of the existing `tempdeck` section and change the key and `serial_number`.

For example this adds a `tempdeck` with the serial number `tempdeck2`:

```
tempdeck2:
build: .
command: python3 -m opentrons.hardware_control.emulation.scripts.run_module_emulator tempdeck emulator
links:
- 'emulator'
depends_on:
- 'emulator'
environment:
OT_EMULATOR_tempdeck: '{"serial_number": "tempdeck2", "model":"temp_deck_v20", "version":"v2.0.1", "temperature": {"starting":0.0, "degrees_per_tick": 2.0}}'
```

#### Thermocycler

To add a second thermocycler emulator make a copy of the existing `thermocycler` section and change the key and `serial_number`.

For example this adds a `thermocycler` with the serial number `thermocycler2`:

```
thermocycler2:
build: .
command: python3 -m opentrons.hardware_control.emulation.scripts.run_module_emulator thermocycler emulator
links:
- 'emulator'
depends_on:
- 'emulator'
environment:
OT_EMULATOR_thermocycler: '{"serial_number": "thermocycler2", "model":"v02", "version":"v1.1.0", "lid_temperature": {"starting":23.0, "degrees_per_tick": 2.0}, "plate_temperature": {"starting":23.0, "degrees_per_tick": 2.0}}'
```

## Known Issues

- Pipettes cannot be changed at run time.
8 changes: 6 additions & 2 deletions api/src/opentrons/hardware_control/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ async def blink():

api_instance = cls(backend, loop=checked_loop, config=checked_config)
await api_instance.cache_instruments()
module_controls = await AttachedModulesControl.build(api_instance)
module_controls = await AttachedModulesControl.build(
api_instance, board_revision=backend.board_revision
)
backend.module_controls = module_controls
checked_loop.create_task(backend.watch(loop=checked_loop))
backend.start_gpio_door_watcher(
Expand Down Expand Up @@ -260,7 +262,9 @@ async def build_hardware_simulator(
)
api_instance = cls(backend, loop=checked_loop, config=checked_config)
await api_instance.cache_instruments()
module_controls = await AttachedModulesControl.build(api_instance)
module_controls = await AttachedModulesControl.build(
api_instance, board_revision=backend.board_revision
)
backend.module_controls = module_controls
await backend.watch()
return api_instance
Expand Down
3 changes: 1 addition & 2 deletions api/src/opentrons/hardware_control/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
aionotify = None

from opentrons.drivers.smoothie_drivers import SmoothieDriver
from opentrons.drivers.rpi_drivers import build_gpio_chardev, usb
from opentrons.drivers.rpi_drivers import build_gpio_chardev
import opentrons.config
from opentrons.config import pipette_config
from opentrons.config.types import RobotConfig
Expand Down Expand Up @@ -77,7 +77,6 @@ def __init__(self, config: RobotConfig, gpio: GPIODriverLike):
config=self.config, gpio_chardev=self._gpio_chardev
)
self._cached_fw_version: Optional[str] = None
self._usb = usb.USBBus(self._board_revision)
self._module_controls: Optional[AttachedModulesControl] = None
try:
self._event_watcher = self._build_event_watcher()
Expand Down
17 changes: 9 additions & 8 deletions api/src/opentrons/hardware_control/emulation/magdeck.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,21 @@
from opentrons.drivers.mag_deck.driver import GCODE
from opentrons.hardware_control.emulation.parser import Parser, Command
from .abstract_emulator import AbstractEmulator
from .settings import MagDeckSettings

logger = logging.getLogger(__name__)


SERIAL = "magnetic_emulator"
MODEL = "mag_deck_v20"
VERSION = "2.0.0"


class MagDeckEmulator(AbstractEmulator):
"""Magdeck emulator"""

height: float = 0
position: float = 0

def __init__(self, parser: Parser) -> None:
self.reset()
def __init__(self, parser: Parser, settings: MagDeckSettings) -> None:
self._settings = settings
self._parser = parser
self.reset()

def handle(self, line: str) -> Optional[str]:
"""Handle a line"""
Expand Down Expand Up @@ -53,7 +50,11 @@ def _handle(self, command: Command) -> Optional[str]:
elif command.gcode == GCODE.GET_CURRENT_POSITION:
return f"Z:{self.position}"
elif command.gcode == GCODE.DEVICE_INFO:
return f"serial:{SERIAL} model:{MODEL} version:{VERSION}"
return (
f"serial:{self._settings.serial_number} "
f"model:{self._settings.model} "
f"version:{self._settings.version}"
)
elif command.gcode == GCODE.PROGRAMMING_MODE:
pass
return None
216 changes: 0 additions & 216 deletions api/src/opentrons/hardware_control/emulation/module_server.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Package for the module status server."""
from .server import ModuleStatusServer
from .client import ModuleStatusClient

__all__ = [
"ModuleStatusServer",
"ModuleStatusClient",
]
Loading

0 comments on commit 0be1cd0

Please sign in to comment.