Skip to content

Commit e49748d

Browse files
authored
Chevrolet Bolt: Non-linear torque tune (#27344)
* add non linear tune * update refs * rerun tests
1 parent 6f1d5ed commit e49748d

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

selfdrive/car/gm/interface.py

+42-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/usr/bin/env python3
2+
import numpy as np
23
from cereal import car
34
from math import fabs
45
from panda import Panda
56

7+
from common.numpy_fast import interp
68
from common.conversions import Conversions as CV
79
from selfdrive.car import STD_CARGO_KG, create_button_event, scale_tire_stiffness, get_safety_config
810
from selfdrive.car.gm.values import CAR, CruiseButtons, CarControllerParams, EV_CAR, CAMERA_ACC_CAR
9-
from selfdrive.car.interfaces import CarInterfaceBase
11+
from selfdrive.car.interfaces import CarInterfaceBase, TorqueFromLateralAccelCallbackType, FRICTION_THRESHOLD
12+
from selfdrive.controls.lib.drive_helpers import apply_center_deadzone
1013

1114
ButtonType = car.CarState.ButtonEvent.Type
1215
EventName = car.CarEvent.EventName
@@ -43,6 +46,43 @@ def get_steer_feedforward_function(self):
4346
else:
4447
return CarInterfaceBase.get_steer_feedforward_default
4548

49+
@staticmethod
50+
def torque_from_lateral_accel_bolt(lateral_accel_value, torque_params, lateral_accel_error, lateral_accel_deadzone, vego, friction_compensation):
51+
friction_interp = interp(
52+
apply_center_deadzone(lateral_accel_error, lateral_accel_deadzone),
53+
[-FRICTION_THRESHOLD, FRICTION_THRESHOLD],
54+
[-torque_params.friction, torque_params.friction]
55+
)
56+
friction = friction_interp if friction_compensation else 0.0
57+
steer_torque = lateral_accel_value / torque_params.latAccelFactor
58+
59+
# TODO:
60+
# 1. Learn the correction factors from data
61+
# 2. Generalize the logic to other GM torque control platforms
62+
steer_break_pts = np.array([-1.0, -0.9, -0.75, -0.5, 0.0, 0.5, 0.75, 0.9, 1.0])
63+
steer_lataccel_factors = np.array([1.5, 1.15, 1.02, 1.0, 1.0, 1.0, 1.02, 1.15, 1.5])
64+
steer_correction_factor = np.interp(
65+
steer_torque,
66+
steer_break_pts,
67+
steer_lataccel_factors
68+
)
69+
70+
vego_break_pts = np.array([0.0, 10.0, 15.0, 20.0, 100.0])
71+
vego_lataccel_factors = np.array([1.5, 1.5, 1.25, 1.0, 1.0])
72+
vego_correction_factor = np.interp(
73+
vego,
74+
vego_break_pts,
75+
vego_lataccel_factors,
76+
)
77+
78+
return float((steer_torque + friction) / (steer_correction_factor * vego_correction_factor))
79+
80+
def torque_from_lateral_accel(self) -> TorqueFromLateralAccelCallbackType:
81+
if self.CP.carFingerprint == CAR.BOLT_EUV:
82+
return self.torque_from_lateral_accel_bolt
83+
else:
84+
return self.torque_from_lateral_accel_linear
85+
4686
@staticmethod
4787
def _get_params(ret, candidate, fingerprint, car_fw, experimental_long):
4888
ret.carName = "gm"
@@ -176,7 +216,7 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long):
176216
ret.steerRatio = 16.8
177217
ret.centerToFront = 2.15 # measured
178218
tire_stiffness_factor = 1.0
179-
ret.steerActuatorDelay = 0.2
219+
ret.steerActuatorDelay = 0.12
180220
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)
181221

182222
elif candidate == CAR.SILVERADO:

selfdrive/car/interfaces.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
ButtonType = car.CarState.ButtonEvent.Type
1919
GearShifter = car.CarState.GearShifter
2020
EventName = car.CarEvent.EventName
21-
TorqueFromLateralAccelCallbackType = Callable[[float, car.CarParams.LateralTorqueTuning, float, float, bool], float]
21+
TorqueFromLateralAccelCallbackType = Callable[[float, car.CarParams.LateralTorqueTuning, float, float, float, bool], float]
2222

2323
MAX_CTRL_SPEED = (V_CRUISE_MAX + 4) * CV.KPH_TO_MS
2424
ACCEL_MAX = 2.0
@@ -131,7 +131,7 @@ def get_steer_feedforward_function(self):
131131
return self.get_steer_feedforward_default
132132

133133
@staticmethod
134-
def torque_from_lateral_accel_linear(lateral_accel_value, torque_params, lateral_accel_error, lateral_accel_deadzone, friction_compensation):
134+
def torque_from_lateral_accel_linear(lateral_accel_value, torque_params, lateral_accel_error, lateral_accel_deadzone, vego, friction_compensation):
135135
# The default is a linear relationship between torque and lateral acceleration (accounting for road roll and steering friction)
136136
friction_interp = interp(
137137
apply_center_deadzone(lateral_accel_error, lateral_accel_deadzone),

selfdrive/controls/lib/latcontrol_torque.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ def update(self, active, CS, VM, params, last_actuators, steer_limited, desired_
6464
error = setpoint - measurement
6565
gravity_adjusted_lateral_accel = desired_lateral_accel - params.roll * ACCELERATION_DUE_TO_GRAVITY
6666
pid_log.error = self.torque_from_lateral_accel(error, self.torque_params, error,
67-
lateral_accel_deadzone, friction_compensation=False)
67+
lateral_accel_deadzone, CS.vEgo, friction_compensation=False)
6868
ff = self.torque_from_lateral_accel(gravity_adjusted_lateral_accel, self.torque_params,
6969
desired_lateral_accel - actual_lateral_accel,
70-
lateral_accel_deadzone, friction_compensation=True)
70+
lateral_accel_deadzone, CS.vEgo, friction_compensation=True)
7171

7272
freeze_integrator = steer_limited or CS.steeringPressed or CS.vEgo < 5
7373
output_torque = self.pid.update(pid_log.error,
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f4efbb65a7eb9a8f4e23492372e707674f80114e
1+
3e53ce81f1ce26409fdc4479e650ef5626130876

0 commit comments

Comments
 (0)