diff --git a/openpilot/starpilot/lateral/hkg_vehicle_policy.py b/openpilot/starpilot/lateral/hkg_vehicle_policy.py index cc14c7d203..4cda250c03 100644 --- a/openpilot/starpilot/lateral/hkg_vehicle_policy.py +++ b/openpilot/starpilot/lateral/hkg_vehicle_policy.py @@ -180,7 +180,15 @@ class HKGVehicleTorquePolicy(HKGShapedTorquePolicy): transition = np.interp(abs(self.jerk_filter.x), (.8, 1.5), (1., 0.)) feedback = np.interp(abs(error), (.14, .38), (0., 1.)) damping += .35 * highway * curve * transition * feedback - return error * (1.0 - damping) + feedback = error * (1.0 - damping) + if abs(error) > .12 and abs(setpoint) < 1.55 and (1. < speed < 5. or 15. < speed < 31.): + road_weight = np.interp(speed, (15., 18., 27., 31.), (0., 1., 1., 0.)) + crawl_weight = np.interp(speed, (1., 2., 3.5, 5.), (0., 1., 1., 0.)) + turn_weight = np.interp(abs(setpoint), (.62, 1.55), (1., 0.)) + steady_weight = np.interp(abs(self.jerk_filter.x), (.65, 1.5), (1., 0.)) + error_weight = np.interp(abs(error), (.12, .38), (0., 1.)) + feedback *= 1.0 - (.42 * road_weight + .22 * crawl_weight) * turn_weight * steady_weight * error_weight + return feedback return error * (1.0 - shaping.KIA_CARNIVAL_HEV_CENTER_ERROR_REDUCTION * self.hev_center_weight) def jerk_deadzone(self, setpoint, jerk, measurement, speed): diff --git a/openpilot/starpilot/lateral/tests/test_hkg_highway_friction.py b/openpilot/starpilot/lateral/tests/test_hkg_highway_friction.py index 480ff3c40c..fd6f530f64 100644 --- a/openpilot/starpilot/lateral/tests/test_hkg_highway_friction.py +++ b/openpilot/starpilot/lateral/tests/test_hkg_highway_friction.py @@ -174,9 +174,9 @@ def test_tucson_softens_shallow_curve_feedback_in_both_cruise_modes(): policy = controller.starpilot_extension.policy for direction in (-1., 1.): assert math.isclose(policy.pid_error_context(direction, direction * .5, 13.), direction * .55) - for speed, demand in ((4., .5), (31., .5), (13., 1.15)): + for speed, demand in ((1., .5), (31., .5), (13., 1.15)): assert policy.pid_error_context(direction, direction * demand, speed) == direction - for demand, speed, base_scale in ((.5, 19., .8875), (.9, 13., .925)): + for demand, speed, base_scale in ((.5, 19., .8875 * .58), (.9, 13., .925)): assert math.isclose(policy.pid_error_context(1., demand, speed), base_scale) policy.jerk_filter.x = -1.0 assert math.isclose(policy.pid_error_context(1., .5, 13.), .85) @@ -196,7 +196,7 @@ def test_tucson_highway_feedback_damps_large_errors_without_touching_steady_trac _, controller = controller_for(CAR.HYUNDAI_TUCSON_4TH_GEN, ControllerMode.STARPILOT) policy = controller.starpilot_extension.policy for side in (-1., 1.): - assert math.isclose(policy.pid_error_context(side * .5, side * .8, 25.), side * .325) + assert math.isclose(policy.pid_error_context(side * .5, side * .8, 25.), side * .325 * (1. - .42 * (1.55 - .8) / (1.55 - .62))) assert policy.pid_error_context(side * .1, side * .8, 25.) == side * .1 assert policy.pid_error_context(side * .5, side * 1.7, 25.) == side * .5 assert policy.pid_error_context(side * .5, side * .8, 31.) == side * .5 @@ -247,3 +247,24 @@ def test_tucson_damps_large_road_speed_corrections_in_both_cruise_modes(): setattr(policy, pressed, True) assert scale(22., .7, .52) == scale(22., .7, .0) setattr(policy, pressed, False) + + + +def test_tucson_reduces_wobble_feedback_without_dulling_small_corrections(): + 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.): + assert math.isclose(policy.pid_error_context(side * .5, side * .5, 2.5), side * .39) + assert math.isclose(policy.pid_error_context(side * .5, side * .5, 20.), side * .5 * .925 * .58) + assert policy.pid_error_context(side * .1, side * .5, 2.5) == side * .1 + assert policy.pid_error_context(side * .5, side * 1.55, 20.) == side * .5 + assert policy.pid_error_context(side * .5, side * .5, 1.) == side * .5 + policy.jerk_filter.x = 1.5 + assert math.isclose(policy.pid_error_context(side * .5, side * .5, 20.), side * .5 * .925) + policy.jerk_filter.x = 0. + for field in ('steering_pressed', 'previous_pressed'): + setattr(policy, field, True) + assert policy.pid_error_context(side * .5, side * .5, 20.) == side * .5 + setattr(policy, field, False) diff --git a/prebuilt.json b/prebuilt.json index 06d464b560..c24a87da36 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "cc0b33df4c5668611841a226ad800d762ec35c406951b93803e36ee5504adf68", "schema_version": 1} +{"protected_inventory_sha256": "146ab4f3093ffecff75b0d692a6effa00182c5b6b0e5706d0839092de3da59c6", "schema_version": 1}