3
3
import numpy as np
4
4
from panda import Panda
5
5
from panda .tests .safety import libpandasafety_py
6
- from panda .tests .safety .common import StdTest , make_msg , UNSAFE_MODE
6
+ import panda .tests .safety .common as common
7
+ from panda .tests .safety .common import CANPackerPanda , UNSAFE_MODE
7
8
8
9
MAX_RATE_UP = 7
9
10
MAX_RATE_DOWN = 17
15
16
MAX_RT_DELTA = 128
16
17
RT_INTERVAL = 250000
17
18
18
- DRIVER_TORQUE_ALLOWANCE = 50 ;
19
- DRIVER_TORQUE_FACTOR = 4 ;
20
-
21
- TX_MSGS = [[384 , 0 ], [1033 , 0 ], [1034 , 0 ], [715 , 0 ], [880 , 0 ], # pt bus
22
- [161 , 1 ], [774 , 1 ], [776 , 1 ], [784 , 1 ], # obs bus
23
- [789 , 2 ], # ch bus
24
- [0x104c006c , 3 ], [0x10400060 ]] # gmlan
25
-
26
- def twos_comp (val , bits ):
27
- if val >= 0 :
28
- return val
29
- else :
30
- return (2 ** bits ) + val
31
-
32
- def sign (a ):
33
- if a > 0 :
34
- return 1
35
- else :
36
- return - 1
37
-
38
- class TestGmSafety (unittest .TestCase ):
39
- @classmethod
40
- def setUp (cls ):
41
- cls .safety = libpandasafety_py .libpandasafety
42
- cls .safety .set_safety_hooks (Panda .SAFETY_GM , 0 )
43
- cls .safety .init_tests_gm ()
19
+ DRIVER_TORQUE_ALLOWANCE = 50
20
+ DRIVER_TORQUE_FACTOR = 4
21
+
22
+ class TestGmSafety (common .PandaSafetyTest ):
23
+ TX_MSGS = [[384 , 0 ], [1033 , 0 ], [1034 , 0 ], [715 , 0 ], [880 , 0 ], # pt bus
24
+ [161 , 1 ], [774 , 1 ], [776 , 1 ], [784 , 1 ], # obs bus
25
+ [789 , 2 ], # ch bus
26
+ [0x104c006c , 3 ], [0x10400060 ]] # gmlan
27
+ STANDSTILL_THRESHOLD = 0
28
+ RELAY_MALFUNCTION_ADDR = 384
29
+ RELAY_MALFUNCTION_BUS = 0
30
+ FWD_BLACKLISTED_ADDRS = {}
31
+ FWD_BUS_LOOKUP = {}
32
+
33
+ def setUp (self ):
34
+ self .packer = CANPackerPanda ("gm_global_a_powertrain" )
35
+ self .packer_chassis = CANPackerPanda ("gm_global_a_chassis" )
36
+ self .safety = libpandasafety_py .libpandasafety
37
+ self .safety .set_safety_hooks (Panda .SAFETY_GM , 0 )
38
+ self .safety .init_tests_gm ()
39
+
40
+ # override these tests from PandaSafetyTest, GM uses button enable
41
+ def test_disable_control_allowed_from_cruise (self ): pass
42
+ def test_enable_control_allowed_from_cruise (self ): pass
44
43
45
44
def _speed_msg (self , speed ):
46
- to_send = make_msg (0 , 842 )
47
- to_send [0 ].RDLR = speed
48
- return to_send
45
+ values = {"%sWheelSpd" % s : speed for s in ["RL" , "RR" ]}
46
+ return self .packer .make_can_msg_panda ("EBCMWheelSpdRear" , 0 , values )
49
47
50
48
def _button_msg (self , buttons ):
51
- to_send = make_msg (0 , 481 )
52
- to_send [0 ].RDHR = buttons << 12
53
- return to_send
49
+ values = {"ACCButtons" : buttons }
50
+ return self .packer .make_can_msg_panda ("ASCMSteeringButton" , 0 , values )
54
51
55
52
def _brake_msg (self , brake ):
56
- to_send = make_msg ( 0 , 241 )
57
- to_send [ 0 ]. RDLR = 0xa00 if brake else 0x900
58
- return to_send
53
+ # GM safety has a brake threshold of 10
54
+ values = { "BrakePedalPosition" : 10 if brake else 0 }
55
+ return self . packer . make_can_msg_panda ( "EBCMBrakePedalPosition" , 0 , values )
59
56
60
57
def _gas_msg (self , gas ):
61
- to_send = make_msg (0 , 417 )
62
- to_send [0 ].RDHR = (1 << 16 ) if gas else 0
63
- return to_send
58
+ values = {"AcceleratorPedal" : 1 if gas else 0 }
59
+ return self .packer .make_can_msg_panda ("AcceleratorPedal" , 0 , values )
64
60
65
61
def _send_brake_msg (self , brake ):
66
- to_send = make_msg (2 , 789 )
67
- brake = (- brake ) & 0xfff
68
- to_send [0 ].RDLR = (brake >> 8 ) | ((brake & 0xff ) << 8 )
69
- return to_send
62
+ values = {"FrictionBrakeCmd" : - brake }
63
+ return self .packer_chassis .make_can_msg_panda ("EBCMFrictionBrakeCmd" , 2 , values )
70
64
71
65
def _send_gas_msg (self , gas ):
72
- to_send = make_msg (0 , 715 )
73
- to_send [0 ].RDLR = ((gas & 0x1f ) << 27 ) | ((gas & 0xfe0 ) << 11 )
74
- return to_send
66
+ values = {"GasRegenCmd" : gas }
67
+ return self .packer .make_can_msg_panda ("ASCMGasRegenCmd" , 0 , values )
75
68
76
69
def _set_prev_torque (self , t ):
77
70
self .safety .set_gm_desired_torque_last (t )
78
71
self .safety .set_gm_rt_torque_last (t )
79
72
80
73
def _torque_driver_msg (self , torque ):
81
- t = twos_comp (torque , 11 )
82
- to_send = make_msg (0 , 388 )
83
- to_send [0 ].RDHR = (((t >> 8 ) & 0x7 ) << 16 ) | ((t & 0xFF ) << 24 )
84
- return to_send
74
+ values = {"LKADriverAppldTrq" : torque }
75
+ return self .packer .make_can_msg_panda ("PSCMStatus" , 0 , values )
85
76
86
77
def _torque_msg (self , torque ):
87
- t = twos_comp (torque , 11 )
88
- to_send = make_msg (0 , 384 )
89
- to_send [0 ].RDLR = ((t >> 8 ) & 0x7 ) | ((t & 0xFF ) << 8 )
90
- return to_send
91
-
92
- def test_spam_can_buses (self ):
93
- StdTest .test_spam_can_buses (self , TX_MSGS )
94
-
95
- def test_relay_malfunction (self ):
96
- StdTest .test_relay_malfunction (self , 384 )
97
-
98
- def test_default_controls_not_allowed (self ):
99
- self .assertFalse (self .safety .get_controls_allowed ())
78
+ values = {"LKASteeringCmd" : torque }
79
+ return self .packer .make_can_msg_panda ("ASCMLKASteeringCmd" , 0 , values )
100
80
101
81
def test_resume_button (self ):
102
82
RESUME_BTN = 2
@@ -116,31 +96,6 @@ def test_cancel_button(self):
116
96
self .safety .safety_rx_hook (self ._button_msg (CANCEL_BTN ))
117
97
self .assertFalse (self .safety .get_controls_allowed ())
118
98
119
- def test_brake_disengage (self ):
120
- StdTest .test_allow_brake_at_zero_speed (self )
121
- StdTest .test_not_allow_brake_when_moving (self , 0 )
122
-
123
- def test_disengage_on_gas (self ):
124
- self .safety .set_controls_allowed (1 )
125
- self .safety .safety_rx_hook (self ._gas_msg (True ))
126
- self .assertFalse (self .safety .get_controls_allowed ())
127
- self .safety .safety_rx_hook (self ._gas_msg (False ))
128
-
129
- def test_unsafe_mode_no_disengage_on_gas (self ):
130
- self .safety .safety_rx_hook (self ._gas_msg (False ))
131
- self .safety .set_controls_allowed (1 )
132
- self .safety .set_unsafe_mode (UNSAFE_MODE .DISABLE_DISENGAGE_ON_GAS )
133
- self .safety .safety_rx_hook (self ._gas_msg (True ))
134
- self .assertTrue (self .safety .get_controls_allowed ())
135
- self .safety .set_unsafe_mode (UNSAFE_MODE .DEFAULT )
136
-
137
- def test_allow_engage_with_gas_pressed (self ):
138
- self .safety .safety_rx_hook (self ._gas_msg (True ))
139
- self .safety .set_controls_allowed (1 )
140
- self .safety .safety_rx_hook (self ._gas_msg (True ))
141
- self .assertTrue (self .safety .get_controls_allowed ())
142
- self .safety .safety_rx_hook (self ._gas_msg (False ))
143
-
144
99
def test_brake_safety_check (self ):
145
100
for enabled in [0 , 1 ]:
146
101
for b in range (0 , 500 ):
@@ -169,9 +124,6 @@ def test_steer_safety_check(self):
169
124
else :
170
125
self .assertTrue (self .safety .safety_tx_hook (self ._torque_msg (t )))
171
126
172
- def test_manually_enable_controls_allowed (self ):
173
- StdTest .test_manually_enable_controls_allowed (self )
174
-
175
127
def test_non_realtime_limit_up (self ):
176
128
self .safety .set_gm_torque_driver (0 , 0 )
177
129
self .safety .set_controls_allowed (True )
@@ -250,16 +202,6 @@ def test_realtime_limits(self):
250
202
self .assertTrue (self .safety .safety_tx_hook (self ._torque_msg (sign * (MAX_RT_DELTA + 1 ))))
251
203
252
204
253
- def test_fwd_hook (self ):
254
- # nothing allowed
255
- buss = list (range (0x0 , 0x3 ))
256
- msgs = list (range (0x1 , 0x800 ))
257
-
258
- for b in buss :
259
- for m in msgs :
260
- # assume len 8
261
- self .assertEqual (- 1 , self .safety .safety_fwd_hook (b , make_msg (b , m , 8 )))
262
-
263
205
def test_tx_hook_on_pedal_pressed (self ):
264
206
for pedal in ['brake' , 'gas' ]:
265
207
if pedal == 'brake' :
0 commit comments