11"""Test TOF Sensor Functional."""
22
33from typing import List , Union
4+
45from hardware_testing .data import ui
56from hardware_testing .data .csv_report import (
67 CSVReport ,
1112from hardware_testing .modules .flex_stacker_dvt_qc .utils import labware_detected
1213
1314from .driver import FlexStackerInterface as FlexStacker
15+ from .utils import NUMBER_OF_BINS , NUMBER_OF_ZONES
1416from opentrons .drivers .flex_stacker .types import (
1517 Direction ,
1618 StackerAxis ,
@@ -59,6 +61,7 @@ async def test_tof_sensors_labware_detection(
5961 """Test that we can detect labware with the TOF sensor."""
6062 open = not await stacker ._driver .get_hopper_door_closed ()
6163 if open :
64+ print ("Failed: Make sure to close the stacker door." )
6265 report (
6366 section ,
6467 f"tof-{ sensor .name } -histogram-{ labware } " ,
@@ -72,19 +75,19 @@ async def test_tof_sensors_labware_detection(
7275 return
7376
7477 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 )
78+ bins = list (range (NUMBER_OF_BINS ))
79+ zones = list (range (NUMBER_OF_ZONES ))
7980 histogram = await stacker ._driver .get_tof_histogram (sensor )
80- detected = not labware_detected (histogram .bins , sensor , bins , zones )
81+ diff = labware_detected (histogram .bins , sensor , bins , zones )
82+ labware_expected = labware != "empty"
83+ result = labware_expected == bool (diff )
8184 report (
8285 section ,
8386 f"tof-{ sensor .name } -histogram-{ labware } " ,
8487 [
85- detected ,
88+ result ,
8689 "HISTOGRAM" ,
87- CSVResult .from_bool (detected ),
90+ CSVResult .from_bool (result ),
8891 histogram .bins ,
8992 ],
9093 )
@@ -102,28 +105,32 @@ async def run(stacker: FlexStacker, report: CSVReport, section: str) -> None:
102105 await stacker .home_axis (StackerAxis .Z , Direction .RETRACT )
103106
104107 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." )
108+ ui .get_user_ready ("Make sure there is no labware on the stacker gripper position" )
109+ await stacker .home_axis (StackerAxis .X , Direction .RETRACT )
106110 await test_tof_sensors_labware_detection (
107111 stacker , report , section , TOFSensor .X , "empty"
108112 )
109113
110- print ("Test that we detect tiprack on the X" )
111- ui .get_user_ready ("Add 1 tiprack to the stacker X." )
114+ print ("Test that we detect tiprack on the X home position" )
115+ await stacker .home_axis (StackerAxis .X , Direction .EXTEND )
116+ ui .get_user_ready ("Add 1 tiprack to the stacker X" )
117+ await stacker .home_axis (StackerAxis .X , Direction .RETRACT )
112118 await test_tof_sensors_labware_detection (
113119 stacker , report , section , TOFSensor .X , "tiprack"
114120 )
121+ await stacker .home_axis (StackerAxis .X , Direction .EXTEND )
115122
116123 print ("Test that we have no labware on the Z" )
117124 ui .get_user_ready (
118- "Make sure there is no labware in the stacker and close the hopper door. "
125+ "Make sure there is no labware in the stacker and close the hopper door"
119126 )
120127 await stacker .close_latch ()
121128 await test_tof_sensors_labware_detection (
122129 stacker , report , section , TOFSensor .Z , "empty"
123130 )
124131
125132 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. " )
133+ ui .get_user_ready ("Add 1 tiprack to the stacker Z and close the hopper door" )
127134 await test_tof_sensors_labware_detection (
128135 stacker , report , section , TOFSensor .Z , "tiprack"
129136 )
0 commit comments