mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-29 00:03:57 +08:00
Smooth Palisade HDA II curve transitions
This commit is contained in:
@@ -70,9 +70,15 @@ class PalisadeTorquePolicy(HKGShapedTorquePolicy):
|
||||
|
||||
def output_context(self, value, setpoint, jerk, measurement, speed):
|
||||
output = self.output(value, setpoint, speed)
|
||||
if not self.hda2 or speed <= 24. or self.previous_pressed:
|
||||
if not self.hda2 or self.previous_pressed:
|
||||
return output
|
||||
highway = float(np.interp(speed, (24., 29.), (0., 1.)))
|
||||
transient = float(np.interp(abs(jerk), (.35, .9), (0., 1.)))
|
||||
small_curve = float(np.interp(abs(setpoint), (.18, .40, .55, .85), (0., 1., 1., 0.)))
|
||||
return output * (1.0 - .12 * highway * transient * small_curve)
|
||||
taper = .12 * highway * transient * small_curve
|
||||
if self.driver_steering:
|
||||
return output * (1.0 - taper)
|
||||
speed_weight = np.interp(speed, (10.5, 17.0), (0., 1.))
|
||||
curve_weight = np.interp(abs(setpoint), (.18, .45, 1.8, 2.5), (0., 1., 1., 0.))
|
||||
jerk_weight = np.interp(abs(jerk), (.20, .85), (0., 1.))
|
||||
return output * (1.0 - max(taper, .22 * speed_weight * curve_weight * jerk_weight))
|
||||
|
||||
@@ -107,10 +107,11 @@ def test_hda2_softens_rapid_highway_corrections_across_longitudinal_modes(alpha,
|
||||
policy = LatControlTorque(cp.as_reader(), interfaces[cp.carFingerprint](cp), .01).starpilot_extension.policy
|
||||
value, demand, jerk = direction * .4, direction * .45, direction * 1.1
|
||||
baseline = policy.output(value, demand, 31.)
|
||||
assert policy.output_context(value, demand, jerk, 0., 31.) == pytest.approx(.88 * baseline)
|
||||
assert policy.output_context(value, demand, jerk, 0., 31.) == pytest.approx(.78 * baseline)
|
||||
assert policy.output_context(value, demand, .2, 0., 31.) == baseline
|
||||
assert policy.output_context(value, direction, jerk, 0., 31.) == policy.output(value, direction, 31.)
|
||||
assert policy.output_context(value, demand, jerk, 0., 20.) == policy.output(value, demand, 20.)
|
||||
assert policy.output_context(value, direction, jerk, 0., 31.) == pytest.approx(.78 * policy.output(value, direction, 31.))
|
||||
assert policy.output_context(value, demand, jerk, 0., 20.) == pytest.approx(.78 * policy.output(value, demand, 20.))
|
||||
assert policy.output_context(value, demand, jerk, 0., 10.5) == policy.output(value, demand, 10.5)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('alpha', (False, True))
|
||||
@@ -214,3 +215,27 @@ def test_hda2_uses_stronger_friction_damping_in_both_longitudinal_modes(alpha):
|
||||
hda1 = topology_params('hdai')
|
||||
other = LatControlTorque(hda1.as_reader(), interfaces[hda1.carFingerprint](hda1), .01).starpilot_extension.policy
|
||||
assert other.friction_context(.3, .4, 0., 30.) == other.friction(.3, .4, 30.)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('alpha', (False, True))
|
||||
def test_hda2_curve_transition_taper_preserves_steady_turns_and_driver_response(alpha):
|
||||
cp = topology_params('hdaii')
|
||||
cp.openpilotLongitudinalControl, cp.pcmCruise = alpha, not alpha
|
||||
policy = LatControlTorque(cp.as_reader(), interfaces[cp.carFingerprint](cp), .01).starpilot_extension.policy
|
||||
|
||||
for side in (-1., 1.):
|
||||
steady = policy.output(.5, side * 1.2, 30.)
|
||||
for phase in (-1., 1.):
|
||||
transition = policy.output_context(.5, side * 1.2, side * phase * .85, 0., 30.)
|
||||
assert transition == pytest.approx(.78 * steady)
|
||||
for demand, jerk, speed in ((1.2, .20, 30.), (.18, .85, 30.), (2.5, .85, 30.), (1.2, .85, 10.5)):
|
||||
assert policy.output_context(.5, side * demand, side * jerk, 0., speed) == policy.output(.5, side * demand, speed)
|
||||
|
||||
for attr in ('driver_steering', 'previous_pressed'):
|
||||
setattr(policy, attr, True)
|
||||
assert policy.output_context(.5, 1.2, .85, 0., 30.) == policy.output(.5, 1.2, 30.)
|
||||
setattr(policy, attr, False)
|
||||
|
||||
hda1 = topology_params('hdai')
|
||||
other = LatControlTorque(hda1.as_reader(), interfaces[hda1.carFingerprint](hda1), .01).starpilot_extension.policy
|
||||
assert other.output_context(.5, 1.2, .85, 0., 30.) == other.output(.5, 1.2, 30.)
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "ecaab531736a0f9eb74ed0db0cd19e58e816550c08d97ccb0ddeaf37dc485cd2", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "22c7611c6c0aa3389556ee830e55577518977ad11002ecfc340f5dfa7b31c22e", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user