Skip to content

Commit

Permalink
update simulating modules
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Mar 4, 2024
1 parent 880db71 commit 79e7b9a
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 14 deletions.
7 changes: 4 additions & 3 deletions api/src/opentrons/drivers/heater_shaker/simulator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Dict, Optional
from opentrons.util.async_helpers import ensure_yield
from opentrons.drivers.heater_shaker.abstract import AbstractHeaterShakerDriver
from opentrons.drivers.types import Temperature, RPM, HeaterShakerLabwareLatchStatus
Expand All @@ -7,12 +7,13 @@
class SimulatingDriver(AbstractHeaterShakerDriver):
DEFAULT_TEMP = 23

def __init__(self) -> None:
def __init__(self, serial_number: Optional[str] = None) -> None:
self._labware_latch_state = HeaterShakerLabwareLatchStatus.IDLE_UNKNOWN
self._current_temperature = self.DEFAULT_TEMP
self._temperature = Temperature(current=self.DEFAULT_TEMP, target=None)
self._rpm = RPM(current=0, target=None)
self._homing_status = True
self._serial_number = serial_number

@ensure_yield
async def connect(self) -> None:
Expand Down Expand Up @@ -83,7 +84,7 @@ async def deactivate(self) -> None:
@ensure_yield
async def get_device_info(self) -> Dict[str, str]:
return {
"serial": "dummySerialHS",
"serial": self._serial_number if self._serial_number else "dummySerialHS",
"model": "dummyModelHS",
"version": "dummyVersionHS",
}
Expand Down
7 changes: 5 additions & 2 deletions api/src/opentrons/drivers/mag_deck/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@


class SimulatingDriver(AbstractMagDeckDriver):
def __init__(self, sim_model: Optional[str] = None) -> None:
def __init__(
self, sim_model: Optional[str] = None, serial_number: Optional[str] = None
) -> None:
self._height = 0.0
self._model = MAG_DECK_MODELS[sim_model] if sim_model else "mag_deck_v1.1"
self._serial_number = serial_number

@ensure_yield
async def probe_plate(self) -> None:
Expand All @@ -30,7 +33,7 @@ async def move(self, location: float) -> None:
@ensure_yield
async def get_device_info(self) -> Dict[str, str]:
return {
"serial": "dummySerialMD",
"serial": self._serial_number if self._serial_number else "dummySerialMD",
"model": self._model,
"version": "dummyVersionMD",
}
Expand Down
7 changes: 5 additions & 2 deletions api/src/opentrons/drivers/temp_deck/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@


class SimulatingDriver(AbstractTempDeckDriver):
def __init__(self, sim_model: Optional[str] = None):
def __init__(
self, sim_model: Optional[str] = None, serial_number: Optional[str] = None
):
self._temp = Temperature(target=None, current=0)
self._port: Optional[str] = None
self._model = TEMP_DECK_MODELS[sim_model] if sim_model else "temp_deck_v1.1"
self._serial_number = serial_number

@ensure_yield
async def set_temperature(self, celsius: float) -> None:
Expand Down Expand Up @@ -48,7 +51,7 @@ async def enter_programming_mode(self) -> None:
@ensure_yield
async def get_device_info(self) -> Dict[str, str]:
return {
"serial": "dummySerialTD",
"serial": self._serial_number if self._serial_number else "dummySerialTD",
"model": self._model,
"version": "dummyVersionTD",
}
7 changes: 5 additions & 2 deletions api/src/opentrons/drivers/thermocycler/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
class SimulatingDriver(AbstractThermocyclerDriver):
DEFAULT_TEMP = 23

def __init__(self, model: Optional[str] = None) -> None:
def __init__(
self, model: Optional[str] = None, serial_number: Optional[str] = None
) -> None:
self._ramp_rate: Optional[float] = None
self._lid_status = ThermocyclerLidStatus.OPEN
self._lid_temperature = Temperature(current=self.DEFAULT_TEMP, target=None)
self._plate_temperature = PlateTemperature(
current=self.DEFAULT_TEMP, target=None, hold=None
)
self._model = model if model else "thermocyclerModuleV1"
self._serial_number = serial_number

def model(self) -> str:
return self._model
Expand Down Expand Up @@ -103,7 +106,7 @@ async def deactivate_all(self) -> None:
@ensure_yield
async def get_device_info(self) -> Dict[str, str]:
return {
"serial": "dummySerialTC",
"serial": self._serial_number if self._serial_number else "dummySerialTC",
"model": "dummyModelTC",
"version": "dummyVersionTC",
}
Expand Down
7 changes: 7 additions & 0 deletions api/src/opentrons/hardware_control/module_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
save_module_calibration_offset,
)
from opentrons.hardware_control.modules.types import ModuleType
from opentrons.hardware_control.modules import SimulatingModuleAtPort

from opentrons.types import Point
from .types import AionotifyEvent, BoardRevision, OT3Mount
from . import modules
Expand Down Expand Up @@ -84,6 +86,7 @@ async def build_module(
usb_port: types.USBPort,
type: modules.ModuleType,
sim_model: Optional[str] = None,
serial_number: Optional[str] = None,
) -> modules.AbstractModule:
return await modules.build(
port=port,
Expand All @@ -93,6 +96,7 @@ async def build_module(
hw_control_loop=self._api.loop,
execution_manager=self._api._execution_manager,
sim_model=sim_model,
serial_number=serial_number,
)

async def unregister_modules(
Expand Down Expand Up @@ -154,6 +158,9 @@ async def register_modules(
port=mod.port,
usb_port=mod.usb_port,
type=modules.MODULE_TYPE_BY_NAME[mod.name],
serial_number=mod.serial_number
if isinstance(mod, SimulatingModuleAtPort)
else None,
)
self._available_modules.append(new_instance)
log.info(
Expand Down
3 changes: 2 additions & 1 deletion api/src/opentrons/hardware_control/modules/heater_shaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async def build(
poll_interval_seconds: Optional[float] = None,
simulating: bool = False,
sim_model: Optional[str] = None,
serial_number: Optional[str] = None,
) -> "HeaterShaker":
"""
Build a HeaterShaker
Expand All @@ -71,7 +72,7 @@ async def build(
driver = await HeaterShakerDriver.create(port=port, loop=hw_control_loop)
poll_interval_seconds = poll_interval_seconds or POLL_PERIOD
else:
driver = SimulatingDriver()
driver = SimulatingDriver(serial_number=serial_number)
poll_interval_seconds = poll_interval_seconds or SIMULATING_POLL_PERIOD

reader = HeaterShakerReader(driver=driver)
Expand Down
3 changes: 2 additions & 1 deletion api/src/opentrons/hardware_control/modules/magdeck.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ async def build(
poll_interval_seconds: Optional[float] = None,
simulating: bool = False,
sim_model: Optional[str] = None,
serial_number: Optional[str] = None,
) -> "MagDeck":
"""Factory function."""
driver: AbstractMagDeckDriver
if not simulating:
driver = await MagDeckDriver.create(port=port, loop=hw_control_loop)
else:
driver = SimulatingDriver(sim_model=sim_model)
driver = SimulatingDriver(sim_model=sim_model, serial_number=serial_number)

mod = cls(
port=port,
Expand Down
1 change: 1 addition & 0 deletions api/src/opentrons/hardware_control/modules/mod_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async def build(
poll_interval_seconds: Optional[float] = None,
simulating: bool = False,
sim_model: Optional[str] = None,
serial_number: Optional[str] = None,
) -> "AbstractModule":
"""Modules should always be created using this factory.
Expand Down
3 changes: 2 additions & 1 deletion api/src/opentrons/hardware_control/modules/tempdeck.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async def build(
poll_interval_seconds: Optional[float] = None,
simulating: bool = False,
sim_model: Optional[str] = None,
serial_number: Optional[str] = None,
) -> "TempDeck":
"""
Build a TempDeck
Expand All @@ -60,7 +61,7 @@ async def build(
driver = await TempDeckDriver.create(port=port, loop=hw_control_loop)
poll_interval_seconds = poll_interval_seconds or TEMP_POLL_INTERVAL_SECS
else:
driver = SimulatingDriver(sim_model=sim_model)
driver = SimulatingDriver(sim_model=sim_model, serial_number=serial_number)
poll_interval_seconds = poll_interval_seconds or SIM_TEMP_POLL_INTERVAL_SECS

reader = TempDeckReader(driver=driver)
Expand Down
3 changes: 2 additions & 1 deletion api/src/opentrons/hardware_control/modules/thermocycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async def build(
poll_interval_seconds: Optional[float] = None,
simulating: bool = False,
sim_model: Optional[str] = None,
serial_number: Optional[str] = None,
) -> "Thermocycler":
"""
Build and connect to a Thermocycler
Expand All @@ -87,7 +88,7 @@ async def build(
)
poll_interval_seconds = poll_interval_seconds or POLLING_FREQUENCY_SEC
else:
driver = SimulatingDriver(model=sim_model)
driver = SimulatingDriver(model=sim_model, serial_number=serial_number)
poll_interval_seconds = poll_interval_seconds or SIM_POLLING_FREQUENCY_SEC

reader = ThermocyclerReader(driver=driver)
Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/hardware_control/modules/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class ModuleAtPort:


class SimulatingModuleAtPort(ModuleAtPort):
serial_numer: str
serial_number: str


class BundledFirmware(NamedTuple):
Expand Down
2 changes: 2 additions & 0 deletions api/src/opentrons/hardware_control/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async def build(
hw_control_loop: asyncio.AbstractEventLoop,
execution_manager: ExecutionManager,
sim_model: Optional[str] = None,
serial_number: Optional[str] = None,
) -> AbstractModule:
return await _MODULE_CLS_BY_TYPE[type].build(
port=port,
Expand All @@ -50,6 +51,7 @@ async def build(
hw_control_loop=hw_control_loop,
execution_manager=execution_manager,
sim_model=sim_model,
serial_number=serial_number,
)


Expand Down

0 comments on commit 79e7b9a

Please sign in to comment.