Skip to content

Commit

Permalink
moved magic numbers into shared-data LiquidProbeSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoegenburg committed Aug 19, 2024
1 parent 318a7aa commit e3f1255
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 8 deletions.
6 changes: 6 additions & 0 deletions api/src/opentrons/config/defaults_ot3.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
sensor_threshold_pascals=15,
output_option=OutputOptions.sync_buffer_to_csv,
aspirate_while_sensing=False,
samples_for_baselining=20,
sample_time_sec=0.004,
data_files={InstrumentProbeType.PRIMARY: "/data/pressure_sensor_data.csv"},
)

Expand Down Expand Up @@ -343,6 +345,10 @@ def _build_default_liquid_probe(
aspirate_while_sensing=from_conf.get(
"aspirate_while_sensing", default.aspirate_while_sensing
),
samples_for_baselining=from_conf.get(
"samples_for_baselining", default.samples_for_baselining
),
sample_time_sec=from_conf.get("sample_time_sec", default.sample_time_sec),
data_files=data_files,
)

Expand Down
2 changes: 2 additions & 0 deletions api/src/opentrons/config/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class LiquidProbeSettings:
sensor_threshold_pascals: float
output_option: OutputOptions
aspirate_while_sensing: bool
samples_for_baselining: int
sample_time_sec: float
data_files: Optional[Dict[InstrumentProbeType, str]]


Expand Down
14 changes: 8 additions & 6 deletions api/src/opentrons/hardware_control/ot3api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2606,17 +2606,17 @@ def remove_gripper_probe(self) -> None:
self._gripper_handler.remove_probe()

@staticmethod
def liquid_probe_non_responsive_z_distance(z_speed: float) -> float:
def liquid_probe_non_responsive_z_distance(
z_speed: float, samples_for_baselining: int, sample_time_sec: float
) -> float:
"""Calculate the Z distance travelled where the LLD pass will be unresponsive."""
# NOTE: (sigler) Here lye some magic numbers.
# The Z axis probing motion uses the first 20 samples to calculate
# a baseline for all following samples, making the very beginning of
# that Z motion unable to detect liquid. The sensor is configured for
# 4ms sample readings, and so we then assume it takes ~80ms to complete.
# If the Z is moving at 5mm/sec, then ~80ms equates to ~0.4
baseline_during_z_sample_num = 20 # FIXME: (sigler) shouldn't be defined here?
sample_time_sec = 0.004 # FIXME: (sigler) shouldn't be defined here?
baseline_duration_sec = baseline_during_z_sample_num * sample_time_sec
# If the Z is moving at 5mm/sec, then ~80ms equates to ~0.4mm
baseline_duration_sec = samples_for_baselining * sample_time_sec
non_responsive_z_mm = baseline_duration_sec * z_speed
return non_responsive_z_mm

Expand Down Expand Up @@ -2710,7 +2710,9 @@ async def liquid_probe(
# TODO: (sigler) add this to pipette's liquid def (per tip)
z_overlap_between_passes_mm = 0.1
sensor_baseline_z_move_mm = OT3API.liquid_probe_non_responsive_z_distance(
probe_settings.mount_speed
probe_settings.mount_speed,
probe_settings.samples_for_baselining,
probe_settings.sample_time_sec,
)
z_offset_per_pass = sensor_baseline_z_move_mm + z_overlap_between_passes_mm

Expand Down
2 changes: 2 additions & 0 deletions api/tests/opentrons/config/ot3_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
"sensor_threshold_pascals": 17,
"output_option": OutputOptions.stream_to_csv,
"aspirate_while_sensing": False,
"samples_for_baselining": 20,
"sample_time_sec": 0.004,
"data_files": {"PRIMARY": "/data/pressure_sensor_data.csv"},
},
"calibration": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ def fake_liquid_settings() -> LiquidProbeSettings:
sensor_threshold_pascals=15,
output_option=OutputOptions.can_bus_only,
aspirate_while_sensing=False,
samples_for_baselining=20,
sample_time_sec=0.004,
data_files={InstrumentProbeType.PRIMARY: "fake_file_name"},
)

Expand Down
20 changes: 18 additions & 2 deletions api/tests/opentrons/hardware_control/test_ot3_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def fake_liquid_settings() -> LiquidProbeSettings:
sensor_threshold_pascals=15,
output_option=OutputOptions.can_bus_only,
aspirate_while_sensing=False,
samples_for_baselining=20,
sample_time_sec=0.004,
data_files={InstrumentProbeType.PRIMARY: "fake_file_name"},
)

Expand Down Expand Up @@ -825,6 +827,8 @@ async def test_liquid_probe(
sensor_threshold_pascals=15,
output_option=OutputOptions.can_bus_only,
aspirate_while_sensing=True,
samples_for_baselining=20,
sample_time_sec=0.004,
data_files={InstrumentProbeType.PRIMARY: "fake_file_name"},
)
fake_max_z_dist = 10.0
Expand Down Expand Up @@ -901,8 +905,12 @@ async def test_liquid_probe_plunger_moves(
fake_max_z_dist = 75.0
config = ot3_hardware.config.liquid_sense
mount_speed = config.mount_speed
samples_for_baselining = config.samples_for_baselining
sample_time_sec = config.sample_time_sec
non_responsive_z_mm = ot3_hardware.liquid_probe_non_responsive_z_distance(
mount_speed
mount_speed,
samples_for_baselining,
sample_time_sec,
)

probe_pass_overlap = 0.1
Expand Down Expand Up @@ -995,8 +1003,12 @@ async def test_liquid_probe_mount_moves(
fake_max_z_dist = 10.0
config = ot3_hardware.config.liquid_sense
mount_speed = config.mount_speed
samples_for_baselining = config.samples_for_baselining
sample_time_sec = config.sample_time_sec
non_responsive_z_mm = ot3_hardware.liquid_probe_non_responsive_z_distance(
mount_speed
mount_speed,
samples_for_baselining,
sample_time_sec,
)

probe_pass_overlap = 0.1
Expand Down Expand Up @@ -1068,6 +1080,8 @@ async def test_multi_liquid_probe(
sensor_threshold_pascals=15,
output_option=OutputOptions.can_bus_only,
aspirate_while_sensing=True,
samples_for_baselining=20,
sample_time_sec=0.004,
data_files={InstrumentProbeType.PRIMARY: "fake_file_name"},
)
fake_max_z_dist = 10.0
Expand Down Expand Up @@ -1140,6 +1154,8 @@ async def _fake_pos_update_and_raise(
sensor_threshold_pascals=15,
output_option=OutputOptions.can_bus_only,
aspirate_while_sensing=True,
samples_for_baselining=20,
sample_time_sec=0.004,
data_files={InstrumentProbeType.PRIMARY: "fake_file_name"},
)
# with a mount speed of 5, pass overlap of 0.5 and a 0.2s delay on z
Expand Down
2 changes: 2 additions & 0 deletions hardware-testing/hardware_testing/gravimetric/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def _get_liquid_probe_settings(
sensor_threshold_pascals=lqid_cfg["sensor_threshold_pascals"],
output_option=OutputOptions.sync_only,
aspirate_while_sensing=False,
samples_for_baselining=20,
sample_time_sec=0.004,
data_files={InstrumentProbeType.PRIMARY: "/data/testing_data/pressure.csv"},
)

Expand Down
2 changes: 2 additions & 0 deletions hardware-testing/hardware_testing/liquid_sense/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ def _run_trial(
sensor_threshold_pascals=lqid_cfg["sensor_threshold_pascals"],
output_option=OutputOptions.sync_buffer_to_csv,
aspirate_while_sensing=run_args.aspirate,
samples_for_baselining=20,
sample_time_sec=0.004,
data_files=data_files,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,8 @@ async def _test_liquid_probe(
sensor_threshold_pascals=probe_cfg.sensor_threshold_pascals,
output_option=OutputOptions.can_bus_only, # FIXME: remove
aspirate_while_sensing=False,
samples_for_baselining=20,
sample_time_sec=0.004,
data_files=None,
)
end_z = await api.liquid_probe(
Expand Down

0 comments on commit e3f1255

Please sign in to comment.