diff --git a/openpilot/starpilot/lateral/hkg_vehicle_policy.py b/openpilot/starpilot/lateral/hkg_vehicle_policy.py index b8368dd546..cc14c7d203 100644 --- a/openpilot/starpilot/lateral/hkg_vehicle_policy.py +++ b/openpilot/starpilot/lateral/hkg_vehicle_policy.py @@ -220,6 +220,12 @@ class HKGVehicleTorquePolicy(HKGShapedTorquePolicy): 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 + if (16.0 < speed < 31.0 and abs(setpoint) < 1.35 and abs(setpoint - measurement) > .16 and + not (self.steering_pressed or self.previous_pressed)): + speed_weight = np.interp(speed, (16., 20., 27., 31.), (0., 1., 1., 0.)) + turn_weight = np.interp(abs(setpoint), (.85, 1.35), (1., 0.)) + error_weight = np.interp(abs(setpoint - measurement), (.16, .52), (0., 1.)) + value *= 1.0 - .28 * 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) diff --git a/openpilot/starpilot/lateral/tests/test_hkg_highway_friction.py b/openpilot/starpilot/lateral/tests/test_hkg_highway_friction.py index b38157f9ba..480ff3c40c 100644 --- a/openpilot/starpilot/lateral/tests/test_hkg_highway_friction.py +++ b/openpilot/starpilot/lateral/tests/test_hkg_highway_friction.py @@ -224,6 +224,26 @@ def test_tucson_damps_large_shallow_turn_corrections_at_city_speeds(): 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)): + for unmodified_request, unmodified_speed in ((request, 5.), (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) + + + +def test_tucson_damps_large_road_speed_corrections_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 side in (-1., 1.): + def scale(speed, request, error, policy=policy, side=side): + return policy.output_context(side, side * request, 0., side * (request - error), speed) / side + + assert math.isclose(scale(22., .7, .52) / scale(22., .7, .0), .72) + assert math.isclose(scale(21., .7, .34) / scale(21., .7, .0), .86) + for speed, request, error in ((22., .7, .1), (31., .7, .52), (22., 1.35, .52)): + assert scale(speed, request, error) == scale(speed, request, .0) + for pressed in ('steering_pressed', 'previous_pressed'): + setattr(policy, pressed, True) + assert scale(22., .7, .52) == scale(22., .7, .0) + setattr(policy, pressed, False) diff --git a/prebuilt.json b/prebuilt.json index f595c3591c..4987b87631 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "c31e42eb6e48a30c08fede78b96cdd034c00d804969b869ccc003e9e64b24c5d", "schema_version": 1} +{"protected_inventory_sha256": "646954a61ed9ea445d5a0a824bee535576151654486f0b988f788e42497d5a28", "schema_version": 1}