|
1 | 1 | #!/usr/bin/env python3
|
| 2 | +import numpy as np |
2 | 3 | from cereal import car
|
3 | 4 | from math import fabs
|
4 | 5 | from panda import Panda
|
5 | 6 |
|
| 7 | +from common.numpy_fast import interp |
6 | 8 | from common.conversions import Conversions as CV
|
7 | 9 | from selfdrive.car import STD_CARGO_KG, create_button_event, scale_tire_stiffness, get_safety_config
|
8 | 10 | 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 |
10 | 13 |
|
11 | 14 | ButtonType = car.CarState.ButtonEvent.Type
|
12 | 15 | EventName = car.CarEvent.EventName
|
@@ -43,6 +46,43 @@ def get_steer_feedforward_function(self):
|
43 | 46 | else:
|
44 | 47 | return CarInterfaceBase.get_steer_feedforward_default
|
45 | 48 |
|
| 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 | + |
46 | 86 | @staticmethod
|
47 | 87 | def _get_params(ret, candidate, fingerprint, car_fw, experimental_long):
|
48 | 88 | ret.carName = "gm"
|
@@ -176,7 +216,7 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long):
|
176 | 216 | ret.steerRatio = 16.8
|
177 | 217 | ret.centerToFront = 2.15 # measured
|
178 | 218 | tire_stiffness_factor = 1.0
|
179 |
| - ret.steerActuatorDelay = 0.2 |
| 219 | + ret.steerActuatorDelay = 0.12 |
180 | 220 | CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)
|
181 | 221 |
|
182 | 222 | elif candidate == CAR.SILVERADO:
|
|
0 commit comments