12
12
from opentrons_shared_data .errors .exceptions import FlexStackerStallError
13
13
from opentrons .drivers .flex_stacker .driver import (
14
14
STACKER_MOTION_CONFIG ,
15
+ STALLGUARD_CONFIG ,
16
+ )
17
+ from opentrons .drivers .flex_stacker .types import (
18
+ StackerAxis ,
19
+ Direction ,
15
20
)
16
- from opentrons .drivers .flex_stacker .types import StackerAxis , Direction
17
21
18
22
# The distance from limit switch to limit switch, mm
19
23
TEST_DISTANCE = {StackerAxis .X : 193.5 , StackerAxis .Z : 137 }
20
24
21
25
26
+ def generate_test_thresholds (test_axis : StackerAxis ) -> List [int ]:
27
+ """Generate test thresholds."""
28
+ thresholds = []
29
+ default_threshold = STALLGUARD_CONFIG [test_axis ].threshold
30
+ for sgt in range (default_threshold - 2 , default_threshold + 3 ):
31
+ thresholds .append (sgt )
32
+ return thresholds
33
+
34
+
35
+ def _get_test_tag (test_axis : StackerAxis , sgt : int ) -> str :
36
+ """Get test tag."""
37
+ return f"stallguard-{ test_axis } -SGT-{ sgt } "
38
+
39
+
22
40
def build_csv_lines () -> List [Union [CSVLine , CSVLineRepeating ]]:
23
41
"""Build CSV Lines."""
24
- return [
25
- CSVLine (f"stallguard-{ StackerAxis .X } " , [CSVResult ]),
26
- CSVLine (f"stallguard-{ StackerAxis .Z } " , [CSVResult ]),
27
- ]
42
+ lines : List [Union [CSVLine , CSVLineRepeating ]] = []
43
+ for axis in [StackerAxis .X , StackerAxis .Z ]:
44
+ for sgt in generate_test_thresholds (axis ):
45
+ lines .append (CSVLine (_get_test_tag (axis , sgt ), [CSVResult ]))
46
+ return lines
28
47
29
48
30
49
async def test_stallguard (
31
50
stacker : FlexStacker , test_axis : StackerAxis , report : CSVReport , section : str
32
51
) -> None :
33
52
"""Test Stall-Guard."""
34
53
ui .print_header (f"Testing { test_axis } Axis" )
35
- stall_detected = False
36
- try :
37
- await stacker .move_axis (
38
- test_axis ,
39
- Direction .RETRACT ,
40
- TEST_DISTANCE [test_axis ],
41
- STACKER_MOTION_CONFIG [test_axis ]["move" ].move_params .max_speed ,
42
- STACKER_MOTION_CONFIG [test_axis ]["move" ].move_params .acceleration ,
43
- STACKER_MOTION_CONFIG [test_axis ]["move" ].run_current ,
44
- )
45
- except FlexStackerStallError :
46
- ui .print_info ("Stall Detected" )
47
- stall_detected = True
48
54
49
- axis_reset = False
50
- while not axis_reset :
55
+ for sgt in generate_test_thresholds (test_axis ):
56
+ ui .print_header (f"Testing Stallguard Threshold: { sgt } " )
57
+ await stacker ._driver .set_stallguard_threshold (test_axis , True , sgt )
58
+ stall_detected = False
51
59
try :
52
- # Move the axis off the crash block before re-homing
53
60
await stacker .move_axis (
54
61
test_axis ,
55
- Direction .EXTEND ,
56
- 20 ,
57
- STACKER_MOTION_CONFIG [test_axis ]["home " ].move_params .max_speed ,
58
- STACKER_MOTION_CONFIG [test_axis ]["home " ].move_params .acceleration ,
59
- STACKER_MOTION_CONFIG [test_axis ]["home " ].run_current ,
62
+ Direction .RETRACT ,
63
+ TEST_DISTANCE [ test_axis ] ,
64
+ STACKER_MOTION_CONFIG [test_axis ]["move " ].move_params .max_speed ,
65
+ STACKER_MOTION_CONFIG [test_axis ]["move " ].move_params .acceleration ,
66
+ STACKER_MOTION_CONFIG [test_axis ]["move " ].run_current ,
60
67
)
61
- axis_reset = True
62
68
except FlexStackerStallError :
63
- axis_reset = False
69
+ ui .print_info ("Stall Detected" )
70
+ stall_detected = True
71
+ await stacker ._driver .set_stallguard_threshold (test_axis , False , 0 )
64
72
65
- await stacker .home_axis (test_axis , Direction .EXTEND )
73
+ await stacker .home_axis (test_axis , Direction .EXTEND )
66
74
67
- report (section , f"stallguard-{ test_axis } " , [CSVResult .from_bool (stall_detected )])
75
+ report (
76
+ section ,
77
+ _get_test_tag (test_axis , sgt ),
78
+ [CSVResult .from_bool (stall_detected )],
79
+ )
80
+
81
+ # Restore default stallguard threshold
82
+ await stacker ._driver .set_stallguard_threshold (
83
+ test_axis , True , STALLGUARD_CONFIG [test_axis ].threshold
84
+ )
68
85
69
86
return
70
87
@@ -88,13 +105,6 @@ async def run(stacker: FlexStacker, report: CSVReport, section: str) -> None:
88
105
# Test Axes
89
106
await test_stallguard (stacker , StackerAxis .X , report , section )
90
107
await test_stallguard (stacker , StackerAxis .Z , report , section )
91
- # ui.print_header(f"Testing {StackerAxis.X} Axis")
92
- # x_result = await test_stallguard(stacker, StackerAxis.X)
93
- # report(section, f"stallguard-x", [CSVResult.from_bool(x_result)])
94
-
95
- # ui.print_header("Testing Z Axis")
96
- # z_result = await test_stallguard(stacker, StackerAxis.Z)
97
- # report(section, f"stallguard-z", [CSVResult.from_bool(z_result)])
98
108
99
109
# Prompt operator to remove the crash block
100
110
if not stacker .is_simulated :
@@ -109,7 +119,13 @@ async def run(stacker: FlexStacker, report: CSVReport, section: str) -> None:
109
119
test_reset = True
110
120
except FlexStackerStallError :
111
121
# Double check if crash block was actually removed
112
- await stacker .home_axis (StackerAxis .Z , Direction .EXTEND )
113
- await stacker .home_axis (StackerAxis .X , Direction .EXTEND )
122
+ await stacker ._driver .set_stallguard_threshold (StackerAxis .Z , False , 0 )
123
+ await stacker ._driver .set_stallguard_threshold (StackerAxis .X , False , 0 )
124
+ await stacker ._driver .set_stallguard_threshold (
125
+ StackerAxis .Z , True , STALLGUARD_CONFIG [StackerAxis .Z ].threshold
126
+ )
127
+ await stacker ._driver .set_stallguard_threshold (
128
+ StackerAxis .X , True , STALLGUARD_CONFIG [StackerAxis .X ].threshold
129
+ )
114
130
if not stacker .is_simulated :
115
131
ui .get_user_ready ("Remove the crash block from the stacker" )
0 commit comments