mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-30 00:33:41 +08:00
Restore Kona stopping ramp and synchronize the cruise display
This commit is contained in:
@@ -627,12 +627,13 @@ class CarController(CarControllerBase):
|
||||
now_nanos - min(CS.ccnc_161_ts_ns, CS.ccnc_162_ts_ns) <= 50_000_000 and
|
||||
abs(CS.ccnc_161_ts_ns - CS.ccnc_162_ts_ns) <= 50_000_000)
|
||||
if fresh_pair:
|
||||
show_cruise = CS.out.cruiseState.available and (not kona_handoff or CC.enabled)
|
||||
support_current = (CS.ccnc_1b5_ts_ns > 0 and CS.ccnc_1b5_ts_ns <= now_nanos and
|
||||
abs(CS.ccnc_1b5_ts_ns - pair_ts) <= 50_000_000)
|
||||
can_sends.extend(hyundaicanfd.create_ccnc(self.packer, self.CAN, self.CP.openpilotLongitudinalControl,
|
||||
CC.enabled, hud_control, CC.leftBlinker, CC.rightBlinker,
|
||||
CS.ccnc_161.copy(), CS.ccnc_162.copy(), CS.ccnc_1b5 if support_current else None,
|
||||
CS.is_metric, CS.out, CS.out.cruiseState.available, CC.latActive,
|
||||
CS.is_metric, CS.out, show_cruise, CC.latActive,
|
||||
owned_lfa_status=(stock_ccnc_owned if self.ccnc_fault_ownership_required else None)))
|
||||
self.last_ccnc_161_ts_ns = CS.ccnc_161_ts_ns
|
||||
self.last_ccnc_162_ts_ns = CS.ccnc_162_ts_ns
|
||||
|
||||
@@ -236,3 +236,30 @@ def test_kona_factory_handoff_is_limited_to_healthy_internal_c4(panda_type, faul
|
||||
panda = SimpleNamespace(pandaType=panda_type, faults=faults, ignitionLine=True, ignitionCan=False, controlsAllowed=False)
|
||||
configure_kona_factory_handoff(cp, [panda])
|
||||
assert cp.safetyConfigs[0].safetyParam == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('handoff,enabled,hud_mode', ((True, False, 0), (True, True, 2), (False, False, 1)))
|
||||
def test_kona_handoff_cruise_main_display_follows_star_long_engagement(handoff, enabled, hud_mode):
|
||||
from opendbc.can import CANParser
|
||||
cp = kona_params(CARS[0])
|
||||
cp.safetyConfigs[0].safetyParam = 0x1C0C if handoff else 0x0C0C
|
||||
cp.alternativeExperience = 32
|
||||
ci = CarInterface(cp)
|
||||
ci.CS.out = structs.CarState(cruiseState={'available': True}, vCruiseCluster=40.).as_reader()
|
||||
for frame in range(5):
|
||||
ci.apply(structs.CarControl().as_reader(), 950_000_000 + frame * 10_000_000)
|
||||
ci.CS.ccnc_161_ts_ns = ci.CS.ccnc_162_ts_ns = 1_000_000_000
|
||||
ci.CS.ccnc_161 = {'SETSPEED_HUD': 3, 'SETSPEED_SPEED': 20, 'DISTANCE_SPACING': 1}
|
||||
ci.CS.ccnc_162 = {'FAULT_LSS': 2, 'FAULT_FCA': 1}
|
||||
command = structs.CarControl(enabled=enabled, latActive=True, longActive=enabled)
|
||||
_, packets = ci.apply(command.as_reader(), 1_000_000_000)
|
||||
parser = CANParser('hyundai_canfd_generated', [('CCNC_0x161', 0), ('CCNC_0x162', 0)], 0)
|
||||
assert {0x161, 0x162} <= parser.update((1_000_000_000, packets))
|
||||
display = parser.vl['CCNC_0x161']
|
||||
assert display['SETSPEED_HUD'] == hud_mode
|
||||
assert display['LFA_ICON'] == 2
|
||||
if hud_mode == 0:
|
||||
assert display['SETSPEED_SPEED'] == 255
|
||||
assert display['DISTANCE_SPACING'] == 0
|
||||
assert parser.vl['CCNC_0x162']['FAULT_LSS'] == 2
|
||||
assert parser.vl['CCNC_0x162']['FAULT_FCA'] == 1
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import unittest
|
||||
|
||||
from opendbc.car import gen_empty_fingerprint, structs
|
||||
from opendbc.car.hyundai.interface import CarInterface
|
||||
from opendbc.car.hyundai.values import CAR
|
||||
from openpilot.selfdrive.controls.lib.longcontrol import LongControl
|
||||
|
||||
|
||||
def kona_params(candidate, alpha, alternate=False, marked=False):
|
||||
fp = gen_empty_fingerprint()
|
||||
fp[0].update({0x1AA if alternate else 0x1CF: 16 if alternate else 8,
|
||||
0xFA if candidate == CAR.HYUNDAI_KONA_HEV_2ND_GEN else 0x100: 32,
|
||||
0x175: 24, 0xA0: 24, 0xEA: 24, 0x125: 16})
|
||||
fp[2].update({0x12A: 16, 0x1A0: 32, 0x161: 16, 0x162: 32})
|
||||
cp = CarInterface.get_params(candidate, fp, [], alpha, False, False)
|
||||
if marked:
|
||||
cp.safetyConfigs[0].safetyParam |= 0x800
|
||||
cp.alternativeExperience = 32
|
||||
return cp
|
||||
|
||||
|
||||
class TestKonaStopRate(unittest.TestCase):
|
||||
def test_qualified_gas_kona_restores_stable_stop_rate(self):
|
||||
for alternate in (False, True):
|
||||
for marked in (False, True):
|
||||
with self.subTest(alternate=alternate, marked=marked):
|
||||
cp = kona_params(CAR.HYUNDAI_KONA_2ND_GEN, True, alternate, marked)
|
||||
original = cp.to_dict()
|
||||
controller = LongControl(cp)
|
||||
state = structs.CarState(vEgo=1.3).as_reader()
|
||||
for frame in range(30):
|
||||
output = controller.update(True, state, -0.5, True, (-3.5, 2.0))
|
||||
self.assertAlmostEqual(output, -0.008 * (frame + 1))
|
||||
self.assertEqual(controller.update(False, state, -0.5, True, (-3.5, 2.0)), 0.)
|
||||
self.assertEqual(original, cp.to_dict())
|
||||
|
||||
def test_kona_camera_handoff_keeps_stable_stop_rate_and_factory_hold(self):
|
||||
cp = kona_params(CAR.HYUNDAI_KONA_2ND_GEN, True, marked=True)
|
||||
cp.safetyConfigs[0].safetyParam = 0x1C0C
|
||||
controller = LongControl(cp)
|
||||
self.assertEqual(controller.stopping_decel_rate, 0.8)
|
||||
state = structs.CarState(vEgo=0.3).as_reader()
|
||||
for _ in range(380):
|
||||
output = controller.update(True, state, -0.5, True, (-3.5, 2.0))
|
||||
self.assertAlmostEqual(output, cp.stopAccel, delta=0.008)
|
||||
self.assertEqual(controller.update(False, state, -0.5, True, (-3.5, 2.0)), 0.)
|
||||
|
||||
def test_stock_hybrid_and_unqualified_profiles_keep_default_rate(self):
|
||||
stock = kona_params(CAR.HYUNDAI_KONA_2ND_GEN, False)
|
||||
hybrid = kona_params(CAR.HYUNDAI_KONA_HEV_2ND_GEN, True)
|
||||
unqualified = kona_params(CAR.HYUNDAI_KONA_2ND_GEN, True)
|
||||
unqualified.safetyConfigs[0].safetyParam ^= 0x100
|
||||
for cp in (stock, hybrid, unqualified):
|
||||
self.assertEqual(LongControl(cp).stopping_decel_rate, 1.)
|
||||
@@ -27,6 +27,11 @@ def policy_for(cp, startup_preferences=None):
|
||||
|
||||
|
||||
def stopping_decel_rate(cp, policy):
|
||||
from opendbc.car.hyundai.values import CAR as HYUNDAI
|
||||
if cp.carFingerprint == HYUNDAI.HYUNDAI_KONA_2ND_GEN:
|
||||
from opendbc.car.hyundai.canfd_stock_aol import qualified_long
|
||||
if qualified_long(cp):
|
||||
return 0.8
|
||||
from opendbc.car.hyundai.legacy_long_aol import stopping_decel_rate as legacy_stop_rate
|
||||
rate = legacy_stop_rate(cp)
|
||||
if rate is not None:
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "c305449b5668a10ceaac348e5d80ff657f5ab4daa9567e57b7bfaaeb88f0704a", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "9753d4174e5a29790514d52a39292d5ce3b8ed45f6ae7a36f4431c9684dd2129", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user