tests.dashboard.main
1from typing import Optional 2 3import hil2.hil2 as hil2 4import hil2.component as hil2_comp 5import hil2.can_helper as can_helper 6import mk_assert.mk_assert as mka 7 8import time 9import logging 10 11# Consts ------------------------------------------------------------------------------# 12PEDAL_LOW_V = 0.5 # volts read when pedal is not pressed 13PEDAL_HIGH_V = 4.5 # volts read when pedal is fully pressed 14PEDAL_PERCENT_V = (PEDAL_HIGH_V - PEDAL_LOW_V) / 100.0 15 16SLEEP_TIME = 0.03 # seconds 17 18MSG_NAME = "raw_throttle_brake" 19 20# Helpers -----------------------------------------------------------------------------# 21def pedal_percent_to_volts_1(percent: float) -> float: 22 """ 23 Normal linear mapping from 0-100% to volts 24 25 :param percent: Percent value from 0 to 100 26 :return: Corresponding voltage value 27 """ 28 return PEDAL_LOW_V + percent * PEDAL_PERCENT_V 29 30def pedal_percent_to_volts_2(percent: float) -> float: 31 """ 32 Inverted linear mapping from 0-100% to volts 33 34 :param percent: Percent value from 0 to 100 35 :return: Corresponding voltage value 36 """ 37 return PEDAL_HIGH_V - percent * PEDAL_PERCENT_V 38 39def power_cycle(pow: hil2_comp.DO, delay_s: float = 0.5): 40 pow.set(False) 41 time.sleep(delay_s) 42 pow.set(True) 43 time.sleep(delay_s) 44 45 46def set_both(pedal1: hil2_comp.AO, pedal2: hil2_comp.AO, percent: float) -> None: 47 """ 48 Set a set of two pedals to the same percent value. 49 50 :param pedal1: First pedal AO component 51 :param pedal2: Second pedal AO component 52 :param percent: Percent value from 0 to 100 53 """ 54 pedal1.set(percent) 55 pedal2.set(percent) 56 57def check_msg(msg: Optional[can_helper.CanMessage], test_prefix: str): 58 mka.assert_true(msg is not None, f"{test_prefix}: VCAN message received") 59 60def check_brakes(msg: Optional[can_helper.CanMessage], exp_percent: float, tol_v: float, test_prefix: str): 61 check_msg(msg, test_prefix) 62 mka.assert_eqf(msg is not None and msg.data["brake"], pedal_percent_to_volts(exp_percent), tol_v, f"{test_prefix}: brake left {exp_percent}%") 63 mka.assert_eqf(msg is not None and msg.data["brake_right"], pedal_percent_to_volts(exp_percent), tol_v, f"{test_prefix}: brake right {exp_percent}%") 64 65def check_throttle_left(msg: Optional[can_helper.CanMessage], exp_percent: float, tol_v: float, test_prefix: str): 66 mka.assert_eqf(msg is not None and msg.data["throttle"], pedal_percent_to_volts(exp_percent), tol_v, f"{test_prefix}: throttle left {exp_percent}%") 67 68def check_throttle_right(msg: Optional[can_helper.CanMessage], exp_percent: float, tol_v: float, test_prefix: str): 69 mka.assert_eqf(msg is not None and msg.data["throttle_right"], pedal_percent_to_volts(exp_percent), tol_v, f"{test_prefix}: throttle right {exp_percent}%") 70 71def check_throttles(msg: Optional[can_helper.CanMessage], exp_percent: float, tol_v: float, test_prefix: str): 72 check_msg(msg, test_prefix) 73 check_throttle_left(msg, exp_percent, tol_v, test_prefix) 74 check_throttle_right(msg, exp_percent, tol_v, test_prefix) 75 76# EV.4.7.2 ----------------------------------------------------------------------------# 77def ev_4_7_2_test(h: hil2.Hil2): 78 """ 79 If brake is activated (5% pressed) and throttle is activated more than 25%, motor 80 must shutdown and stay shutdown until throttle is under 5% 81 82 - brake low, throttle low, check motor on 83 - brake high, throttle low, check motor on 84 - brake high, throttle high, check motor off 85 - brake low, throttle mid, check motor off (sweep down to 5% on throttle) 86 - brake low, throttle low, check motor back on 87 Note: Check for motor off: throttle can message is 0 88 """ 89 90 brk1 = h.ao("Dashboard", "BRK1_RAW") 91 brk2 = h.ao("Dashboard", "BRK2_RAW") 92 thrtl1 = h.ao("Dashboard", "THRTL1_RAW") 93 thrtl2 = h.ao("Dashboard", "THRTL2_RAW") 94 mcan = h.can("HIL2", "VCAN") 95 96 # Setup: set brake and throttle to 0% 97 set_both(brk1, brk2, pedal_percent_to_volts(0)) 98 set_both(thrtl1, thrtl2, pedal_percent_to_volts(0)) 99 time.sleep(SLEEP_TIME) 100 msg = mcan.get_last(MSG_NAME) 101 check_brakes(msg, 0, 0.1, "Setup") 102 check_throttles(msg, 0, 0.1, "Setup") 103 104 # Test 1: brake low, throttle low, check motor on 105 set_both(brk1, brk2, pedal_percent_to_volts(5)) 106 set_both(thrtl1, thrtl2, pedal_percent_to_volts(5)) 107 time.sleep(SLEEP_TIME) 108 msg = mcan.get_last(MSG_NAME) 109 check_brakes(msg, 5, 0.1, "Brakes low, throttle low") 110 check_throttles(msg, 5, 0.1, "Brakes low, throttle low") 111 112 # Test 2: brake high, throttle low, check motor on 113 set_both(brk1, brk2, pedal_percent_to_volts(50)) 114 set_both(thrtl1, thrtl2, pedal_percent_to_volts(5)) 115 time.sleep(SLEEP_TIME) 116 msg = mcan.get_last(MSG_NAME) 117 check_brakes(msg, 50, 0.1, "Brakes high, throttle low") 118 check_throttles(msg, 5, 0.1, "Brakes high, throttle low") 119 120 # Test 3: brake high, throttle high, check motor off 121 set_both(brk1, brk2, pedal_percent_to_volts(50)) 122 set_both(thrtl1, thrtl2, pedal_percent_to_volts(50)) 123 time.sleep(SLEEP_TIME) 124 msg = mcan.get_last(MSG_NAME) 125 check_brakes(msg, 50, 0.1, "Brakes high, throttle high") 126 check_throttles(msg, 0, 0.1, "Brakes high, throttle high") 127 128 # Test 4: brake low, throttle mid, check motor off (sweep down to 5% on throttle) 129 set_both(brk1, brk2, pedal_percent_to_volts(5)) 130 time.sleep(SLEEP_TIME) 131 msg = mcan.get_last(MSG_NAME) 132 check_brakes(msg, 5, 0.1, "Brakes low, throttle mid") 133 134 for p in range(50, 4, -1): 135 set_both(thrtl1, thrtl2, pedal_percent_to_volts(p)) 136 time.sleep(SLEEP_TIME) 137 msg = mcan.get_last(MSG_NAME) 138 expected_throttle = 0 if p > 5 else pedal_percent_to_volts(p) 139 check_throttles(msg, expected_throttle, 0.1, f"Brakes low, throttle {p} (expected {expected_throttle}%)") 140 141 # Test 5: brake low, throttle mid, check motor back on 142 set_both(brk1, brk2, pedal_percent_to_volts(5)) 143 set_both(thrtl1, thrtl2, pedal_percent_to_volts(25)) 144 time.sleep(SLEEP_TIME) 145 msg = mcan.get_last(MSG_NAME) 146 check_brakes(msg, 5, 0.1, "Brakes low, throttle mid") 147 check_throttles(msg, 25, 0.1, "Brakes low, throttle mid") 148 149 150# T.4.2.5 -----------------------------------------------------------------------------# 151def t_4_2_5_impl(left_is_1: bool, sens1: hil2_comp.AO, sens2: hil2_comp.AO, sdc: hil2_comp.DI, mcan: hil2_comp.CAN): 152 """ 153 - sens1 and sens2 similar, check motor on, sdc not triggered 154 - sens1 and sens2 slightly different, check motor on, sdc not triggered 155 - sens1 and sens2 10% different, check motor on, sdc not triggered 156 - sens1 and sens2 slightly different, check motor on, sdc not triggered 157 - sens1 and sens2 10% different, check motor on, sdc not triggered 158 - sens1 and sens2 still 10% different (~100 msec later), check motor off, sdc not triggered 159 - sens1 and sens2 similar, check motor on, sdc not triggered 160 Note: Check for motor off: throttle can message is 0 161 """ 162 163 # Sensors similar, check motor on, sdc not triggered 164 set_both(sens1, sens2, pedal_percent_to_volts(20)) 165 time.sleep(SLEEP_TIME) 166 msg = mcan.get_last(MSG_NAME) 167 check_throttles(msg, 20, 0.1, "Sensors similar") 168 mka.assert_false(sdc.get(), "SDC not triggered") 169 170 # Sensors slightly different, check motor on, sdc not triggered 171 sens1.set(pedal_percent_to_volts(20)) 172 sens2.set(pedal_percent_to_volts(25)) 173 time.sleep(SLEEP_TIME) 174 msg = mcan.get_last(MSG_NAME) 175 check_msg(msg, "Sensors slightly different") 176 if left_is_1: 177 check_throttle_left(msg, 20, 0.1, "Sensors slightly different") 178 check_throttle_right(msg, 25, 0.1, "Sensors slightly different") 179 else: 180 check_throttle_left(msg, 25, 0.1, "Sensors slightly different") 181 check_throttle_right(msg, 20, 0.1, "Sensors slightly different") 182 mka.assert_false(sdc.get(), "SDC not triggered") 183 184 # Sensors 10% different, check motor on, sdc not triggered 185 sens1.set(pedal_percent_to_volts(20)) 186 sens2.set(pedal_percent_to_volts(30)) 187 time.sleep(SLEEP_TIME) 188 msg = mcan.get_last(MSG_NAME) 189 check_msg(msg, "Sensors 10% different") 190 if left_is_1: 191 check_throttle_left(msg, 20, 0.1, "Sensors 10% different") 192 check_throttle_right(msg, 30, 0.1, "Sensors 10% different") 193 else: 194 check_throttle_left(msg, 30, 0.1, "Sensors 10% different") 195 check_throttle_right(msg, 20, 0.1, "Sensors 10% different") 196 mka.assert_false(sdc.get(), "SDC not triggered") 197 198 # Sensors slightly different, check motor on, sdc not triggered 199 sens1.set(pedal_percent_to_volts(25)) 200 sens2.set(pedal_percent_to_volts(30)) 201 time.sleep(SLEEP_TIME) 202 msg = mcan.get_last(MSG_NAME) 203 check_msg(msg, "Sensors slightly different") 204 if left_is_1: 205 check_throttle_left(msg, 25, 0.1, "Sensors slightly different") 206 check_throttle_right(msg, 30, 0.1, "Sensors slightly different") 207 else: 208 check_throttle_left(msg, 30, 0.1, "Sensors slightly different") 209 check_throttle_right(msg, 25, 0.1, "Sensors slightly different") 210 mka.assert_false(sdc.get(), "SDC not triggered") 211 212 # Sensors 10% different, check motor on, sdc not triggered 213 sens1.set(pedal_percent_to_volts(20)) 214 sens2.set(pedal_percent_to_volts(30)) 215 time.sleep(SLEEP_TIME) 216 msg = mcan.get_last(MSG_NAME) 217 check_msg(msg, "Sensors 10% different") 218 if left_is_1: 219 check_throttle_left(msg, 20, 0.1, "Sensors 10% different") 220 check_throttle_right(msg, 30, 0.1, "Sensors 10% different") 221 else: 222 check_throttle_left(msg, 30, 0.1, "Sensors 10% different") 223 check_throttle_right(msg, 20, 0.1, "Sensors 10% different") 224 mka.assert_false(sdc.get(), "SDC not triggered") 225 226 # Sensors still 10% different (~100 msec later), check motor off, sdc not triggered 227 time.sleep(0.1) 228 msg = mcan.get_last(MSG_NAME) 229 check_msg(msg, "Sensors still 10% different (~100 msec later)") 230 check_throttles(msg, 0, 0.1, "Sensors still 10% different (~100 msec later)") 231 mka.assert_false(sdc.get(), "SDC not triggered") 232 233 # Sensors similar, check motor on, sdc not triggered 234 set_both(sens1, sens2, pedal_percent_to_volts(20)) 235 time.sleep(SLEEP_TIME) 236 msg = mcan.get_last(MSG_NAME) 237 check_throttles(msg, 20, 0.1, "Sensors similar") 238 mka.assert_false(sdc.get(), "SDC not triggered") 239 240 241def t_4_2_5_test(h: hil2.Hil2): 242 """ 243 If the throttle sensors differ by more than 10% of the pedal travel or disconnects 244 and this exists for more than 100 msec, motors must be stopped, sdc isn't tripped 245 """ 246 thrtl1 = h.ao("Dashboard", "THRTL1_RAW") 247 thrtl2 = h.ao("Dashboard", "THRTL2_RAW") 248 sdc = h.di("Dashboard", "SDC") 249 mcan = h.can("HIL2", "VCAN") 250 251 # Setup: set brake and throttle to 0% 252 set_both(thrtl1, thrtl2, pedal_percent_to_volts(0)) 253 time.sleep(SLEEP_TIME) 254 msg = mcan.get_last(MSG_NAME) 255 check_throttles(msg, 0, 0.1, "Setup") 256 257 # Test with left as sens1 258 t_4_2_5_impl(True, thrtl1, thrtl2, sdc, mcan) 259 260 # Setup: set brake and throttle to 0% 261 set_both(thrtl1, thrtl2, pedal_percent_to_volts(0)) 262 time.sleep(SLEEP_TIME) 263 msg = mcan.get_last(MSG_NAME) 264 check_throttles(msg, 0, 0.1, "Setup") 265 266 # Test with right as sens1 267 t_4_2_5_impl(False, thrtl2, thrtl1, sdc, mcan) 268 269# T.4.2.10 ----------------------------------------------------------------------------# 270def t_4_2_10_test_out_of_range(left_is_1: bool, sens1: hil2_comp.AO, sens2: hil2_comp.AO, sdc: hil2_comp.DI, mcan: hil2_comp.CAN): 271 """ 272 - sens1 and sens2 ok, check motor on, sdc not triggered 273 - both are out of range high, check motor off, sdc triggered 274 """ 275 276 277# Main --------------------------------------------------------------------------------# 278def main(): 279 logging.basicConfig(level=logging.DEBUG) 280 281 with hil2.Hil2( 282 "./tests/dash/config.json", 283 "device_configs", 284 "TODO", 285 "TODO" 286 ) as h: 287 288 pow = h.do("HIL2", "RLY1") 289 290 mka.set_setup_fn(lambda: power_cycle(pow, 0.5)) 291 mka.add_test(ev_4_7_2_test, h) 292 mka.add_test(t_4_2_5_test, h) 293 mka.run_tests() 294 295 296if __name__ == "__main__": 297 main()
PEDAL_LOW_V =
0.5
PEDAL_HIGH_V =
4.5
PEDAL_PERCENT_V =
0.04
SLEEP_TIME =
0.03
MSG_NAME =
'raw_throttle_brake'
def
pedal_percent_to_volts_1(percent: float) -> float:
22def pedal_percent_to_volts_1(percent: float) -> float: 23 """ 24 Normal linear mapping from 0-100% to volts 25 26 :param percent: Percent value from 0 to 100 27 :return: Corresponding voltage value 28 """ 29 return PEDAL_LOW_V + percent * PEDAL_PERCENT_V
Normal linear mapping from 0-100% to volts
Parameters
- percent: Percent value from 0 to 100
Returns
Corresponding voltage value
def
pedal_percent_to_volts_2(percent: float) -> float:
31def pedal_percent_to_volts_2(percent: float) -> float: 32 """ 33 Inverted linear mapping from 0-100% to volts 34 35 :param percent: Percent value from 0 to 100 36 :return: Corresponding voltage value 37 """ 38 return PEDAL_HIGH_V - percent * PEDAL_PERCENT_V
Inverted linear mapping from 0-100% to volts
Parameters
- percent: Percent value from 0 to 100
Returns
Corresponding voltage value
47def set_both(pedal1: hil2_comp.AO, pedal2: hil2_comp.AO, percent: float) -> None: 48 """ 49 Set a set of two pedals to the same percent value. 50 51 :param pedal1: First pedal AO component 52 :param pedal2: Second pedal AO component 53 :param percent: Percent value from 0 to 100 54 """ 55 pedal1.set(percent) 56 pedal2.set(percent)
Set a set of two pedals to the same percent value.
Parameters
- pedal1: First pedal AO component
- pedal2: Second pedal AO component
- percent: Percent value from 0 to 100
def
check_brakes( msg: Optional[hil2.can_helper.CanMessage], exp_percent: float, tol_v: float, test_prefix: str):
61def check_brakes(msg: Optional[can_helper.CanMessage], exp_percent: float, tol_v: float, test_prefix: str): 62 check_msg(msg, test_prefix) 63 mka.assert_eqf(msg is not None and msg.data["brake"], pedal_percent_to_volts(exp_percent), tol_v, f"{test_prefix}: brake left {exp_percent}%") 64 mka.assert_eqf(msg is not None and msg.data["brake_right"], pedal_percent_to_volts(exp_percent), tol_v, f"{test_prefix}: brake right {exp_percent}%")
def
check_throttle_left( msg: Optional[hil2.can_helper.CanMessage], exp_percent: float, tol_v: float, test_prefix: str):
def
check_throttle_right( msg: Optional[hil2.can_helper.CanMessage], exp_percent: float, tol_v: float, test_prefix: str):
def
check_throttles( msg: Optional[hil2.can_helper.CanMessage], exp_percent: float, tol_v: float, test_prefix: str):
78def ev_4_7_2_test(h: hil2.Hil2): 79 """ 80 If brake is activated (5% pressed) and throttle is activated more than 25%, motor 81 must shutdown and stay shutdown until throttle is under 5% 82 83 - brake low, throttle low, check motor on 84 - brake high, throttle low, check motor on 85 - brake high, throttle high, check motor off 86 - brake low, throttle mid, check motor off (sweep down to 5% on throttle) 87 - brake low, throttle low, check motor back on 88 Note: Check for motor off: throttle can message is 0 89 """ 90 91 brk1 = h.ao("Dashboard", "BRK1_RAW") 92 brk2 = h.ao("Dashboard", "BRK2_RAW") 93 thrtl1 = h.ao("Dashboard", "THRTL1_RAW") 94 thrtl2 = h.ao("Dashboard", "THRTL2_RAW") 95 mcan = h.can("HIL2", "VCAN") 96 97 # Setup: set brake and throttle to 0% 98 set_both(brk1, brk2, pedal_percent_to_volts(0)) 99 set_both(thrtl1, thrtl2, pedal_percent_to_volts(0)) 100 time.sleep(SLEEP_TIME) 101 msg = mcan.get_last(MSG_NAME) 102 check_brakes(msg, 0, 0.1, "Setup") 103 check_throttles(msg, 0, 0.1, "Setup") 104 105 # Test 1: brake low, throttle low, check motor on 106 set_both(brk1, brk2, pedal_percent_to_volts(5)) 107 set_both(thrtl1, thrtl2, pedal_percent_to_volts(5)) 108 time.sleep(SLEEP_TIME) 109 msg = mcan.get_last(MSG_NAME) 110 check_brakes(msg, 5, 0.1, "Brakes low, throttle low") 111 check_throttles(msg, 5, 0.1, "Brakes low, throttle low") 112 113 # Test 2: brake high, throttle low, check motor on 114 set_both(brk1, brk2, pedal_percent_to_volts(50)) 115 set_both(thrtl1, thrtl2, pedal_percent_to_volts(5)) 116 time.sleep(SLEEP_TIME) 117 msg = mcan.get_last(MSG_NAME) 118 check_brakes(msg, 50, 0.1, "Brakes high, throttle low") 119 check_throttles(msg, 5, 0.1, "Brakes high, throttle low") 120 121 # Test 3: brake high, throttle high, check motor off 122 set_both(brk1, brk2, pedal_percent_to_volts(50)) 123 set_both(thrtl1, thrtl2, pedal_percent_to_volts(50)) 124 time.sleep(SLEEP_TIME) 125 msg = mcan.get_last(MSG_NAME) 126 check_brakes(msg, 50, 0.1, "Brakes high, throttle high") 127 check_throttles(msg, 0, 0.1, "Brakes high, throttle high") 128 129 # Test 4: brake low, throttle mid, check motor off (sweep down to 5% on throttle) 130 set_both(brk1, brk2, pedal_percent_to_volts(5)) 131 time.sleep(SLEEP_TIME) 132 msg = mcan.get_last(MSG_NAME) 133 check_brakes(msg, 5, 0.1, "Brakes low, throttle mid") 134 135 for p in range(50, 4, -1): 136 set_both(thrtl1, thrtl2, pedal_percent_to_volts(p)) 137 time.sleep(SLEEP_TIME) 138 msg = mcan.get_last(MSG_NAME) 139 expected_throttle = 0 if p > 5 else pedal_percent_to_volts(p) 140 check_throttles(msg, expected_throttle, 0.1, f"Brakes low, throttle {p} (expected {expected_throttle}%)") 141 142 # Test 5: brake low, throttle mid, check motor back on 143 set_both(brk1, brk2, pedal_percent_to_volts(5)) 144 set_both(thrtl1, thrtl2, pedal_percent_to_volts(25)) 145 time.sleep(SLEEP_TIME) 146 msg = mcan.get_last(MSG_NAME) 147 check_brakes(msg, 5, 0.1, "Brakes low, throttle mid") 148 check_throttles(msg, 25, 0.1, "Brakes low, throttle mid")
If brake is activated (5% pressed) and throttle is activated more than 25%, motor must shutdown and stay shutdown until throttle is under 5%
- brake low, throttle low, check motor on
- brake high, throttle low, check motor on
- brake high, throttle high, check motor off
- brake low, throttle mid, check motor off (sweep down to 5% on throttle)
- brake low, throttle low, check motor back on Note: Check for motor off: throttle can message is 0
def
t_4_2_5_impl( left_is_1: bool, sens1: hil2.component.AO, sens2: hil2.component.AO, sdc: hil2.component.DI, mcan: hil2.component.CAN):
152def t_4_2_5_impl(left_is_1: bool, sens1: hil2_comp.AO, sens2: hil2_comp.AO, sdc: hil2_comp.DI, mcan: hil2_comp.CAN): 153 """ 154 - sens1 and sens2 similar, check motor on, sdc not triggered 155 - sens1 and sens2 slightly different, check motor on, sdc not triggered 156 - sens1 and sens2 10% different, check motor on, sdc not triggered 157 - sens1 and sens2 slightly different, check motor on, sdc not triggered 158 - sens1 and sens2 10% different, check motor on, sdc not triggered 159 - sens1 and sens2 still 10% different (~100 msec later), check motor off, sdc not triggered 160 - sens1 and sens2 similar, check motor on, sdc not triggered 161 Note: Check for motor off: throttle can message is 0 162 """ 163 164 # Sensors similar, check motor on, sdc not triggered 165 set_both(sens1, sens2, pedal_percent_to_volts(20)) 166 time.sleep(SLEEP_TIME) 167 msg = mcan.get_last(MSG_NAME) 168 check_throttles(msg, 20, 0.1, "Sensors similar") 169 mka.assert_false(sdc.get(), "SDC not triggered") 170 171 # Sensors slightly different, check motor on, sdc not triggered 172 sens1.set(pedal_percent_to_volts(20)) 173 sens2.set(pedal_percent_to_volts(25)) 174 time.sleep(SLEEP_TIME) 175 msg = mcan.get_last(MSG_NAME) 176 check_msg(msg, "Sensors slightly different") 177 if left_is_1: 178 check_throttle_left(msg, 20, 0.1, "Sensors slightly different") 179 check_throttle_right(msg, 25, 0.1, "Sensors slightly different") 180 else: 181 check_throttle_left(msg, 25, 0.1, "Sensors slightly different") 182 check_throttle_right(msg, 20, 0.1, "Sensors slightly different") 183 mka.assert_false(sdc.get(), "SDC not triggered") 184 185 # Sensors 10% different, check motor on, sdc not triggered 186 sens1.set(pedal_percent_to_volts(20)) 187 sens2.set(pedal_percent_to_volts(30)) 188 time.sleep(SLEEP_TIME) 189 msg = mcan.get_last(MSG_NAME) 190 check_msg(msg, "Sensors 10% different") 191 if left_is_1: 192 check_throttle_left(msg, 20, 0.1, "Sensors 10% different") 193 check_throttle_right(msg, 30, 0.1, "Sensors 10% different") 194 else: 195 check_throttle_left(msg, 30, 0.1, "Sensors 10% different") 196 check_throttle_right(msg, 20, 0.1, "Sensors 10% different") 197 mka.assert_false(sdc.get(), "SDC not triggered") 198 199 # Sensors slightly different, check motor on, sdc not triggered 200 sens1.set(pedal_percent_to_volts(25)) 201 sens2.set(pedal_percent_to_volts(30)) 202 time.sleep(SLEEP_TIME) 203 msg = mcan.get_last(MSG_NAME) 204 check_msg(msg, "Sensors slightly different") 205 if left_is_1: 206 check_throttle_left(msg, 25, 0.1, "Sensors slightly different") 207 check_throttle_right(msg, 30, 0.1, "Sensors slightly different") 208 else: 209 check_throttle_left(msg, 30, 0.1, "Sensors slightly different") 210 check_throttle_right(msg, 25, 0.1, "Sensors slightly different") 211 mka.assert_false(sdc.get(), "SDC not triggered") 212 213 # Sensors 10% different, check motor on, sdc not triggered 214 sens1.set(pedal_percent_to_volts(20)) 215 sens2.set(pedal_percent_to_volts(30)) 216 time.sleep(SLEEP_TIME) 217 msg = mcan.get_last(MSG_NAME) 218 check_msg(msg, "Sensors 10% different") 219 if left_is_1: 220 check_throttle_left(msg, 20, 0.1, "Sensors 10% different") 221 check_throttle_right(msg, 30, 0.1, "Sensors 10% different") 222 else: 223 check_throttle_left(msg, 30, 0.1, "Sensors 10% different") 224 check_throttle_right(msg, 20, 0.1, "Sensors 10% different") 225 mka.assert_false(sdc.get(), "SDC not triggered") 226 227 # Sensors still 10% different (~100 msec later), check motor off, sdc not triggered 228 time.sleep(0.1) 229 msg = mcan.get_last(MSG_NAME) 230 check_msg(msg, "Sensors still 10% different (~100 msec later)") 231 check_throttles(msg, 0, 0.1, "Sensors still 10% different (~100 msec later)") 232 mka.assert_false(sdc.get(), "SDC not triggered") 233 234 # Sensors similar, check motor on, sdc not triggered 235 set_both(sens1, sens2, pedal_percent_to_volts(20)) 236 time.sleep(SLEEP_TIME) 237 msg = mcan.get_last(MSG_NAME) 238 check_throttles(msg, 20, 0.1, "Sensors similar") 239 mka.assert_false(sdc.get(), "SDC not triggered")
- sens1 and sens2 similar, check motor on, sdc not triggered
- sens1 and sens2 slightly different, check motor on, sdc not triggered
- sens1 and sens2 10% different, check motor on, sdc not triggered
- sens1 and sens2 slightly different, check motor on, sdc not triggered
- sens1 and sens2 10% different, check motor on, sdc not triggered
- sens1 and sens2 still 10% different (~100 msec later), check motor off, sdc not triggered
- sens1 and sens2 similar, check motor on, sdc not triggered Note: Check for motor off: throttle can message is 0
242def t_4_2_5_test(h: hil2.Hil2): 243 """ 244 If the throttle sensors differ by more than 10% of the pedal travel or disconnects 245 and this exists for more than 100 msec, motors must be stopped, sdc isn't tripped 246 """ 247 thrtl1 = h.ao("Dashboard", "THRTL1_RAW") 248 thrtl2 = h.ao("Dashboard", "THRTL2_RAW") 249 sdc = h.di("Dashboard", "SDC") 250 mcan = h.can("HIL2", "VCAN") 251 252 # Setup: set brake and throttle to 0% 253 set_both(thrtl1, thrtl2, pedal_percent_to_volts(0)) 254 time.sleep(SLEEP_TIME) 255 msg = mcan.get_last(MSG_NAME) 256 check_throttles(msg, 0, 0.1, "Setup") 257 258 # Test with left as sens1 259 t_4_2_5_impl(True, thrtl1, thrtl2, sdc, mcan) 260 261 # Setup: set brake and throttle to 0% 262 set_both(thrtl1, thrtl2, pedal_percent_to_volts(0)) 263 time.sleep(SLEEP_TIME) 264 msg = mcan.get_last(MSG_NAME) 265 check_throttles(msg, 0, 0.1, "Setup") 266 267 # Test with right as sens1 268 t_4_2_5_impl(False, thrtl2, thrtl1, sdc, mcan)
If the throttle sensors differ by more than 10% of the pedal travel or disconnects and this exists for more than 100 msec, motors must be stopped, sdc isn't tripped
def
t_4_2_10_test_out_of_range( left_is_1: bool, sens1: hil2.component.AO, sens2: hil2.component.AO, sdc: hil2.component.DI, mcan: hil2.component.CAN):
271def t_4_2_10_test_out_of_range(left_is_1: bool, sens1: hil2_comp.AO, sens2: hil2_comp.AO, sdc: hil2_comp.DI, mcan: hil2_comp.CAN): 272 """ 273 - sens1 and sens2 ok, check motor on, sdc not triggered 274 - both are out of range high, check motor off, sdc triggered 275 """
- sens1 and sens2 ok, check motor on, sdc not triggered
- both are out of range high, check motor off, sdc triggered
def
main():
279def main(): 280 logging.basicConfig(level=logging.DEBUG) 281 282 with hil2.Hil2( 283 "./tests/dash/config.json", 284 "device_configs", 285 "TODO", 286 "TODO" 287 ) as h: 288 289 pow = h.do("HIL2", "RLY1") 290 291 mka.set_setup_fn(lambda: power_cycle(pow, 0.5)) 292 mka.add_test(ev_4_7_2_test, h) 293 mka.add_test(t_4_2_5_test, h) 294 mka.run_tests()