diff --git a/openpilot/starpilot/lateral/hkg_vehicle_policy.py b/openpilot/starpilot/lateral/hkg_vehicle_policy.py index 07aafda04d..18cbd99b95 100644 --- a/openpilot/starpilot/lateral/hkg_vehicle_policy.py +++ b/openpilot/starpilot/lateral/hkg_vehicle_policy.py @@ -211,7 +211,13 @@ class HKGVehicleTorquePolicy(HKGShapedTorquePolicy): * shaping.get_kia_carnival_highway_transition_output_scale(setpoint, jerk, speed) ) if self.profile == 'tucson_4th_gen': - return value * shaping.get_tucson_4th_gen_center_taper_scale(setpoint, speed) + value *= shaping.get_tucson_4th_gen_center_taper_scale(setpoint, speed) + if 5.0 < speed < 21.0 and abs(setpoint) < 1.25 and abs(setpoint - measurement) > .16: + speed_weight = np.interp(speed, (5., 7., 16., 21.), (0., 1., 1., 0.)) + turn_weight = np.interp(abs(setpoint), (.75, 1.25), (1., 0.)) + error_weight = np.interp(abs(setpoint - measurement), (.16, .60), (0., 1.)) + value *= 1.0 - .35 * speed_weight * turn_weight * error_weight + return value if self.profile == 'kona_non_scc': value *= shaping.get_kona_non_scc_center_taper_scale(setpoint, speed) if value * setpoint > 0 or setpoint * jerk < 0: diff --git a/openpilot/starpilot/lateral/tests/test_hkg_highway_friction.py b/openpilot/starpilot/lateral/tests/test_hkg_highway_friction.py index 2d88fe728e..83eebf32f2 100644 --- a/openpilot/starpilot/lateral/tests/test_hkg_highway_friction.py +++ b/openpilot/starpilot/lateral/tests/test_hkg_highway_friction.py @@ -206,3 +206,23 @@ def test_tucson_highway_feedback_damps_large_errors_without_touching_steady_trac setattr(policy, field, True) assert policy.pid_error_context(.5, .8, 25.) == .5 setattr(policy, field, False) + + +def test_tucson_damps_large_shallow_turn_corrections_at_city_speeds(): + 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 side in (-1., 1.): + request = side * .55 + speed = 12. + nominal = policy.output_context(side, request, 0., request, speed) + near = policy.output_context(side, request, 0., request - side * .1, speed) + moderate = policy.output_context(side, request, 0., request - side * .38, speed) + far = policy.output_context(side, request, 0., request - side * .6, speed) + assert near == nominal + assert math.isclose(moderate, nominal * .825) + assert math.isclose(far, nominal * .65) + for unmodified_request, unmodified_speed in ((request, 5.), (request, 21.), (side * 1.25, speed)): + assert policy.output_context(side, unmodified_request, 0., unmodified_request - side, unmodified_speed) == \ + policy.output_context(side, unmodified_request, 0., unmodified_request, unmodified_speed) diff --git a/prebuilt.json b/prebuilt.json index 5e29ef9cbe..844d9e2afb 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "1b36278aa0f48e3fced1834e5784dd3b4533b64ae60335db294d23c5bb1beac7", "schema_version": 1} +{"protected_inventory_sha256": "eff0a83f9023b678da553c027dce6b47766ddf265fd5483feb899d27c4a6b489", "schema_version": 1}