mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-24 09:43:47 +08:00
Compare commits
87 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 14b1793c79 | |||
| 055c223ded | |||
| 4d406112f7 | |||
| e03f28bba0 | |||
| f0cc963c0e | |||
| cd39ce0305 | |||
| 749b5e06fb | |||
| 23121cca0e | |||
| 6f0502e862 | |||
| 04c59fb18e | |||
| 844dce2030 | |||
| aa77db1fc9 | |||
| bee9b2b046 | |||
| 469cd5e528 | |||
| 23f52644ae | |||
| e76b82603b | |||
| 1b5d776464 | |||
| 61f4e8b142 | |||
| f0fefb6e13 | |||
| 25a7090c3d | |||
| b0de4d64b4 | |||
| 77ae5b176a | |||
| 89de28682c | |||
| a1d4dcb9a0 | |||
| c8deae75b7 | |||
| 8653fb41f2 | |||
| c064197fde | |||
| 7f878ec1dc | |||
| 140bdd59fb | |||
| 6f728f935a | |||
| 568b72095f | |||
| 0aaf4d1336 | |||
| bb3f0a3354 | |||
| f2aba355b9 | |||
| e6513efb9b | |||
| 872a2c58aa | |||
| 1630560715 | |||
| 4cfd893837 | |||
| 0e93ceef00 | |||
| d626f0fe49 | |||
| 8dae3d375c | |||
| 721d39ef1f | |||
| a97c5742b7 | |||
| 488f821983 | |||
| 190dc98180 | |||
| 0b459d9f0b | |||
| 3cd594bbe4 | |||
| f31082ce2b | |||
| b51d7ae35d | |||
| 884fcb8315 | |||
| 77597e60b2 | |||
| f2fbc8f30b | |||
| fffea614a4 | |||
| e7e593cdb2 | |||
| 97f8736605 | |||
| 48efc5b97a | |||
| 4cca6553e4 | |||
| 6eda52b562 | |||
| de9cbc5de6 | |||
| fee241dc0b | |||
| 2094be9a7a | |||
| 6ce476025d | |||
| dd6c62dbf6 | |||
| 2ab19dbd4c | |||
| 3241fbdd8c | |||
| 1f0350e66a | |||
| ce46776439 | |||
| afb209a1a8 | |||
| b4e29d4ed6 | |||
| dada0f2ae6 | |||
| 4532e7f5d1 | |||
| 78de442ee1 | |||
| 953b343e06 | |||
| 5b26be2e3c | |||
| 4abe50405c | |||
| f2e705413c | |||
| da56f26105 | |||
| ab39266180 | |||
| dac85dfd3a | |||
| 7e539cde38 | |||
| 16a79fbc3d | |||
| 9cdf0120cf | |||
| aa0f0aaac8 | |||
| aefaafb616 | |||
| 388f63168f | |||
| 7fe40f6e7f | |||
| eb2218e733 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,11 +1,11 @@
|
||||
const SteeringLimits GM_STEERING_LIMITS = {
|
||||
.max_steer = 450,
|
||||
.max_rate_up = 15,
|
||||
.max_rate_down = 34,
|
||||
.driver_torque_allowance = 78,
|
||||
.driver_torque_factor = 6,
|
||||
.max_rt_delta = 345,
|
||||
.max_rt_interval = 200000,
|
||||
.max_steer = 300,
|
||||
.max_rate_up = 10,
|
||||
.max_rate_down = 15,
|
||||
.driver_torque_allowance = 65,
|
||||
.driver_torque_factor = 4,
|
||||
.max_rt_delta = 128,
|
||||
.max_rt_interval = 250000,
|
||||
.type = TorqueDriverLimited,
|
||||
};
|
||||
|
||||
|
||||
@@ -27,10 +27,22 @@ CAM_MSG = 0x320 # AEBCmd
|
||||
ACCELERATOR_POS_MSG = 0xbe
|
||||
|
||||
NON_LINEAR_TORQUE_PARAMS = {
|
||||
CAR.CHEVROLET_BOLT_EUV: [2.15, 1.0, 0.21, 0.0],
|
||||
CAR.CHEVROLET_BOLT_CC: [2.15, 1.0, 0.21, 0.0],
|
||||
CAR.GMC_ACADIA: [4.78003305, 1.0, 0.3122, 0.05591772],
|
||||
CAR.CHEVROLET_SILVERADO: [3.29974374, 1.0, 0.25571356, 0.0465122]
|
||||
CAR.CHEVROLET_BOLT_EUV: {
|
||||
"left": [1.8, 1.1, 0.27, 0.0],
|
||||
"right": [2.0, 1.0, 0.205, 0.0],
|
||||
},
|
||||
CAR.CHEVROLET_BOLT_CC: {
|
||||
"left": [1.8, 1.1, 0.27, 0.0],
|
||||
"right": [2.0, 1.0, 0.205, 0.0],
|
||||
},
|
||||
CAR.GMC_ACADIA: {
|
||||
"left": [4.78003305, 1.0, 0.3122, 0.05591772],
|
||||
"right": [4.78003305, 1.0, 0.3122, 0.05591772],
|
||||
},
|
||||
CAR.CHEVROLET_SILVERADO: {
|
||||
"left": [3.29974374, 1.0, 0.25571356, 0.0465122],
|
||||
"right": [3.29974374, 1.0, 0.25571356, 0.0465122],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +76,9 @@ class CarInterface(CarInterfaceBase):
|
||||
# This has big effect on the stability about 0 (noise when going straight)
|
||||
non_linear_torque_params = NON_LINEAR_TORQUE_PARAMS.get(self.CP.carFingerprint)
|
||||
assert non_linear_torque_params, "The params are not defined"
|
||||
a, b, c, d = non_linear_torque_params
|
||||
# Left is positive
|
||||
side_key = "left" if lateral_acceleration >= 0 else "right"
|
||||
a, b, c, d = non_linear_torque_params[side_key]
|
||||
sig_input = a * lateral_acceleration
|
||||
sig = np.sign(sig_input) * (1 / (1 + exp(-fabs(sig_input))) - 0.5)
|
||||
steer_torque = (sig * b) + (lateral_acceleration * c) + d
|
||||
@@ -225,6 +239,12 @@ class CarInterface(CarInterfaceBase):
|
||||
ret.steerActuatorDelay = 0.2
|
||||
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)
|
||||
|
||||
# Bolt-only lateral tuning overrides
|
||||
ret.lateralTuning.torque.kp = 1.03
|
||||
ret.lateralTuning.torque.ki = 1.07
|
||||
ret.lateralTuning.torque.kd = 0.93
|
||||
ret.lateralTuning.torque.kfDEPRECATED = 0.02
|
||||
|
||||
if ret.enableGasInterceptor:
|
||||
# ACC Bolts use pedal for full longitudinal control, not just sng
|
||||
ret.flags |= GMFlags.PEDAL_LONG.value
|
||||
|
||||
@@ -11,13 +11,13 @@ Ecu = car.CarParams.Ecu
|
||||
|
||||
|
||||
class CarControllerParams:
|
||||
STEER_MAX = 450 # GM limit is 3Nm. Used by carcontroller to generate LKA output
|
||||
STEER_MAX = 300 # GM limit is 3Nm. Used by carcontroller to generate LKA output
|
||||
STEER_STEP = 3 # Active control frames per command (~33hz)
|
||||
INACTIVE_STEER_STEP = 10 # Inactive control frames per command (10hz)
|
||||
STEER_DELTA_UP = 15 # Delta rates require review due to observed EPS weakness
|
||||
STEER_DELTA_DOWN = 34
|
||||
STEER_DRIVER_ALLOWANCE = 78
|
||||
STEER_DRIVER_MULTIPLIER = 6
|
||||
STEER_DELTA_UP = 10 # Delta rates require review due to observed EPS weakness
|
||||
STEER_DELTA_DOWN = 15
|
||||
STEER_DRIVER_ALLOWANCE = 65
|
||||
STEER_DRIVER_MULTIPLIER = 4
|
||||
STEER_DRIVER_FACTOR = 100
|
||||
NEAR_STOP_BRAKE_PHASE = 0.25 # m/s
|
||||
SNG_INTERCEPTOR_GAS = 18. / 255.
|
||||
|
||||
@@ -37,12 +37,12 @@ EventName = car.CarEvent.EventName
|
||||
MAX_CTRL_SPEED = (V_CRUISE_MAX + 4) * CV.KPH_TO_MS
|
||||
ACCEL_MAX = 2.0
|
||||
ACCEL_MIN = -3.5
|
||||
FRICTION_THRESHOLD = 0.09
|
||||
FRICTION_THRESHOLD = 0.12
|
||||
|
||||
def get_friction_threshold(v_ego):
|
||||
# Interpolate friction threshold from 0.09 at 50 mph to 0.15 at 75 mph
|
||||
# Interpolate friction threshold
|
||||
from openpilot.common.numpy_fast import interp
|
||||
return interp(v_ego, [1 * CV.MPH_TO_MS, 75 * CV.MPH_TO_MS], [0.12, 0.25])
|
||||
return interp(v_ego, [1 * CV.MPH_TO_MS, 75 * CV.MPH_TO_MS], [0.12, 0.3])
|
||||
|
||||
TORQUE_PARAMS_PATH = os.path.join(BASEDIR, 'selfdrive/car/torque_data/params.toml')
|
||||
TORQUE_OVERRIDE_PATH = os.path.join(BASEDIR, 'selfdrive/car/torque_data/override.toml')
|
||||
|
||||
@@ -43,7 +43,7 @@ legend = ["LAT_ACCEL_FACTOR", "MAX_LAT_ACCEL_MEASURED", "FRICTION"]
|
||||
"CADILLAC_ESCALADE" = [1.899999976158142, 1.842270016670227, 0.1120000034570694]
|
||||
"CADILLAC_ESCALADE_ESV_2019" = [1.15, 1.3, 0.2]
|
||||
"CADILLAC_XT4" = [1.45, 1.6, 0.2]
|
||||
"CHEVROLET_BOLT_EUV" = [2.0, 2.0, 0.05]
|
||||
"CHEVROLET_BOLT_EUV" = [2.0, 2.0, 0.09]
|
||||
"CHEVROLET_MALIBU_CC" = [1.85, 1.85, 0.075]
|
||||
"CHEVROLET_SILVERADO" = [1.9, 1.9, 0.112]
|
||||
"CHEVROLET_TRAILBLAZER" = [1.33, 1.9, 0.16]
|
||||
|
||||
@@ -7,6 +7,7 @@ from openpilot.selfdrive.car.interfaces import FRICTION_THRESHOLD, get_friction_
|
||||
from openpilot.selfdrive.controls.lib.drive_helpers import MIN_SPEED, get_friction
|
||||
from openpilot.common.filter_simple import FirstOrderFilter
|
||||
from openpilot.selfdrive.controls.lib.latcontrol import LatControl, MIN_LATERAL_CONTROL_SPEED
|
||||
from openpilot.selfdrive.car.gm.values import CAR as GM_CAR
|
||||
from openpilot.selfdrive.controls.lib.pid import PIDController
|
||||
from openpilot.selfdrive.controls.lib.vehicle_model import ACCELERATION_DUE_TO_GRAVITY
|
||||
|
||||
@@ -21,8 +22,8 @@ from openpilot.selfdrive.controls.lib.vehicle_model import ACCELERATION_DUE_TO_G
|
||||
# Additionally, there is friction in the steering wheel that needs
|
||||
# to be overcome to move it at all, this is compensated for too.
|
||||
|
||||
KP = 0.6
|
||||
KI = 0.3
|
||||
KP = 0.7
|
||||
KI = 0.35
|
||||
|
||||
INTERP_SPEEDS = [1, 1.5, 2.0, 3.0, 5, 7.5, 10, 15, 30]
|
||||
KP_INTERP = [250, 120, 65, 30, 11.5, 5.5, 3.5, 2.0, KP]
|
||||
@@ -36,6 +37,13 @@ JERK_LOOKAHEAD_SECONDS = 0.19
|
||||
JERK_GAIN = 0.22
|
||||
LAT_ACCEL_REQUEST_BUFFER_SECONDS = 1.0
|
||||
VERSION = 2
|
||||
DEBUG_TORQUE_TUNE = False
|
||||
FF_SCALE_BLEND_LAT_ACCEL = 0.05
|
||||
DEADZONE_BOOST_LAT_ACCEL = 0.08
|
||||
UNWIND_D_DES_THRESHOLD = -1.0
|
||||
UNWIND_LAT_ACCEL_NEAR_ZERO = 0.3
|
||||
|
||||
BOLT_CARS = (GM_CAR.CHEVROLET_BOLT_EUV, GM_CAR.CHEVROLET_BOLT_CC)
|
||||
|
||||
class LatControlTorque(LatControl):
|
||||
def __init__(self, CP, CI, dt):
|
||||
@@ -55,6 +63,21 @@ class LatControlTorque(LatControl):
|
||||
self.previous_measurement = 0.0
|
||||
self.measurement_rate_filter = FirstOrderFilter(0.0, 1 / (2 * np.pi * (MAX_LAT_JERK_UP - 0.5)), self.dt)
|
||||
self.low_speed_reset_threshold = max(CP.minSteerSpeed, MIN_LATERAL_CONTROL_SPEED)
|
||||
self.debug_counter = 0
|
||||
self.prev_desired_lateral_accel = 0.0
|
||||
|
||||
self.is_bolt = CP.carFingerprint in BOLT_CARS
|
||||
self.torque_ff_scale_pos = 1.0
|
||||
self.torque_ff_scale_neg = 1.0
|
||||
self.torque_deadzone_boost_neg = 0.0
|
||||
self.torque_ki_mult = 1.0
|
||||
if self.is_bolt:
|
||||
self.torque_ff_scale_pos = float(self.torque_params.kp)
|
||||
self.torque_ff_scale_neg = float(self.torque_params.ki)
|
||||
self.torque_ki_mult = float(self.torque_params.kd)
|
||||
self.torque_deadzone_boost_neg = float(getattr(self.torque_params, "kfDEPRECATED", 0.0))
|
||||
if self.torque_ki_mult > 0.0 and self.torque_ki_mult != 1.0:
|
||||
self.pid._k_i = [self.pid._k_i[0], [k * self.torque_ki_mult for k in self.pid._k_i[1]]]
|
||||
|
||||
def update_live_torque_params(self, latAccelFactor, latAccelOffset, friction):
|
||||
self.torque_params.latAccelFactor = latAccelFactor
|
||||
@@ -76,6 +99,7 @@ class LatControlTorque(LatControl):
|
||||
self.previous_measurement = 0.0
|
||||
self.measurement_rate_filter.x = 0.0
|
||||
self.lat_accel_request_buffer = deque([0.] * self.lat_accel_request_buffer_len , maxlen=self.lat_accel_request_buffer_len)
|
||||
self.prev_desired_lateral_accel = 0.0
|
||||
else:
|
||||
if self.prev_steering_pressed and not CS.steeringPressed:
|
||||
self.pid.i *= self.steer_release_i_decay
|
||||
@@ -94,6 +118,10 @@ class LatControlTorque(LatControl):
|
||||
desired_lateral_jerk = np.clip(self.jerk_filter.update(raw_lateral_jerk), -MAX_LAT_JERK_UP, MAX_LAT_JERK_UP)
|
||||
gravity_adjusted_future_lateral_accel = future_desired_lateral_accel - roll_compensation
|
||||
setpoint = expected_lateral_accel + desired_lateral_jerk * lat_delay
|
||||
desired_lateral_accel_rate = (setpoint - self.prev_desired_lateral_accel) / self.dt
|
||||
unwind_detected = (desired_lateral_accel_rate < UNWIND_D_DES_THRESHOLD and
|
||||
abs(setpoint) < UNWIND_LAT_ACCEL_NEAR_ZERO)
|
||||
self.prev_desired_lateral_accel = setpoint
|
||||
|
||||
measurement = measured_curvature * CS.vEgo ** 2
|
||||
measurement_rate = self.measurement_rate_filter.update((measurement - self.previous_measurement) / self.dt)
|
||||
@@ -110,11 +138,23 @@ class LatControlTorque(LatControl):
|
||||
ff = gravity_adjusted_future_lateral_accel
|
||||
# latAccelOffset corrects roll compensation bias from device roll misalignment relative to car roll
|
||||
ff -= self.torque_params.latAccelOffset
|
||||
ff_scale = 1.0
|
||||
if self.is_bolt:
|
||||
ff_scale = np.interp(ff, [-FF_SCALE_BLEND_LAT_ACCEL, 0.0, FF_SCALE_BLEND_LAT_ACCEL],
|
||||
[self.torque_ff_scale_neg, 1.0, self.torque_ff_scale_pos])
|
||||
ff *= ff_scale
|
||||
ff += get_friction(error_with_lsf + JERK_GAIN * desired_lateral_jerk, lateral_accel_deadzone, get_friction_threshold(CS.vEgo), self.torque_params)
|
||||
deadzone_boost_active = False
|
||||
if self.is_bolt and self.torque_deadzone_boost_neg > 0.0 and gravity_adjusted_future_lateral_accel < 0.0:
|
||||
if abs(gravity_adjusted_future_lateral_accel) < DEADZONE_BOOST_LAT_ACCEL:
|
||||
boost_scale = np.interp(abs(gravity_adjusted_future_lateral_accel), [0.0, DEADZONE_BOOST_LAT_ACCEL], [1.0, 0.0])
|
||||
ff -= self.torque_deadzone_boost_neg * boost_scale
|
||||
deadzone_boost_active = True
|
||||
|
||||
if CS.vEgo < self.low_speed_reset_threshold:
|
||||
self.pid.reset()
|
||||
freeze_integrator = steer_limited_by_safety or CS.steeringPressed or CS.vEgo < self.low_speed_reset_threshold
|
||||
freeze_integrator = (steer_limited_by_safety or CS.steeringPressed or
|
||||
CS.vEgo < self.low_speed_reset_threshold or unwind_detected)
|
||||
output_lataccel = self.pid.update(pid_log.error, error_rate=-measurement_rate, speed=CS.vEgo, feedforward=ff, freeze_integrator=freeze_integrator)
|
||||
output_torque = self.torque_from_lateral_accel(output_lataccel, self.torque_params)
|
||||
|
||||
@@ -129,6 +169,12 @@ class LatControlTorque(LatControl):
|
||||
pid_log.desiredLateralJerk = float(desired_lateral_jerk)
|
||||
pid_log.saturated = bool(self._check_saturation(self.steer_max - abs(output_torque) < 1e-3, CS, steer_limited_by_safety, curvature_limited))
|
||||
|
||||
if DEBUG_TORQUE_TUNE and self.is_bolt:
|
||||
self.debug_counter += 1
|
||||
if self.debug_counter % 50 == 0:
|
||||
print(f"bolt_torque ff_scale={ff_scale:.3f} pos={self.torque_ff_scale_pos:.3f} "
|
||||
f"neg={self.torque_ff_scale_neg:.3f} deadzone_boost_active={deadzone_boost_active}")
|
||||
|
||||
self.prev_steering_pressed = CS.steeringPressed
|
||||
|
||||
# TODO left is positive in this convention
|
||||
|
||||
@@ -180,6 +180,14 @@ def manager_init() -> None:
|
||||
with open(lateral_tuning_migration_flag_file, "w") as f:
|
||||
f.write("migrated")
|
||||
|
||||
# One-time migration for MaxDesiredAcceleration to 4
|
||||
max_desired_acceleration_migration_flag_file = "/data/media/0/frogpilot_max_desired_acceleration_migrated.flag"
|
||||
if not os.path.exists(max_desired_acceleration_migration_flag_file):
|
||||
if params.get_float("MaxDesiredAcceleration") != 4.0:
|
||||
params.put_float("MaxDesiredAcceleration", 4.0)
|
||||
with open(max_desired_acceleration_migration_flag_file, "w") as f:
|
||||
f.write("migrated")
|
||||
|
||||
# set dongle id
|
||||
reg_res = register(show_spinner=True)
|
||||
if reg_res:
|
||||
|
||||
Reference in New Issue
Block a user