15
15
16
16
MAX_TORQUE_ERROR = 350
17
17
18
+ IPAS_OVERRIDE_THRESHOLD = 200
19
+
18
20
def twos_comp (val , bits ):
19
21
if val >= 0 :
20
22
return val
@@ -42,6 +44,18 @@ def _torque_meas_msg(self, torque):
42
44
to_send [0 ].RDHR = t | ((t & 0xFF ) << 16 )
43
45
return to_send
44
46
47
+ def _torque_driver_msg (self , torque ):
48
+ to_send = libpandasafety_py .ffi .new ('CAN_FIFOMailBox_TypeDef *' )
49
+ to_send [0 ].RIR = 0x260 << 21
50
+
51
+ t = twos_comp (torque , 16 )
52
+ to_send [0 ].RDLR = t | ((t & 0xFF ) << 16 )
53
+ return to_send
54
+
55
+ def _torque_driver_msg_array (self , torque ):
56
+ for i in range (3 ):
57
+ self .safety .toyota_rx_hook (self ._torque_driver_msg (torque ))
58
+
45
59
def _torque_msg (self , torque ):
46
60
to_send = libpandasafety_py .ffi .new ('CAN_FIFOMailBox_TypeDef *' )
47
61
to_send [0 ].RIR = 0x2E4 << 21
@@ -50,6 +64,19 @@ def _torque_msg(self, torque):
50
64
to_send [0 ].RDLR = t | ((t & 0xFF ) << 16 )
51
65
return to_send
52
66
67
+ def _ipas_state_msg (self , state ):
68
+ to_send = libpandasafety_py .ffi .new ('CAN_FIFOMailBox_TypeDef *' )
69
+ to_send [0 ].RIR = 0x262 << 21
70
+
71
+ to_send [0 ].RDLR = state & 0xF
72
+ return to_send
73
+
74
+ def _ipas_control_msg (self ):
75
+ to_send = libpandasafety_py .ffi .new ('CAN_FIFOMailBox_TypeDef *' )
76
+ to_send [0 ].RIR = 0x266 << 21
77
+
78
+ return to_send
79
+
53
80
def _accel_msg (self , accel ):
54
81
to_send = libpandasafety_py .ffi .new ('CAN_FIFOMailBox_TypeDef *' )
55
82
to_send [0 ].RIR = 0x343 << 21
@@ -180,6 +207,54 @@ def test_torque_measurements(self):
180
207
self .assertEqual (- 1 , self .safety .get_torque_meas_max ())
181
208
self .assertEqual (- 1 , self .safety .get_torque_meas_min ())
182
209
210
+ def test_ipas_override (self ):
211
+
212
+ ## angle control is not active
213
+ self .safety .set_controls_allowed (1 )
214
+
215
+ # 3 consecutive msgs where driver exceeds threshold but angle_control isn't active
216
+ self .safety .set_controls_allowed (1 )
217
+ self ._torque_driver_msg_array (IPAS_OVERRIDE_THRESHOLD + 1 )
218
+ self .assertTrue (self .safety .get_controls_allowed ())
219
+
220
+ self ._torque_driver_msg_array (- IPAS_OVERRIDE_THRESHOLD - 1 )
221
+ self .assertTrue (self .safety .get_controls_allowed ())
222
+
223
+ # ipas state is override
224
+ self .safety .toyota_rx_hook (self ._ipas_state_msg (5 ))
225
+ self .assertTrue (self .safety .get_controls_allowed ())
226
+
227
+ ## now angle control is active
228
+ self .safety .toyota_tx_hook (self ._ipas_control_msg ())
229
+ self .safety .toyota_rx_hook (self ._ipas_state_msg (0 ))
230
+
231
+ # 3 consecutive msgs where driver does exceed threshold
232
+ self .safety .set_controls_allowed (1 )
233
+ self ._torque_driver_msg_array (IPAS_OVERRIDE_THRESHOLD + 1 )
234
+ self .assertFalse (self .safety .get_controls_allowed ())
235
+
236
+ self .safety .set_controls_allowed (1 )
237
+ self ._torque_driver_msg_array (- IPAS_OVERRIDE_THRESHOLD - 1 )
238
+ self .assertFalse (self .safety .get_controls_allowed ())
239
+
240
+ # ipas state is override and torque isn't overriding any more
241
+ self .safety .set_controls_allowed (1 )
242
+ self ._torque_driver_msg_array (0 )
243
+ self .safety .toyota_rx_hook (self ._ipas_state_msg (5 ))
244
+ self .assertFalse (self .safety .get_controls_allowed ())
245
+
246
+ # 3 consecutive msgs where driver does not exceed threshold and
247
+ # ipas state is not override
248
+ self .safety .set_controls_allowed (1 )
249
+ self .safety .toyota_rx_hook (self ._ipas_state_msg (0 ))
250
+ self .assertTrue (self .safety .get_controls_allowed ())
251
+
252
+ self ._torque_driver_msg_array (IPAS_OVERRIDE_THRESHOLD )
253
+ self .assertTrue (self .safety .get_controls_allowed ())
254
+
255
+ self ._torque_driver_msg_array (- IPAS_OVERRIDE_THRESHOLD )
256
+ self .assertTrue (self .safety .get_controls_allowed ())
257
+
183
258
184
259
if __name__ == "__main__" :
185
260
unittest .main ()
0 commit comments