mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 07:23:41 +08:00
Soften ordinary cruise acceleration after speed increases
This commit is contained in:
@@ -47,6 +47,7 @@ A_CRUISE_MAX_VALS = [1.6, 1.2, 0.8, 0.6]
|
||||
A_CRUISE_MAX_BP = [0., 10.0, 25., 40.]
|
||||
J_CRUISE_VALS = [1.6, 1.2, 0.8, 0.6]
|
||||
A_CRUISE_MIN = -0.5
|
||||
CRUISE_ACCEL_RESPONSE_TIME = 2.0
|
||||
CONTROL_N_T_IDX = ModelConstants.T_IDXS[:CONTROL_N]
|
||||
MIN_ALLOW_THROTTLE_SPEED = 2.5
|
||||
NATIVE_ALLOW_THROTTLE_PROBABILITY = 0.4
|
||||
@@ -90,7 +91,10 @@ def get_cruise_accel(e2e, v_cruise, v_ego, a_cruise_prev, angle_steers, CP, dt,
|
||||
max_accel = min(max_accel, coast_limit)
|
||||
|
||||
cruise_min = max(ACCEL_MIN, -profile.cruise_brake_magnitude) if profile is not None else max(ACCEL_MIN, base_brake_floor)
|
||||
target_accel = np.clip(v_cruise - v_ego, cruise_min, max_accel)
|
||||
speed_error = v_cruise - v_ego
|
||||
if not e2e and not faster_takeoffs and v_ego >= MIN_ALLOW_THROTTLE_SPEED and speed_error > 0.:
|
||||
speed_error /= CRUISE_ACCEL_RESPONSE_TIME
|
||||
target_accel = np.clip(speed_error, cruise_min, max_accel)
|
||||
j_cruise = np.interp(v_ego, A_CRUISE_MAX_BP, J_CRUISE_VALS)
|
||||
decel_start = a_cruise_prev if a_target_prev is None else min(a_cruise_prev, a_target_prev)
|
||||
target_accel = float(np.clip(target_accel, decel_start - j_cruise * dt, a_cruise_prev + j_cruise * dt))
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
"""Small cruise increases retain the earlier gradual acceleration response."""
|
||||
import pytest
|
||||
|
||||
from opendbc.car.toyota.interface import CarInterface
|
||||
from opendbc.car.toyota.values import CAR
|
||||
from openpilot.common.constants import CV
|
||||
from openpilot.selfdrive.controls.lib.longitudinal_planner import get_cruise_accel
|
||||
|
||||
|
||||
def camry():
|
||||
return CarInterface.get_params(CAR.TOYOTA_CAMRY, {0: {0x2FF: 4}, 1: {}, 2: {}}, [], True, False, False)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('speed', (10., 25., 28., 35.))
|
||||
@pytest.mark.parametrize('step', (CV.KPH_TO_MS, CV.MPH_TO_MS))
|
||||
def test_ordinary_cruise_taps_use_gradual_response(speed, step):
|
||||
cp = camry()
|
||||
ego, previous = speed, 0.
|
||||
acceleration = []
|
||||
for _ in range(40):
|
||||
target = get_cruise_accel(False, speed + step, ego, previous, 0., cp, .05, 0., True)
|
||||
assert target >= 0.
|
||||
acceleration.append(target)
|
||||
ego += target * .05
|
||||
previous = target
|
||||
# Pre-rebase native MPC peaks were .110-.118 for 1 kph and .175-.189 for 1 mph.
|
||||
assert max(acceleration) <= (.15 if step == CV.KPH_TO_MS else .23), 'CRUISE_TAP_ACCELERATION_REGRESSION'
|
||||
assert ego > speed and ego <= speed + step
|
||||
|
||||
|
||||
@pytest.mark.parametrize('error,expected', ((-.2, -.2), (-1., -.5), (-5., -.5)))
|
||||
def test_cruise_braking_is_unchanged(error, expected):
|
||||
assert get_cruise_accel(False, 28. + error, 28., expected, 0., camry(), .05, 0., True) == pytest.approx(expected)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('experimental,faster', ((True, False), (False, True)))
|
||||
def test_experimental_and_requested_faster_takeoffs_keep_existing_response(experimental, faster):
|
||||
assert get_cruise_accel(experimental, 28.4, 28., .4, 0., camry(), .05, 0., True,
|
||||
faster_takeoffs=faster) == pytest.approx(.4)
|
||||
|
||||
|
||||
def test_large_cruise_error_still_reaches_existing_acceleration_cap():
|
||||
assert get_cruise_accel(False, 40., 25., .8, 0., camry(), .05, 0., True) == .8
|
||||
|
||||
|
||||
def test_small_cruise_step_still_respects_a_lower_selected_cap():
|
||||
assert get_cruise_accel(False, 28.4, 28., .1, 0., camry(), .05, 0., True,
|
||||
selected_acceleration_max=.1) == .1
|
||||
|
||||
|
||||
def test_low_speed_launch_and_resume_keep_existing_response():
|
||||
assert get_cruise_accel(False, .5, .1, .4, 0., camry(), .05, 0., True) == .4
|
||||
|
||||
|
||||
def test_repeated_imperial_cruise_taps_do_not_build_a_sharp_acceleration_peak():
|
||||
cp = camry()
|
||||
speed, previous = 28., 0.
|
||||
acceleration = []
|
||||
for frame in range(160):
|
||||
selected = 28. + (frame // 40 + 1) * CV.MPH_TO_MS
|
||||
previous = get_cruise_accel(False, selected, speed, previous, 0., cp, .05, 0., True)
|
||||
acceleration.append(previous)
|
||||
speed += previous * .05
|
||||
assert max(acceleration) <= .36
|
||||
assert speed > 28. + 3 * CV.MPH_TO_MS
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "a5a262d143e3abd9b4e120e7eea59fb89f1f3c1f2633cfdf34dfbd9af637f92e", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "a094f0789c8f89ab11438b2e08feb70ae8a417b90cbc3f0c9f581310bd3c0013", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user