Soften Tucson steering feedback in shallow curves

This commit is contained in:
firestar5683
2026-11-27 00:10:21 -06:00
parent bdef37d674
commit 6b79f7a227
4 changed files with 28 additions and 4 deletions
@@ -66,7 +66,7 @@ class HKGShapedTorquePolicy:
def jerk_deadzone(self, setpoint, jerk, measurement, speed):
return 0.0
def pid_error_context(self, error):
def pid_error_context(self, error, setpoint, speed):
return error
def output_context(self, value, setpoint, jerk, measurement, speed):
@@ -121,7 +121,7 @@ class HKGShapedTorquePolicy:
if cs.vEgo < self.low_speed_reset_threshold:
parent.pid.reset()
freeze = safety_limited or cs.steeringPressed or cs.vEgo < self.low_speed_reset_threshold or unwind
pid_log.error = float(self.pid_error_context(error))
pid_log.error = float(self.pid_error_context(error, setpoint, cs.vEgo))
output = parent.torque_from_lateral_accel(
parent.pid.update(pid_log.error, error_rate=-rate, speed=cs.vEgo, feedforward=ff, freeze_integrator=freeze), parent.torque_params
)
@@ -163,7 +163,11 @@ class HKGVehicleTorquePolicy(HKGShapedTorquePolicy):
return shaping.get_kona_ev_2022_friction_threshold(speed, setpoint), 1
return (base, 1.0)
def pid_error_context(self, error):
def pid_error_context(self, error, setpoint, speed):
if self.profile == 'tucson_4th_gen' and not (self.steering_pressed or self.previous_pressed):
speed_weight = np.interp(speed, (4., 7., 18., 22.), (0., 1., 1., 0.))
shallow_curve = np.interp(abs(setpoint), (.65, 1.15), (1., 0.))
return error * (1.0 - .15 * speed_weight * shallow_curve)
return error * (1.0 - shaping.KIA_CARNIVAL_HEV_CENTER_ERROR_REDUCTION * self.hev_center_weight)
def jerk_deadzone(self, setpoint, jerk, measurement, speed):
@@ -164,3 +164,23 @@ class HKGHighwayFrictionTests(unittest.TestCase):
value = controller.friction(error, .01, threshold, cs, setpoint)
self.assertEqual(friction.call_args.args, (error, .01, threshold, controller.torque_params))
self.assertEqual(value, get_friction(error, .01, threshold, controller.torque_params))
def test_tucson_softens_shallow_curve_feedback_in_both_cruise_modes():
for alpha_long in (False, True):
_, controller = controller_for(CAR.HYUNDAI_TUCSON_4TH_GEN, ControllerMode.STARPILOT,
openpilotLongitudinalControl=alpha_long, pcmCruise=not alpha_long)
policy = controller.starpilot_extension.policy
for direction in (-1., 1.):
assert math.isclose(policy.pid_error_context(direction, direction * .5, 13.), direction * .85)
for speed, demand in ((4., .5), (22., .5), (13., 1.15)):
assert policy.pid_error_context(direction, direction * demand, speed) == direction
for field in ('steering_pressed', 'previous_pressed'):
setattr(policy, field, True)
assert policy.pid_error_context(1., .5, 13.) == 1.
setattr(policy, field, False)
_, other = controller_for(CAR.KIA_EV6, ControllerMode.STARPILOT)
assert other.starpilot_extension.policy.pid_error_context(1., .5, 13.) == 1.
_, standard = controller_for(CAR.HYUNDAI_TUCSON_4TH_GEN, ControllerMode.STANDARD)
assert standard.starpilot_extension is None
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "3270dcbad49e72ae86330f984d15691dda5480d4bf1f4f7c51fcc9d19b4e4a92", "schema_version": 1}
{"protected_inventory_sha256": "ee1fbfb2b039de398632730e8c6db23efbbceeddc8c99fbaa5b9250c6dd4035e", "schema_version": 1}