|
| 1 | +"""Test TOF Sensor Functional.""" |
| 2 | + |
| 3 | +from typing import List, Union |
| 4 | +from hardware_testing.data import ui |
| 5 | +from hardware_testing.data.csv_report import ( |
| 6 | + CSVReport, |
| 7 | + CSVLine, |
| 8 | + CSVLineRepeating, |
| 9 | + CSVResult, |
| 10 | +) |
| 11 | +from hardware_testing.modules.flex_stacker_dvt_qc.utils import labware_detected |
| 12 | + |
| 13 | +from .driver import FlexStackerInterface as FlexStacker |
| 14 | +from opentrons.drivers.flex_stacker.types import ( |
| 15 | + Direction, |
| 16 | + StackerAxis, |
| 17 | + LEDPattern, |
| 18 | + TOFSensor, |
| 19 | +) |
| 20 | + |
| 21 | + |
| 22 | +def build_csv_lines() -> List[Union[CSVLine, CSVLineRepeating]]: |
| 23 | + """Build CSV Lines.""" |
| 24 | + lines: List[Union[CSVLine, CSVLineRepeating]] = [ |
| 25 | + CSVLine( |
| 26 | + f"tof-{TOFSensor.X}-histogram-empty", |
| 27 | + [bool, str, CSVResult, str], |
| 28 | + ), |
| 29 | + CSVLine( |
| 30 | + f"tof-{TOFSensor.Z}-histogram-empty", |
| 31 | + [bool, str, CSVResult, str], |
| 32 | + ), |
| 33 | + CSVLine( |
| 34 | + f"tof-{TOFSensor.X}-histogram-tiprack", |
| 35 | + [bool, str, CSVResult, str], |
| 36 | + ), |
| 37 | + CSVLine( |
| 38 | + f"tof-{TOFSensor.Z}-histogram-tiprack", |
| 39 | + [bool, str, CSVResult, str], |
| 40 | + ), |
| 41 | + ] |
| 42 | + return lines |
| 43 | + |
| 44 | + |
| 45 | +async def tof_sensors_installed(stacker: FlexStacker) -> bool: |
| 46 | + """Check if the tof sensor are installed.""" |
| 47 | + tof_x = await stacker._driver.get_tof_sensor_status(TOFSensor.X) |
| 48 | + tof_z = await stacker._driver.get_tof_sensor_status(TOFSensor.Z) |
| 49 | + return tof_x.ok and tof_z.ok |
| 50 | + |
| 51 | + |
| 52 | +async def test_tof_sensors_labware_detection( |
| 53 | + stacker: FlexStacker, |
| 54 | + report: CSVReport, |
| 55 | + section: str, |
| 56 | + sensor: TOFSensor, |
| 57 | + labware: str, |
| 58 | +) -> None: |
| 59 | + """Test that we can detect labware with the TOF sensor.""" |
| 60 | + open = not await stacker._driver.get_hopper_door_closed() |
| 61 | + if open: |
| 62 | + report( |
| 63 | + section, |
| 64 | + f"tof-{sensor.name}-histogram-{labware}", |
| 65 | + [ |
| 66 | + False, |
| 67 | + "HOPPER_OPEN", |
| 68 | + CSVResult.FAIL, |
| 69 | + [], |
| 70 | + ], |
| 71 | + ) |
| 72 | + return |
| 73 | + |
| 74 | + print(f"Getting histogram for {sensor}.") |
| 75 | + bins = [40, 80] |
| 76 | + zones = [0, 1, 2, 3] |
| 77 | + status = await stacker._driver.get_tof_sensor_status(sensor) |
| 78 | + print(status) |
| 79 | + histogram = await stacker._driver.get_tof_histogram(sensor) |
| 80 | + detected = not labware_detected(histogram.bins, sensor, bins, zones) |
| 81 | + report( |
| 82 | + section, |
| 83 | + f"tof-{sensor.name}-histogram-{labware}", |
| 84 | + [ |
| 85 | + detected, |
| 86 | + "HISTOGRAM", |
| 87 | + CSVResult.from_bool(detected), |
| 88 | + histogram.bins, |
| 89 | + ], |
| 90 | + ) |
| 91 | + |
| 92 | + |
| 93 | +async def run(stacker: FlexStacker, report: CSVReport, section: str) -> None: |
| 94 | + """Run.""" |
| 95 | + # Reset LEDs to off |
| 96 | + if not stacker._simulating: |
| 97 | + ui.get_user_ready("Make sure both TOF sensors are installed.") |
| 98 | + await stacker._driver.set_led(0, pattern=LEDPattern.STATIC) |
| 99 | + |
| 100 | + print("Homing stacker X and Z axis.") |
| 101 | + await stacker.home_axis(StackerAxis.X, Direction.EXTEND) |
| 102 | + await stacker.home_axis(StackerAxis.Z, Direction.RETRACT) |
| 103 | + |
| 104 | + print("Test that we have no labware on the X") |
| 105 | + ui.get_user_ready("Make sure there is no labware on the stacker gripper position.") |
| 106 | + await test_tof_sensors_labware_detection( |
| 107 | + stacker, report, section, TOFSensor.X, "empty" |
| 108 | + ) |
| 109 | + |
| 110 | + print("Test that we detect tiprack on the X") |
| 111 | + ui.get_user_ready("Add 1 tiprack to the stacker X.") |
| 112 | + await test_tof_sensors_labware_detection( |
| 113 | + stacker, report, section, TOFSensor.X, "tiprack" |
| 114 | + ) |
| 115 | + |
| 116 | + print("Test that we have no labware on the Z") |
| 117 | + ui.get_user_ready( |
| 118 | + "Make sure there is no labware in the stacker and close the hopper door." |
| 119 | + ) |
| 120 | + await stacker.close_latch() |
| 121 | + await test_tof_sensors_labware_detection( |
| 122 | + stacker, report, section, TOFSensor.Z, "empty" |
| 123 | + ) |
| 124 | + |
| 125 | + print("Test that we detect tiprack on the Z") |
| 126 | + ui.get_user_ready("Add 1 tiprack to the stacker Z and close the hopper door.") |
| 127 | + await test_tof_sensors_labware_detection( |
| 128 | + stacker, report, section, TOFSensor.Z, "tiprack" |
| 129 | + ) |
0 commit comments