5
5
import sys
6
6
7
7
from opendbc .car import DT_CTRL
8
-
9
8
from opendbc .car .interfaces import get_torque_params
10
9
from opendbc .car .values import PLATFORMS
11
10
20
19
21
20
@pytest .fixture
22
21
def car_interface_and_params (request , interfaces ):
23
- car_model = request .param
24
- CarInterface , _ , _ , _ = interfaces [car_model ]
25
- CP = CarInterface .get_non_essential_params (car_model )
22
+ return TestLateralLimits .setup (request .param , interfaces )
26
23
27
- if car_model == 'MOCK' :
28
- pytest .skip ('Mock car' )
24
+ class TestLateralLimits :
25
+ @classmethod
26
+ def setup (cls , car_model , interfaces ):
27
+ cls .car_model = car_model
28
+ CarInterface , _ , _ , _ = interfaces [cls .car_model ]
29
+ CP = CarInterface .get_non_essential_params (cls .car_model )
29
30
30
- # TODO: test all platforms
31
- if CP .steerControlType != 'torque' :
32
- pytest .skip ()
31
+ if cls .car_model == 'MOCK' :
32
+ pytest .skip ('Mock car' )
33
33
34
- if CP .notCar :
35
- pytest .skip ()
34
+ # TODO: test all platforms
35
+ if CP .steerControlType != 'torque' :
36
+ pytest .skip ()
36
37
37
- CarControllerParams = importlib .import_module (f'opendbc.car.{ CP .brand } .values' ).CarControllerParams
38
- control_params = CarControllerParams (CP )
39
- torque_params = get_torque_params ()[car_model ]
40
- return car_model , control_params , torque_params
38
+ if CP .notCar :
39
+ pytest .skip ()
41
40
41
+ CarControllerParams = importlib .import_module (f'opendbc.car.{ CP .brand } .values' ).CarControllerParams
42
+ cls .control_params = CarControllerParams (CP )
43
+ cls .torque_params = get_torque_params ()[cls .car_model ]
44
+ return cls .car_model , cls .control_params , cls .torque_params
42
45
43
- def calculate_0_5s_jerk (control_params , torque_params ):
44
- steer_step = control_params .STEER_STEP
45
- max_lat_accel = torque_params ['MAX_LAT_ACCEL_MEASURED' ]
46
+ @staticmethod
47
+ def calculate_0_5s_jerk (control_params , torque_params ):
48
+ steer_step = control_params .STEER_STEP
49
+ max_lat_accel = torque_params ['MAX_LAT_ACCEL_MEASURED' ]
46
50
47
- # Steer up/down delta per 10ms frame, in percentage of max torque
48
- steer_up_per_frame = control_params .STEER_DELTA_UP / control_params .STEER_MAX / steer_step
49
- steer_down_per_frame = control_params .STEER_DELTA_DOWN / control_params .STEER_MAX / steer_step
51
+ # Steer up/down delta per 10ms frame, in percentage of max torque
52
+ steer_up_per_frame = control_params .STEER_DELTA_UP / control_params .STEER_MAX / steer_step
53
+ steer_down_per_frame = control_params .STEER_DELTA_DOWN / control_params .STEER_MAX / steer_step
50
54
51
- # Lateral acceleration reached in 0.5 seconds, clipping to max torque
52
- accel_up_0_5_sec = min (steer_up_per_frame * JERK_MEAS_T / DT_CTRL , 1.0 ) * max_lat_accel
53
- accel_down_0_5_sec = min (steer_down_per_frame * JERK_MEAS_T / DT_CTRL , 1.0 ) * max_lat_accel
55
+ # Lateral acceleration reached in 0.5 seconds, clipping to max torque
56
+ accel_up_0_5_sec = min (steer_up_per_frame * JERK_MEAS_T / DT_CTRL , 1.0 ) * max_lat_accel
57
+ accel_down_0_5_sec = min (steer_down_per_frame * JERK_MEAS_T / DT_CTRL , 1.0 ) * max_lat_accel
54
58
55
- # Convert to m/s^3
56
- return accel_up_0_5_sec / JERK_MEAS_T , accel_down_0_5_sec / JERK_MEAS_T
59
+ # Convert to m/s^3
60
+ return accel_up_0_5_sec / JERK_MEAS_T , accel_down_0_5_sec / JERK_MEAS_T
57
61
58
- @pytest .mark .parametrize ('car_interface_and_params' , sorted (PLATFORMS ), indirect = True )
59
- def test_jerk_limits (car_interface_and_params ):
60
- _ , control_params , torque_params = car_interface_and_params
61
- up_jerk , down_jerk = calculate_0_5s_jerk (control_params , torque_params )
62
- assert up_jerk <= MAX_LAT_JERK_UP + MAX_LAT_JERK_UP_TOLERANCE
63
- assert down_jerk <= MAX_LAT_JERK_DOWN
62
+ @staticmethod
63
+ @pytest .mark .parametrize ('car_interface_and_params' , sorted (PLATFORMS ), indirect = True )
64
+ def test_jerk_limits (car_interface_and_params ):
65
+ _ , control_params , torque_params = car_interface_and_params
66
+ up_jerk , down_jerk = TestLateralLimits .calculate_0_5s_jerk (control_params , torque_params )
67
+ assert up_jerk <= MAX_LAT_JERK_UP + MAX_LAT_JERK_UP_TOLERANCE
68
+ assert down_jerk <= MAX_LAT_JERK_DOWN
64
69
65
- @pytest .mark .parametrize ('car_interface_and_params' , sorted (PLATFORMS ), indirect = True )
66
- def test_max_lateral_accel (car_interface_and_params ):
67
- _ , _ , torque_params = car_interface_and_params
68
- assert torque_params ["MAX_LAT_ACCEL_MEASURED" ] <= MAX_LAT_ACCEL
70
+ @staticmethod
71
+ @pytest .mark .parametrize ('car_interface_and_params' , sorted (PLATFORMS ), indirect = True )
72
+ def test_max_lateral_accel (car_interface_and_params ):
73
+ _ , _ , torque_params = car_interface_and_params
74
+ assert torque_params ["MAX_LAT_ACCEL_MEASURED" ] <= MAX_LAT_ACCEL
69
75
70
76
71
77
class LatAccelReport :
@@ -88,7 +94,7 @@ def class_setup(self, request):
88
94
yield
89
95
cls = request .cls
90
96
if hasattr (cls , "control_params" ):
91
- up_jerk , down_jerk = calculate_0_5s_jerk (cls .control_params , cls .torque_params )
97
+ up_jerk , down_jerk = TestLateralLimits . calculate_0_5s_jerk (cls .control_params , cls .torque_params )
92
98
self .car_model_jerks [cls .car_model ] = {"up_jerk" : up_jerk , "down_jerk" : down_jerk }
93
99
94
100
0 commit comments