qubot-drivers 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qubot/__init__.py +13 -0
- qubot/end_effector/__init__.py +65 -0
- qubot/end_effector/a_axis_capper.py +28 -0
- qubot/end_effector/autosampler_syringe.py +23 -0
- qubot/end_effector/orion_4ch_led.py +86 -0
- qubot/end_effector/parallel_force_actuator.py +311 -0
- qubot/end_effector/rline.py +65 -0
- qubot/end_effector/rline_50_1000.py +24 -0
- qubot/end_effector/rline_50_1000_multistep.py +52 -0
- qubot/end_effector/rline_pace.py +180 -0
- qubot/end_effector/rotating_vacuum_gripper.py +92 -0
- qubot/end_effector/satorius.py +409 -0
- qubot/end_effector/satorius_multistep.py +552 -0
- qubot/end_effector/vacuum_chamber.py +116 -0
- qubot/gantry/__init__.py +48 -0
- qubot/gantry/frame.py +105 -0
- qubot/gantry/grbl.py +749 -0
- qubot/gantry/grbl_ws.py +302 -0
- qubot/gantry/reprap_http.py +483 -0
- qubot/geometry/__init__.py +5 -0
- qubot/geometry/position.py +378 -0
- qubot/labware/__init__.py +13 -0
- qubot/labware/deck.py +79 -0
- qubot/labware/definitions/MEA_cell_MTP.json +56 -0
- qubot/labware/definitions/bioshake.json +323 -0
- qubot/labware/definitions/opentrons_96_tiprack_300ul.json +1020 -0
- qubot/labware/definitions/polyelectric_8_wellplate_30000ul.json +142 -0
- qubot/labware/definitions/polyelectric_96_wellplate_330ul.json +1127 -0
- qubot/labware/definitions/sartorious_96_tiprack_1000ul.json +1130 -0
- qubot/labware/definitions/trash_bin_create.json +43 -0
- qubot/labware/definitions/trash_bin_mof.json +43 -0
- qubot/labware/labware.py +212 -0
- qubot/serialcontroller.py +279 -0
- qubot_drivers-0.1.0.dist-info/METADATA +151 -0
- qubot_drivers-0.1.0.dist-info/RECORD +37 -0
- qubot_drivers-0.1.0.dist-info/WHEEL +4 -0
- qubot_drivers-0.1.0.dist-info/licenses/LICENSE +21 -0
qubot/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Qubot gantry and end-effector drivers.
|
|
2
|
+
|
|
3
|
+
Import the part you need, for example::
|
|
4
|
+
|
|
5
|
+
from qubot.gantry import Frame, GrblHALController
|
|
6
|
+
from qubot.end_effector import RotatingVacuumGripper, rline_50_1000
|
|
7
|
+
|
|
8
|
+
qubot holds no machine settings. Each edge imports the drivers it needs and
|
|
9
|
+
configures frame limits, decks, calibration, and ports in its own code. Importing ``qubot`` itself does not
|
|
10
|
+
open a port or import ``serial``.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""End-effector drivers. Calibration is passed in by the edge.
|
|
2
|
+
|
|
3
|
+
from qubot.end_effector import RotatingVacuumGripper, Chamber
|
|
4
|
+
|
|
5
|
+
- ``Capper``: A-axis capping tool (``qubot.end_effector.a_axis_capper``).
|
|
6
|
+
- ``narrow_z``: autosampler syringe clearance (``qubot.end_effector.autosampler_syringe``).
|
|
7
|
+
- ``RotatingVacuumGripper``: vacuum cup and yaw servo (``qubot.end_effector.rotating_vacuum_gripper``).
|
|
8
|
+
- ``Chamber``: vacuum-chamber valve and lid (``qubot.end_effector.vacuum_chamber``).
|
|
9
|
+
- ``LedBoard``: Orion four-channel LED (``qubot.end_effector.orion_4ch_led``).
|
|
10
|
+
- ``ParallelFingers``, ``Finger``: force actuators (``qubot.end_effector.parallel_force_actuator``).
|
|
11
|
+
- ``RLineModel``, ``RLINE_SPECS``: rLine spec table (``qubot.end_effector.rline``).
|
|
12
|
+
|
|
13
|
+
The two rLine pipettes are used through their modules, because both define
|
|
14
|
+
``connect`` and ``SatoriusController``::
|
|
15
|
+
|
|
16
|
+
from qubot.end_effector import rline_50_1000, rline_50_1000_multistep
|
|
17
|
+
|
|
18
|
+
Everything loads on first use, so importing this package does not import ``serial``.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import importlib
|
|
24
|
+
from typing import TYPE_CHECKING
|
|
25
|
+
|
|
26
|
+
_LAZY = {
|
|
27
|
+
"Capper": ".a_axis_capper",
|
|
28
|
+
"narrow_z": ".autosampler_syringe",
|
|
29
|
+
"RotatingVacuumGripper": ".rotating_vacuum_gripper",
|
|
30
|
+
"Chamber": ".vacuum_chamber",
|
|
31
|
+
"LedBoard": ".orion_4ch_led",
|
|
32
|
+
"ParallelFingers": ".parallel_force_actuator",
|
|
33
|
+
"Finger": ".parallel_force_actuator",
|
|
34
|
+
"RLineModel": ".rline",
|
|
35
|
+
"RLINE_SPECS": ".rline",
|
|
36
|
+
}
|
|
37
|
+
_MODULES = ("rline_50_1000", "rline_50_1000_multistep")
|
|
38
|
+
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
from . import rline_50_1000, rline_50_1000_multistep
|
|
41
|
+
from .a_axis_capper import Capper
|
|
42
|
+
from .autosampler_syringe import narrow_z
|
|
43
|
+
from .orion_4ch_led import LedBoard
|
|
44
|
+
from .parallel_force_actuator import Finger, ParallelFingers
|
|
45
|
+
from .rline import RLINE_SPECS, RLineModel
|
|
46
|
+
from .rotating_vacuum_gripper import RotatingVacuumGripper
|
|
47
|
+
from .vacuum_chamber import Chamber
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def __getattr__(name: str):
|
|
51
|
+
if name in _MODULES:
|
|
52
|
+
value = importlib.import_module(f".{name}", __name__)
|
|
53
|
+
elif name in _LAZY:
|
|
54
|
+
value = getattr(importlib.import_module(_LAZY[name], __name__), name)
|
|
55
|
+
else:
|
|
56
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
57
|
+
globals()[name] = value
|
|
58
|
+
return value
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def __dir__() -> list[str]:
|
|
62
|
+
return sorted(set(globals()) | set(_LAZY) | set(_MODULES))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
__all__ = [*_LAZY, *_MODULES]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Capping toolhead driven by a gantry axis. No bus and no port of its own.
|
|
2
|
+
|
|
3
|
+
The edge configures the axis, tool length, and mount offset for its machine::
|
|
4
|
+
|
|
5
|
+
capper = Capper(axis="A", tool_length_mm=..., mount_offset_x_mm=...)
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
|
|
10
|
+
COMMUNICATION = "gantry"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class Capper:
|
|
15
|
+
"""Where the capper sits on its gantry."""
|
|
16
|
+
|
|
17
|
+
axis: str
|
|
18
|
+
tool_length_mm: float
|
|
19
|
+
mount_offset_x_mm: float
|
|
20
|
+
|
|
21
|
+
def __post_init__(self) -> None:
|
|
22
|
+
if not str(self.axis).strip():
|
|
23
|
+
raise ValueError("capper axis is empty")
|
|
24
|
+
if self.tool_length_mm < 0:
|
|
25
|
+
raise ValueError(f"tool_length_mm must be zero or positive, got {self.tool_length_mm}")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
__all__ = ["COMMUNICATION", "Capper"]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Passive syringe. No bus and no port. Liquid handling stays on the separate pump edge.
|
|
2
|
+
|
|
3
|
+
``syringe_length_mm`` is measured per machine and set in the edge's own config. It is
|
|
4
|
+
the syringe plus whatever holder it clears, and it narrows downward Z travel. It
|
|
5
|
+
is a clearance figure, not an axis limit; the gantry keeps its firmware Z range.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
COMMUNICATION = "none"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def narrow_z(z_limits: tuple[float, float], syringe_length_mm: float) -> tuple[float, float]:
|
|
12
|
+
"""Shorten downward Z travel by the syringe length. Zero leaves the frame interval unchanged."""
|
|
13
|
+
low, high = z_limits
|
|
14
|
+
length = float(syringe_length_mm)
|
|
15
|
+
if length < 0:
|
|
16
|
+
raise ValueError("syringe_length_mm must be zero or positive")
|
|
17
|
+
narrowed_low = low + length
|
|
18
|
+
if narrowed_low > high:
|
|
19
|
+
raise ValueError("syringe length removes the whole Z range")
|
|
20
|
+
return (narrowed_low, high)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
__all__ = ["COMMUNICATION", "narrow_z"]
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Four-channel LED line protocol.
|
|
2
|
+
|
|
3
|
+
Four LED channels on one serial port, 9600 baud, timeout 1 s by default. The edge passes the port.
|
|
4
|
+
|
|
5
|
+
One write sets every channel:
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
{p0};{p1};{p2};{p3}\n
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Off is `0;0;0;0\n`. The reply format is not known, so this package writes the line and does not wait for `ok`.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import serial
|
|
15
|
+
|
|
16
|
+
COMMUNICATION = "serial"
|
|
17
|
+
BAUD = 9600
|
|
18
|
+
TIMEOUT_S = 1.0
|
|
19
|
+
CHANNELS = (0, 1, 2, 3)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def power_line(powers: list[int]) -> str:
|
|
23
|
+
"""Build the four-channel power line.
|
|
24
|
+
|
|
25
|
+
Raises:
|
|
26
|
+
ValueError: If the channel count is not 4 or a power is negative.
|
|
27
|
+
"""
|
|
28
|
+
if len(powers) != 4:
|
|
29
|
+
raise ValueError(f"LED board expects 4 powers, got {len(powers)}")
|
|
30
|
+
rendered: list[str] = []
|
|
31
|
+
for power in powers:
|
|
32
|
+
if isinstance(power, bool) or not isinstance(power, (int, float)):
|
|
33
|
+
raise ValueError(f"LED power must be a number, got {power!r}")
|
|
34
|
+
if int(power) != power or int(power) < 0:
|
|
35
|
+
raise ValueError(f"LED power must be a non-negative integer, got {power}")
|
|
36
|
+
rendered.append(str(int(power)))
|
|
37
|
+
return ";".join(rendered) + "\n"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class LedBoard:
|
|
41
|
+
"""Write-only board. The reply format is unresolved, so reads are not required."""
|
|
42
|
+
|
|
43
|
+
def __init__(self, port_name: str, *, baud: int = BAUD, timeout_s: float = TIMEOUT_S) -> None:
|
|
44
|
+
self.port_name = port_name
|
|
45
|
+
self.baud = baud
|
|
46
|
+
self.timeout_s = timeout_s
|
|
47
|
+
self._serial: serial.Serial | None = None
|
|
48
|
+
self.powers = [0, 0, 0, 0]
|
|
49
|
+
|
|
50
|
+
def connect(self) -> None:
|
|
51
|
+
self._serial = serial.Serial(self.port_name, baudrate=self.baud, timeout=self.timeout_s)
|
|
52
|
+
|
|
53
|
+
def disconnect(self) -> None:
|
|
54
|
+
if self._serial is not None:
|
|
55
|
+
self._serial.close()
|
|
56
|
+
self._serial = None
|
|
57
|
+
|
|
58
|
+
def set_powers(self, p0: int, p1: int, p2: int, p3: int) -> str:
|
|
59
|
+
"""Write one power line. Powers are raw board units.
|
|
60
|
+
|
|
61
|
+
Raises:
|
|
62
|
+
RuntimeError: If the port is not open.
|
|
63
|
+
ValueError: If a power is not a non-negative integer.
|
|
64
|
+
"""
|
|
65
|
+
line = power_line([p0, p1, p2, p3])
|
|
66
|
+
port = self._serial
|
|
67
|
+
if port is None or not port.is_open:
|
|
68
|
+
raise RuntimeError(f"LED port {self.port_name} is not connected")
|
|
69
|
+
port.write(line.encode("ascii"))
|
|
70
|
+
port.flush()
|
|
71
|
+
self.powers = [int(p0), int(p1), int(p2), int(p3)]
|
|
72
|
+
return line
|
|
73
|
+
|
|
74
|
+
def off(self) -> str:
|
|
75
|
+
"""Write zeros to all four channels."""
|
|
76
|
+
return self.set_powers(0, 0, 0, 0)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
__all__ = [
|
|
80
|
+
"BAUD",
|
|
81
|
+
"CHANNELS",
|
|
82
|
+
"COMMUNICATION",
|
|
83
|
+
"LedBoard",
|
|
84
|
+
"TIMEOUT_S",
|
|
85
|
+
"power_line",
|
|
86
|
+
]
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"""Wire protocol for parallel force actuators. Calibration is configured by the edge.
|
|
2
|
+
|
|
3
|
+
Force actuators, one per serial port at 115200 baud. The stream line is:
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
{target},{speed},{displacement},{end_stop},{value}\r\n
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Home writes `H 0`, waits until the reported displacement is −1.0 mm, disconnects, reconnects, and writes `H 0` again. A move writes `G {mm} {rpm}` with `rpm = int(speed_mm_s * steps_per_second)`. `steps_per_second` is 6400, the actuator default.
|
|
10
|
+
|
|
11
|
+
Travel defaults to −30 mm to 0 mm. Correction is `(raw − intercept) / slope` per channel. Force in newtons is `(corrected − baseline) / calibration_factor × 9.81`. The edge passes each channel's `(slope, intercept)` and the sensor's `calibration_factor`::
|
|
12
|
+
|
|
13
|
+
fingers = ParallelFingers(ports, corrections=[(a0, b0), ...], calibration_factor=...)
|
|
14
|
+
|
|
15
|
+
Force-threshold stops are not applied here. No finger stop command is known, so a gantry emergency stop does not stop these actuators.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import threading
|
|
19
|
+
import time
|
|
20
|
+
|
|
21
|
+
import serial
|
|
22
|
+
|
|
23
|
+
COMMUNICATION = "serial"
|
|
24
|
+
BAUD = 115200
|
|
25
|
+
LIMITS_MM = (-30.0, 0.0)
|
|
26
|
+
HOME_DISPLACEMENT_MM = -1.0
|
|
27
|
+
GRAVITY_M_S2 = 9.81
|
|
28
|
+
STEPS_PER_SECOND = 6400
|
|
29
|
+
MAX_SPEED_MM_S = 0.375
|
|
30
|
+
HOME_PULSE_S = 1.0
|
|
31
|
+
HOME_SETTLE_S = 2.0
|
|
32
|
+
HOME_WAIT_TIMEOUT_S = 120.0
|
|
33
|
+
MOVE_WAIT_TIMEOUT_S = 300.0
|
|
34
|
+
DISPLACEMENT_TOLERANCE_MM = 0.01
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def corrected_counts(raw: float, slope: float, intercept: float) -> float:
|
|
38
|
+
"""Apply `(raw - intercept) / slope`."""
|
|
39
|
+
if slope == 0:
|
|
40
|
+
raise ValueError("correction slope is zero")
|
|
41
|
+
return (float(raw) - float(intercept)) / float(slope)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def force_newton(
|
|
45
|
+
raw: float, slope: float, intercept: float, baseline: float, calibration_factor: float
|
|
46
|
+
) -> float:
|
|
47
|
+
"""Newtons from the channel correction and the sensor calibration factor."""
|
|
48
|
+
if calibration_factor == 0:
|
|
49
|
+
raise ValueError("calibration_factor is zero")
|
|
50
|
+
corrected = corrected_counts(raw, slope, intercept)
|
|
51
|
+
return (corrected - float(baseline)) / float(calibration_factor) * GRAVITY_M_S2
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def parse_sample(line: str) -> dict:
|
|
55
|
+
"""Parse one actuator stream line.
|
|
56
|
+
|
|
57
|
+
Raises:
|
|
58
|
+
ValueError: If the line does not have five fields.
|
|
59
|
+
"""
|
|
60
|
+
parts = line.strip().split(",")
|
|
61
|
+
if len(parts) != 5:
|
|
62
|
+
raise ValueError(f"Force sample expected 5 fields, got {line!r}")
|
|
63
|
+
end_stop = parts[3].strip().lower()
|
|
64
|
+
if end_stop in {"1", "true"}:
|
|
65
|
+
stopped = True
|
|
66
|
+
elif end_stop in {"0", "false"}:
|
|
67
|
+
stopped = False
|
|
68
|
+
else:
|
|
69
|
+
raise ValueError(f"Unrecognized end_stop {parts[3]!r}")
|
|
70
|
+
return {
|
|
71
|
+
"target_mm": float(parts[0]),
|
|
72
|
+
"speed": float(parts[1]),
|
|
73
|
+
"displacement_mm": float(parts[2]),
|
|
74
|
+
"end_stop": stopped,
|
|
75
|
+
"raw": int(float(parts[4])),
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def rpm_for_speed(speed_mm_s: float, steps_per_second: int = STEPS_PER_SECOND) -> int:
|
|
80
|
+
"""Convert mm/s to the integer rpm field. Speed must be positive."""
|
|
81
|
+
if speed_mm_s <= 0:
|
|
82
|
+
raise ValueError(f"speed_mm_s must be positive, got {speed_mm_s}")
|
|
83
|
+
return int(speed_mm_s * steps_per_second)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def move_command(to_mm: float, rpm: int, limits_mm: tuple[float, float] = LIMITS_MM) -> str:
|
|
87
|
+
"""Displacement command, including the CR LF the board is written with."""
|
|
88
|
+
low, high = limits_mm
|
|
89
|
+
if to_mm < low or to_mm > high:
|
|
90
|
+
raise ValueError(f"Target {to_mm} mm is outside {tuple(limits_mm)}")
|
|
91
|
+
return f"G {round(float(to_mm), 2)} {int(rpm)}\r\n"
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def home_command() -> str:
|
|
95
|
+
return "H 0\r\n"
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class Finger:
|
|
99
|
+
"""One actuator. The reader stores the latest sample. Force stop is not applied here."""
|
|
100
|
+
|
|
101
|
+
def __init__(
|
|
102
|
+
self,
|
|
103
|
+
port_name: str,
|
|
104
|
+
channel: int,
|
|
105
|
+
*,
|
|
106
|
+
slope: float,
|
|
107
|
+
intercept: float,
|
|
108
|
+
calibration_factor: float,
|
|
109
|
+
limits_mm: tuple[float, float] = LIMITS_MM,
|
|
110
|
+
) -> None:
|
|
111
|
+
if slope == 0:
|
|
112
|
+
raise ValueError(f"Channel {channel} correction slope is zero")
|
|
113
|
+
if calibration_factor == 0:
|
|
114
|
+
raise ValueError("calibration_factor is zero")
|
|
115
|
+
low, high = limits_mm
|
|
116
|
+
if low > high:
|
|
117
|
+
raise ValueError(f"limits_mm {tuple(limits_mm)} has low above high")
|
|
118
|
+
self.port_name = port_name
|
|
119
|
+
self.channel = channel
|
|
120
|
+
self.slope = float(slope)
|
|
121
|
+
self.intercept = float(intercept)
|
|
122
|
+
self.calibration_factor = float(calibration_factor)
|
|
123
|
+
self.limits_mm = (float(low), float(high))
|
|
124
|
+
self.baseline = 0.0
|
|
125
|
+
self._serial: serial.Serial | None = None
|
|
126
|
+
self._latest: dict | None = None
|
|
127
|
+
self._stop = threading.Event()
|
|
128
|
+
self._thread: threading.Thread | None = None
|
|
129
|
+
self._write_lock = threading.Lock()
|
|
130
|
+
|
|
131
|
+
def connect(self) -> None:
|
|
132
|
+
"""Open the port and start reading stream lines."""
|
|
133
|
+
self._serial = serial.Serial(self.port_name, baudrate=BAUD, timeout=0.2)
|
|
134
|
+
self._stop.clear()
|
|
135
|
+
self._thread = threading.Thread(
|
|
136
|
+
target=self._read_loop,
|
|
137
|
+
name=f"finger-{self.channel}",
|
|
138
|
+
daemon=True,
|
|
139
|
+
)
|
|
140
|
+
self._thread.start()
|
|
141
|
+
|
|
142
|
+
def disconnect(self) -> None:
|
|
143
|
+
"""Stop the reader and close the port."""
|
|
144
|
+
self._stop.set()
|
|
145
|
+
thread = self._thread
|
|
146
|
+
if thread is not None and thread is not threading.current_thread():
|
|
147
|
+
thread.join(timeout=2)
|
|
148
|
+
self._thread = None
|
|
149
|
+
if self._serial is not None:
|
|
150
|
+
self._serial.close()
|
|
151
|
+
self._serial = None
|
|
152
|
+
|
|
153
|
+
def latest(self) -> dict | None:
|
|
154
|
+
"""Most recent sample, or None before the first line."""
|
|
155
|
+
if self._latest is None:
|
|
156
|
+
return None
|
|
157
|
+
return dict(self._latest)
|
|
158
|
+
|
|
159
|
+
def write_command(self, command: str) -> None:
|
|
160
|
+
"""Write one CR LF command.
|
|
161
|
+
|
|
162
|
+
Raises:
|
|
163
|
+
RuntimeError: If the port is not open.
|
|
164
|
+
"""
|
|
165
|
+
port = self._serial
|
|
166
|
+
if port is None or not port.is_open:
|
|
167
|
+
raise RuntimeError(
|
|
168
|
+
f"Finger {self.channel} on {self.port_name} is not connected"
|
|
169
|
+
)
|
|
170
|
+
payload = command if command.endswith("\r\n") else command + "\r\n"
|
|
171
|
+
with self._write_lock:
|
|
172
|
+
port.write(payload.encode("ascii"))
|
|
173
|
+
port.flush()
|
|
174
|
+
|
|
175
|
+
def home(self) -> dict:
|
|
176
|
+
"""Home twice, with a disconnect between the two `H 0` writes.
|
|
177
|
+
|
|
178
|
+
Raises:
|
|
179
|
+
RuntimeError: If displacement does not reach −1 mm before the timeout.
|
|
180
|
+
"""
|
|
181
|
+
self.write_command(home_command())
|
|
182
|
+
time.sleep(HOME_PULSE_S)
|
|
183
|
+
self._wait_displacement(HOME_DISPLACEMENT_MM, HOME_WAIT_TIMEOUT_S)
|
|
184
|
+
self.disconnect()
|
|
185
|
+
time.sleep(HOME_SETTLE_S)
|
|
186
|
+
self.connect()
|
|
187
|
+
time.sleep(HOME_SETTLE_S)
|
|
188
|
+
self.write_command(home_command())
|
|
189
|
+
time.sleep(HOME_PULSE_S)
|
|
190
|
+
displacement = self._wait_displacement(HOME_DISPLACEMENT_MM, HOME_WAIT_TIMEOUT_S)
|
|
191
|
+
return {"channel": self.channel, "displacement_mm": displacement}
|
|
192
|
+
|
|
193
|
+
def move_to(self, to_mm: float, speed_mm_s: float) -> dict:
|
|
194
|
+
"""Move to a displacement. Does not stop on force.
|
|
195
|
+
|
|
196
|
+
The threshold unit is unresolved, so contact is not detected here.
|
|
197
|
+
|
|
198
|
+
Raises:
|
|
199
|
+
ValueError: If the target or speed is outside the actuator range.
|
|
200
|
+
RuntimeError: If the reported displacement does not arrive in time.
|
|
201
|
+
"""
|
|
202
|
+
command = move_command(to_mm, rpm_for_speed(speed_mm_s), self.limits_mm)
|
|
203
|
+
self.write_command(command)
|
|
204
|
+
displacement = self._wait_displacement(to_mm, MOVE_WAIT_TIMEOUT_S)
|
|
205
|
+
self.write_command(move_command(displacement, rpm_for_speed(speed_mm_s), self.limits_mm))
|
|
206
|
+
sample = self.latest() or {"channel": self.channel}
|
|
207
|
+
sample["channel"] = self.channel
|
|
208
|
+
sample["displacement_mm"] = displacement
|
|
209
|
+
return sample
|
|
210
|
+
|
|
211
|
+
def _read_loop(self) -> None:
|
|
212
|
+
pending = b""
|
|
213
|
+
while not self._stop.is_set():
|
|
214
|
+
port = self._serial
|
|
215
|
+
if port is None:
|
|
216
|
+
return
|
|
217
|
+
try:
|
|
218
|
+
chunk = port.read(1)
|
|
219
|
+
except serial.SerialException:
|
|
220
|
+
return
|
|
221
|
+
if not chunk:
|
|
222
|
+
continue
|
|
223
|
+
pending += chunk
|
|
224
|
+
while b"\n" in pending:
|
|
225
|
+
line, pending = pending.split(b"\n", 1)
|
|
226
|
+
text = line.decode("utf-8", errors="replace").strip()
|
|
227
|
+
if not text:
|
|
228
|
+
continue
|
|
229
|
+
try:
|
|
230
|
+
sample = parse_sample(text)
|
|
231
|
+
except ValueError:
|
|
232
|
+
continue
|
|
233
|
+
sample["force_n"] = force_newton(
|
|
234
|
+
sample["raw"],
|
|
235
|
+
self.slope,
|
|
236
|
+
self.intercept,
|
|
237
|
+
self.baseline,
|
|
238
|
+
self.calibration_factor,
|
|
239
|
+
)
|
|
240
|
+
sample["channel"] = self.channel
|
|
241
|
+
self._latest = sample
|
|
242
|
+
|
|
243
|
+
def _wait_displacement(self, target_mm: float, timeout_s: float) -> float:
|
|
244
|
+
deadline = time.monotonic() + timeout_s
|
|
245
|
+
while time.monotonic() < deadline:
|
|
246
|
+
sample = self.latest()
|
|
247
|
+
if sample is not None and abs(sample["displacement_mm"] - target_mm) <= DISPLACEMENT_TOLERANCE_MM:
|
|
248
|
+
return float(sample["displacement_mm"])
|
|
249
|
+
time.sleep(0.01)
|
|
250
|
+
raise RuntimeError(
|
|
251
|
+
f"Finger {self.channel} on {self.port_name} did not reach "
|
|
252
|
+
f"{target_mm} mm within {timeout_s} s"
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class ParallelFingers:
|
|
257
|
+
"""Channels 0 upward in port order. One ``(slope, intercept)`` correction per port."""
|
|
258
|
+
|
|
259
|
+
def __init__(
|
|
260
|
+
self,
|
|
261
|
+
ports: list[str],
|
|
262
|
+
*,
|
|
263
|
+
corrections: list[tuple[float, float]],
|
|
264
|
+
calibration_factor: float,
|
|
265
|
+
limits_mm: tuple[float, float] = LIMITS_MM,
|
|
266
|
+
) -> None:
|
|
267
|
+
if not ports:
|
|
268
|
+
raise ValueError("No finger ports")
|
|
269
|
+
if len(corrections) != len(ports):
|
|
270
|
+
raise ValueError(f"Expected {len(ports)} corrections, got {len(corrections)}")
|
|
271
|
+
self.fingers = [
|
|
272
|
+
Finger(
|
|
273
|
+
port,
|
|
274
|
+
channel,
|
|
275
|
+
slope=slope,
|
|
276
|
+
intercept=intercept,
|
|
277
|
+
calibration_factor=calibration_factor,
|
|
278
|
+
limits_mm=limits_mm,
|
|
279
|
+
)
|
|
280
|
+
for channel, (port, (slope, intercept)) in enumerate(zip(ports, corrections))
|
|
281
|
+
]
|
|
282
|
+
|
|
283
|
+
def connect(self) -> None:
|
|
284
|
+
for finger in self.fingers:
|
|
285
|
+
finger.connect()
|
|
286
|
+
|
|
287
|
+
def disconnect(self) -> None:
|
|
288
|
+
for finger in self.fingers:
|
|
289
|
+
finger.disconnect()
|
|
290
|
+
|
|
291
|
+
def finger(self, channel: int) -> Finger:
|
|
292
|
+
if not 0 <= channel < len(self.fingers):
|
|
293
|
+
raise ValueError(f"Channel {channel} is not one of 0 to {len(self.fingers) - 1}")
|
|
294
|
+
return self.fingers[channel]
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
__all__ = [
|
|
298
|
+
"BAUD",
|
|
299
|
+
"COMMUNICATION",
|
|
300
|
+
"Finger",
|
|
301
|
+
"HOME_DISPLACEMENT_MM",
|
|
302
|
+
"LIMITS_MM",
|
|
303
|
+
"ParallelFingers",
|
|
304
|
+
"STEPS_PER_SECOND",
|
|
305
|
+
"corrected_counts",
|
|
306
|
+
"force_newton",
|
|
307
|
+
"home_command",
|
|
308
|
+
"move_command",
|
|
309
|
+
"parse_sample",
|
|
310
|
+
"rpm_for_speed",
|
|
311
|
+
]
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Sartorius rLine model catalog from technical user manual v1.1, Table 1 and Table 3."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from enum import Enum
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class RLineModel(Enum):
|
|
8
|
+
"""The three rLine heads in manual v1.1."""
|
|
9
|
+
|
|
10
|
+
UL_5_200 = "5-200"
|
|
11
|
+
UL_50_1000 = "50-1000"
|
|
12
|
+
UL_100_5000 = "100-5000"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True)
|
|
16
|
+
class RLineSpec:
|
|
17
|
+
"""Parameters that differ by rLine model."""
|
|
18
|
+
|
|
19
|
+
model: RLineModel
|
|
20
|
+
microliters_per_step: float
|
|
21
|
+
home_position: int
|
|
22
|
+
max_position: int
|
|
23
|
+
tip_eject_position: int
|
|
24
|
+
minimum_volume_ul: int
|
|
25
|
+
maximum_volume_ul: int
|
|
26
|
+
level_sensing: bool
|
|
27
|
+
# Nominal µL/s at speed settings 1 through 6. The SI/SO command is still 1-6.
|
|
28
|
+
microliters_per_second: tuple[int, int, int, int, int, int]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
RLINE_SPECS: dict[RLineModel, RLineSpec] = {
|
|
32
|
+
RLineModel.UL_5_200: RLineSpec(
|
|
33
|
+
model=RLineModel.UL_5_200,
|
|
34
|
+
microliters_per_step=0.5,
|
|
35
|
+
home_position=30,
|
|
36
|
+
max_position=443,
|
|
37
|
+
tip_eject_position=-40,
|
|
38
|
+
minimum_volume_ul=5,
|
|
39
|
+
maximum_volume_ul=200,
|
|
40
|
+
level_sensing=True,
|
|
41
|
+
microliters_per_second=(31, 52, 80, 115, 150, 190),
|
|
42
|
+
),
|
|
43
|
+
RLineModel.UL_50_1000: RLineSpec(
|
|
44
|
+
model=RLineModel.UL_50_1000,
|
|
45
|
+
microliters_per_step=2.5,
|
|
46
|
+
home_position=30,
|
|
47
|
+
max_position=443,
|
|
48
|
+
tip_eject_position=-40,
|
|
49
|
+
minimum_volume_ul=50,
|
|
50
|
+
maximum_volume_ul=1000,
|
|
51
|
+
level_sensing=True,
|
|
52
|
+
microliters_per_second=(150, 265, 410, 650, 945, 1120),
|
|
53
|
+
),
|
|
54
|
+
RLineModel.UL_100_5000: RLineSpec(
|
|
55
|
+
model=RLineModel.UL_100_5000,
|
|
56
|
+
microliters_per_step=10,
|
|
57
|
+
home_position=30,
|
|
58
|
+
max_position=580,
|
|
59
|
+
tip_eject_position=-55,
|
|
60
|
+
minimum_volume_ul=100,
|
|
61
|
+
maximum_volume_ul=5000,
|
|
62
|
+
level_sensing=False,
|
|
63
|
+
microliters_per_second=(550, 1000, 1500, 2500, 3650, 4350),
|
|
64
|
+
),
|
|
65
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""One Sartorius rLine body, model 50-1000 uL, 2.5 uL/step. The edge passes the serial port.
|
|
2
|
+
"""
|
|
3
|
+
|
|
4
|
+
from .rline import RLINE_SPECS, RLineModel
|
|
5
|
+
from .satorius import SatoriusController
|
|
6
|
+
|
|
7
|
+
MODEL = RLineModel.UL_50_1000
|
|
8
|
+
COMMUNICATION = "serial"
|
|
9
|
+
MICROLITERS_PER_STEP = RLINE_SPECS[MODEL].microliters_per_step
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def connect(port_name: str) -> SatoriusController:
|
|
13
|
+
"""Open this physical 50-1000 uL body. The model is not a caller choice."""
|
|
14
|
+
return SatoriusController(port_name=port_name, model=MODEL)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"COMMUNICATION",
|
|
19
|
+
"MICROLITERS_PER_STEP",
|
|
20
|
+
"MODEL",
|
|
21
|
+
"RLineModel",
|
|
22
|
+
"SatoriusController",
|
|
23
|
+
"connect",
|
|
24
|
+
]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Sartorius rLine 50-1000 µL body, 2.5 µL/step. Manual v1.1 Table 1: home 30, max 443, tip eject −40. The six preset speeds are 150, 265, 410, 650, 945, and 1120 µL/s. This is not the 5-200 µL body (0.5 µL/step) and not the 100-5000 µL body (10 µL/step).
|
|
2
|
+
|
|
3
|
+
`aspirate` and `dispense` take `speed_ul_s`. A preset speed is one `RI` or `RO`. Any other positive speed uses a faster preset, split into several moves. The pause after each move makes the transfer take `volume / speed` seconds. `step_resolution` and `response_time_s` are per-pipette calibrations the edge passes in: the smallest step that keeps the volume error tolerable, and the shortest command round-trip the plan is allowed to assume. A speed this calibration cannot hit raises. Nothing faster than 1120 µL/s is possible.
|
|
4
|
+
|
|
5
|
+
A dispense of the whole tracked volume paces those outward steps and then sends `RB`.
|
|
6
|
+
|
|
7
|
+
The edge passes the serial port. `rline-50-1000` is unchanged.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from .rline import RLINE_SPECS, RLineModel
|
|
11
|
+
from .satorius_multistep import SatoriusController
|
|
12
|
+
|
|
13
|
+
# Locked to the 50-1000 uL body. Table 1 of rLine manual v1.1:
|
|
14
|
+
# 2.5 uL/step, not 0.5 (5-200) or 10 (100-5000).
|
|
15
|
+
SELECTED_MODEL = RLineModel.UL_50_1000
|
|
16
|
+
MODEL = SELECTED_MODEL
|
|
17
|
+
COMMUNICATION = "serial"
|
|
18
|
+
MICROLITERS_PER_STEP = RLINE_SPECS[MODEL].microliters_per_step
|
|
19
|
+
MINIMUM_VOLUME_UL = RLINE_SPECS[MODEL].minimum_volume_ul
|
|
20
|
+
MAXIMUM_VOLUME_UL = RLINE_SPECS[MODEL].maximum_volume_ul
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def connect(
|
|
24
|
+
port_name: str,
|
|
25
|
+
*,
|
|
26
|
+
step_resolution: int,
|
|
27
|
+
response_time_s: float,
|
|
28
|
+
) -> SatoriusController:
|
|
29
|
+
"""Open this physical 50-1000 uL body. The model is not a caller choice.
|
|
30
|
+
|
|
31
|
+
``step_resolution`` and ``response_time_s`` are this pipette's calibrated
|
|
32
|
+
multistep limits, set in the edge's own config.
|
|
33
|
+
"""
|
|
34
|
+
return SatoriusController(
|
|
35
|
+
port_name=port_name,
|
|
36
|
+
model=MODEL,
|
|
37
|
+
step_resolution=step_resolution,
|
|
38
|
+
response_time_s=response_time_s,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
__all__ = [
|
|
43
|
+
"COMMUNICATION",
|
|
44
|
+
"MAXIMUM_VOLUME_UL",
|
|
45
|
+
"MICROLITERS_PER_STEP",
|
|
46
|
+
"MINIMUM_VOLUME_UL",
|
|
47
|
+
"MODEL",
|
|
48
|
+
"RLineModel",
|
|
49
|
+
"SELECTED_MODEL",
|
|
50
|
+
"SatoriusController",
|
|
51
|
+
"connect",
|
|
52
|
+
]
|