Refine Palisade HDA2 camera timing and highway response

This commit is contained in:
firestar5683
2026-11-23 16:32:15 -06:00
parent d461cad223
commit 70de2df8f2
6 changed files with 37 additions and 8 deletions
@@ -358,7 +358,8 @@ class CarController(CarControllerBase):
fcw_opt_usm=2 if apply_steer_req or icon == 3 else 1))
if CS.out.canValid and not CS.out.canTimeout and CS.blended_camera_current:
camera_counter = CS.lfa_block_msg["COUNTER"]
if self.frame - self.blended_camera_sent_frame >= 5 and camera_counter != self.blended_camera_sent_counter:
if (self.frame - self.blended_camera_sent_frame >= 5 and camera_counter != self.blended_camera_sent_counter and
(not CC.latActive or CS.blended_camera_updated)):
can_sends.append(hyundaicanfd.create_suppress_lfa(self.packer, self.CAN, CS.lfa_block_msg, False))
self.blended_camera_sent_frame = self.frame
self.blended_camera_sent_counter = camera_counter
@@ -150,6 +150,7 @@ class CarState(CarStateBase):
self.params = CarControllerParams(CP)
self.blended_camera_current = False
self.blended_camera_updated = False
self.ray_pedal_valid = False
self.ray_pedal_state = 5
@@ -347,6 +348,7 @@ class CarState(CarStateBase):
self.lfa_block_msg = copy.copy(cp_cam.vl["CAM_0x2a4"])
from opendbc.car.hyundai.blended_stock_aol import camera_current
self.blended_camera_current = camera_current(cp_cam)
self.blended_camera_updated = bool(cp_cam.vl_all["CAM_0x2a4"]["COUNTER"])
self.lkas11 = {}
else:
self.msg_364 = copy.copy(cp_cam.vl["ALERTS_364"])
@@ -111,7 +111,7 @@ class TestPalisade2023(unittest.TestCase):
addresses = {a for a, _, _ in messages}
self.assertFalse(addresses & {0x420, 0x421, 0x389, 0x7D0, 0x730})
if topology == 'hdaii':
self.assertEqual(addresses, {0x50, 0x2A4} if tick in (0, 5, 10, 15) else {0x50})
self.assertEqual(addresses, {0x50, 0x2A4} if tick in (0, 7, 12, 17) else {0x50})
self.assertTrue(all(bus == 0 for _, _, bus in messages))
else:
self.assertEqual(addresses, {0x340, 0x364})
@@ -128,7 +128,7 @@ class TestPalisade2023(unittest.TestCase):
actuators, _ = ci.apply(command.as_reader(), 1_500_000_000)
self.assertEqual(actuators.torqueOutputCan, 0)
def test_hda2_camera_copy_follows_new_input_instead_of_free_running(self):
def test_hda2_camera_copy_skips_samples_that_miss_the_send_slot(self):
ci = CarInterface(params('hdaii'))
for tick in range(12):
feed(ci, tick)
@@ -136,10 +136,10 @@ class TestPalisade2023(unittest.TestCase):
copied = []
for frame in range(20):
tick = frame + 12
feed(ci, tick, camera={0: 12, 6: 13, 11: 14, 16: 15}.get(frame, False))
feed(ci, tick, camera={0: 12, 4: 13, 9: 14, 14: 15, 19: 16}.get(frame, False))
_, messages = ci.apply(command.as_reader(), 1_000_000_000 + tick * 10_000_000)
copied.extend((frame, data[2]) for address, data, _ in messages if address == 0x2A4)
self.assertEqual(copied, [(0, 12), (6, 13), (11, 14), (16, 15)])
self.assertEqual(copied, [(0, 12), (9, 14), (14, 15), (19, 16)])
def test_hda2_alpha_long_keeps_primary_steering_payload(self):
from opendbc.car.hyundai.blended_longitudinal import candidate_from_stock
+14 -2
View File
@@ -1,3 +1,5 @@
import numpy as np
from opendbc.car.hyundai.values import CAR, HyundaiFlags
from openpilot.starpilot.lateral import palisade_shaping as shaping
from openpilot.starpilot.lateral.hkg_torque_policy import HKGShapedTorquePolicy, supported_torque_cp
@@ -16,8 +18,8 @@ class PalisadeTorquePolicy(HKGShapedTorquePolicy):
def __init__(self, parent, cp):
super().__init__(parent, cp)
hda2 = cp.carFingerprint == CAR.HYUNDAI_PALISADE_2023 and cp.flags & HyundaiFlags.CANFD_LKA_STEER_MSG
self.center_output_taper = 0.27 if hda2 else shaping.PALISADE_CENTER_OUTPUT_TAPER_MAX
self.hda2 = cp.carFingerprint == CAR.HYUNDAI_PALISADE_2023 and bool(cp.flags & HyundaiFlags.CANFD_LKA_STEER_MSG)
self.center_output_taper = 0.27 if self.hda2 else shaping.PALISADE_CENTER_OUTPUT_TAPER_MAX
def feedforward(self, value, setpoint, jerk, speed):
return value * shaping.get_palisade_ff_scale(setpoint, jerk, speed) * shaping.get_palisade_center_taper_scale(setpoint, speed)
@@ -29,3 +31,13 @@ class PalisadeTorquePolicy(HKGShapedTorquePolicy):
def output(self, value, setpoint, speed):
return value * shaping.get_palisade_center_output_scale(setpoint, speed, taper_max=self.center_output_taper)
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:
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)
@@ -97,3 +97,17 @@ def test_only_palisade_hda2_softens_highway_center_corrections():
assert hda2.output(.5, .1, 30.) < .91 * hda1.output(.5, .1, 30.)
assert hda2.output(.5, .8, 30.) == pytest.approx(hda1.output(.5, .8, 30.), abs=4e-6)
assert hda2.output(.5, .1, 4.) == pytest.approx(hda1.output(.5, .1, 4.), abs=.002)
@pytest.mark.parametrize('alpha', (False, True))
@pytest.mark.parametrize('direction', (-1., 1.))
def test_hda2_softens_rapid_highway_corrections_across_longitudinal_modes(alpha, direction):
cp = topology_params('hdaii')
cp.openpilotLongitudinalControl, cp.pcmCruise = alpha, not 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, .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.)
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "1c0e5979b7f1949b9844ebcfec50b6c019b29be32450eec134d6bb6225bb4432", "schema_version": 1}
{"protected_inventory_sha256": "4d6fbc17e4d1e71b4757c4d936d49876a67e148aa87a365299e026a5848fd9cd", "schema_version": 1}