From 01c5dbdc4cc9cda824db217c91977b5c862e675d Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Mon, 13 Jan 2025 16:14:00 -0500 Subject: [PATCH] Hyundai CAN: auto-enable radar tracks on applicable Mando radar (#561) * more * event and checks * comments * missed events * retry 2 times is enough * rename to radar tracks * fix data type * more rename * bump opendbc * drain first * put it behind a toggle lol * re-enable * update comments * revert lead smoothing * Revert "revert lead smoothing" This reverts commit 872267970c3dd1dbfd64a5bdd21d2e1b9ea600bf. * real events and radard engagement * only show up for hyundai with mando * update translations * bump opendbc * fix event name * update description * move above * translations --------- Co-authored-by: rav4kumar --- cereal/log.capnp | 1 + common/params.cc | 6 ++++ opendbc_repo | 2 +- selfdrive/car/card.py | 3 ++ selfdrive/selfdrived/events.py | 3 ++ selfdrive/selfdrived/selfdrived.py | 7 ++++ selfdrive/ui/qt/offroad/developer_panel.cc | 18 ++++++++++ selfdrive/ui/qt/offroad/developer_panel.h | 1 + selfdrive/ui/translations/main_ar.ts | 8 +++++ selfdrive/ui/translations/main_de.ts | 8 +++++ selfdrive/ui/translations/main_es.ts | 8 +++++ selfdrive/ui/translations/main_fr.ts | 8 +++++ selfdrive/ui/translations/main_ja.ts | 8 +++++ selfdrive/ui/translations/main_ko.ts | 8 +++++ selfdrive/ui/translations/main_pt-BR.ts | 8 +++++ selfdrive/ui/translations/main_th.ts | 8 +++++ selfdrive/ui/translations/main_tr.ts | 8 +++++ selfdrive/ui/translations/main_zh-CHS.ts | 8 +++++ selfdrive/ui/translations/main_zh-CHT.ts | 8 +++++ sunnypilot/selfdrive/car/car_specific.py | 34 ++++++++++++++++++ sunnypilot/selfdrive/car/interfaces.py | 41 ++++++++++++++++++++++ 21 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 sunnypilot/selfdrive/car/car_specific.py create mode 100644 sunnypilot/selfdrive/car/interfaces.py diff --git a/cereal/log.capnp b/cereal/log.capnp index d5fbad6fe8..fb38185dfe 100644 --- a/cereal/log.capnp +++ b/cereal/log.capnp @@ -198,6 +198,7 @@ struct OnroadEvent @0xc4fa6047f024e718 { silentSeatbeltNotLatched @161; silentParkBrake @162; controlsMismatchLateral @163; + hyundaiRadarTracksConfirmed @164; soundsUnavailableDEPRECATED @47; } diff --git a/common/params.cc b/common/params.cc index 7c1b21c00c..d86dd58c9f 100644 --- a/common/params.cc +++ b/common/params.cc @@ -223,6 +223,12 @@ std::unordered_map keys = { {"SunnylinkDongleId", PERSISTENT}, {"SunnylinkdPid", PERSISTENT}, {"SunnylinkEnabled", PERSISTENT}, + + // sunnypilot car specific params + {"HyundaiRadarTracks", PERSISTENT}, + {"HyundaiRadarTracksConfirmed", PERSISTENT}, + {"HyundaiRadarTracksPersistent", PERSISTENT}, + {"HyundaiRadarTracksToggle", PERSISTENT}, }; } // namespace diff --git a/opendbc_repo b/opendbc_repo index 6ddebc9a03..6a2ad131eb 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit 6ddebc9a0365d3421bee7cceddb0263c88fb78dd +Subproject commit 6a2ad131ebfe7a15dca5aae391ef5225189c3c2d diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index 1852dccf74..e093b5e0d0 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -23,6 +23,7 @@ from openpilot.selfdrive.car.cruise import VCruiseHelper from openpilot.selfdrive.car.car_specific import MockCarState from openpilot.sunnypilot.mads.mads import MadsParams +from openpilot.sunnypilot.selfdrive.car.interfaces import setup_car_interface_sp, initialize_car_interface_sp REPLAY = "REPLAY" in os.environ @@ -100,6 +101,7 @@ class Car: cached_params = _cached_params self.CI = get_car(*self.can_callbacks, obd_callback(self.params), experimental_long_allowed, num_pandas, cached_params) + setup_car_interface_sp(self.CI.CP, self.params) self.RI = get_radar_interface(self.CI.CP) self.CP = self.CI.CP @@ -230,6 +232,7 @@ class Car: # Initialize CarInterface, once controls are ready # TODO: this can make us miss at least a few cycles when doing an ECU knockout self.CI.init(self.CP, *self.can_callbacks) + initialize_car_interface_sp(self.CP, self.params, *self.can_callbacks) # signal pandad to switch to car safety mode self.params.put_bool_nonblocking("ControlsReady", True) diff --git a/selfdrive/selfdrived/events.py b/selfdrive/selfdrived/events.py index 672d809dd9..481a33079b 100755 --- a/selfdrive/selfdrived/events.py +++ b/selfdrive/selfdrived/events.py @@ -1061,6 +1061,9 @@ EVENTS: dict[int, dict[str, Alert | AlertCallbackType]] = { ET.NO_ENTRY: NoEntryAlert("Controls Mismatch: Lateral"), }, + EventName.hyundaiRadarTracksConfirmed: { + ET.PERMANENT: NormalPermanentAlert("Radar tracks available. Restart the car to initialize") + } } diff --git a/selfdrive/selfdrived/selfdrived.py b/selfdrive/selfdrived/selfdrived.py index 8328bf67f0..759682f44f 100755 --- a/selfdrive/selfdrived/selfdrived.py +++ b/selfdrive/selfdrived/selfdrived.py @@ -24,6 +24,7 @@ from openpilot.selfdrive.controls.lib.latcontrol import MIN_LATERAL_CONTROL_SPEE from openpilot.system.version import get_build_metadata from openpilot.sunnypilot.mads.mads import ModularAssistiveDrivingSystem +from openpilot.sunnypilot.selfdrive.car.car_specific import CarSpecificEventsSP REPLAY = "REPLAY" in os.environ SIMULATION = "SIMULATION" in os.environ @@ -137,6 +138,8 @@ class SelfdriveD: sock_services = list(self.pm.sock.keys()) + ['selfdriveStateSP'] self.pm = messaging.PubMaster(sock_services) + self.car_events_sp = CarSpecificEventsSP(self.CP, self.params) + def update_events(self, CS): """Compute onroadEvents from carState""" @@ -177,6 +180,9 @@ class SelfdriveD: car_events = self.car_events.update(CS, self.CS_prev, self.sm['carControl']).to_msg() self.events.add_from_msg(car_events) + car_events_sp = self.car_events_sp.update().to_msg() + self.events.add_from_msg(car_events_sp) + if self.CP.notCar: # wait for everything to init first if self.sm.frame > int(5. / DT_CTRL) and self.initialized: @@ -495,6 +501,7 @@ class SelfdriveD: self.personality = self.read_personality_param() self.mads.read_params() + self.car_events_sp.read_params() time.sleep(0.1) def run(self): diff --git a/selfdrive/ui/qt/offroad/developer_panel.cc b/selfdrive/ui/qt/offroad/developer_panel.cc index eee48a6bdb..1a362f62c6 100644 --- a/selfdrive/ui/qt/offroad/developer_panel.cc +++ b/selfdrive/ui/qt/offroad/developer_panel.cc @@ -29,6 +29,18 @@ DeveloperPanel::DeveloperPanel(SettingsWindow *parent) : ListWidget(parent) { }); addItem(longManeuverToggle); + // TODO-SP: Move to Vehicles panel when ported back + hyundaiRadarTracksToggle = new ParamControl( + "HyundaiRadarTracksToggle", + tr("Hyundai: Enable Radar Tracks"), + tr("Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. " + "This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance."), ""); + hyundaiRadarTracksToggle->setConfirmation(true, false); + QObject::connect(hyundaiRadarTracksToggle, &ParamControl::toggleFlipped, [=](bool state) { + updateToggles(offroad); + }); + addItem(hyundaiRadarTracksToggle); + auto enableGithubRunner = new ParamControl("EnableGithubRunner", tr("Enable GitHub runner service"), tr("Enables or disables the github runner service."), ""); addItem(enableGithubRunner); @@ -51,9 +63,15 @@ void DeveloperPanel::updateToggles(bool _offroad) { AlignedBuffer aligned_buf; capnp::FlatArrayMessageReader cmsg(aligned_buf.align(cp_bytes.data(), cp_bytes.size())); cereal::CarParams::Reader CP = cmsg.getRoot(); + + auto hyundai = CP.getCarName() == "hyundai"; + auto hyundai_mando_radar = hyundai && (CP.getFlags() & 4096); + longManeuverToggle->setEnabled(hasLongitudinalControl(CP) && _offroad); + hyundaiRadarTracksToggle->setVisible(hyundai_mando_radar && hasLongitudinalControl(CP)); } else { longManeuverToggle->setEnabled(false); + hyundaiRadarTracksToggle->setVisible(false); } offroad = _offroad; diff --git a/selfdrive/ui/qt/offroad/developer_panel.h b/selfdrive/ui/qt/offroad/developer_panel.h index 0351cd045c..5dc5a5c494 100644 --- a/selfdrive/ui/qt/offroad/developer_panel.h +++ b/selfdrive/ui/qt/offroad/developer_panel.h @@ -16,6 +16,7 @@ private: Params params; ParamControl* joystickToggle; ParamControl* longManeuverToggle; + ParamControl* hyundaiRadarTracksToggle; bool is_release; bool offroad; diff --git a/selfdrive/ui/translations/main_ar.ts b/selfdrive/ui/translations/main_ar.ts index bd1452612c..482893fae5 100644 --- a/selfdrive/ui/translations/main_ar.ts +++ b/selfdrive/ui/translations/main_ar.ts @@ -131,6 +131,14 @@ Enable GitHub runner service + + Hyundai: Enable Radar Tracks + + + + Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance. + + DevicePanel diff --git a/selfdrive/ui/translations/main_de.ts b/selfdrive/ui/translations/main_de.ts index f015d2ea5f..3129b79f0d 100644 --- a/selfdrive/ui/translations/main_de.ts +++ b/selfdrive/ui/translations/main_de.ts @@ -131,6 +131,14 @@ Enable GitHub runner service + + Hyundai: Enable Radar Tracks + + + + Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance. + + DevicePanel diff --git a/selfdrive/ui/translations/main_es.ts b/selfdrive/ui/translations/main_es.ts index 658f131a36..dd58f9ddb5 100644 --- a/selfdrive/ui/translations/main_es.ts +++ b/selfdrive/ui/translations/main_es.ts @@ -131,6 +131,14 @@ Enable GitHub runner service + + Hyundai: Enable Radar Tracks + + + + Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance. + + DevicePanel diff --git a/selfdrive/ui/translations/main_fr.ts b/selfdrive/ui/translations/main_fr.ts index 7e2f6649d6..dac8c0373b 100644 --- a/selfdrive/ui/translations/main_fr.ts +++ b/selfdrive/ui/translations/main_fr.ts @@ -131,6 +131,14 @@ Enable GitHub runner service + + Hyundai: Enable Radar Tracks + + + + Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance. + + DevicePanel diff --git a/selfdrive/ui/translations/main_ja.ts b/selfdrive/ui/translations/main_ja.ts index 0229a36bd6..28a4db8a8f 100644 --- a/selfdrive/ui/translations/main_ja.ts +++ b/selfdrive/ui/translations/main_ja.ts @@ -131,6 +131,14 @@ Enable GitHub runner service + + Hyundai: Enable Radar Tracks + + + + Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance. + + DevicePanel diff --git a/selfdrive/ui/translations/main_ko.ts b/selfdrive/ui/translations/main_ko.ts index 0b1c82e92c..af62de8bd5 100644 --- a/selfdrive/ui/translations/main_ko.ts +++ b/selfdrive/ui/translations/main_ko.ts @@ -131,6 +131,14 @@ Enable GitHub runner service + + Hyundai: Enable Radar Tracks + + + + Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance. + + DevicePanel diff --git a/selfdrive/ui/translations/main_pt-BR.ts b/selfdrive/ui/translations/main_pt-BR.ts index 2a2693961e..004f03affe 100644 --- a/selfdrive/ui/translations/main_pt-BR.ts +++ b/selfdrive/ui/translations/main_pt-BR.ts @@ -131,6 +131,14 @@ Enable GitHub runner service + + Hyundai: Enable Radar Tracks + + + + Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance. + + DevicePanel diff --git a/selfdrive/ui/translations/main_th.ts b/selfdrive/ui/translations/main_th.ts index c2557a6faa..1c28c0ebd1 100644 --- a/selfdrive/ui/translations/main_th.ts +++ b/selfdrive/ui/translations/main_th.ts @@ -131,6 +131,14 @@ Enable GitHub runner service + + Hyundai: Enable Radar Tracks + + + + Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance. + + DevicePanel diff --git a/selfdrive/ui/translations/main_tr.ts b/selfdrive/ui/translations/main_tr.ts index ac22574b97..81bc70e154 100644 --- a/selfdrive/ui/translations/main_tr.ts +++ b/selfdrive/ui/translations/main_tr.ts @@ -131,6 +131,14 @@ Enable GitHub runner service + + Hyundai: Enable Radar Tracks + + + + Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance. + + DevicePanel diff --git a/selfdrive/ui/translations/main_zh-CHS.ts b/selfdrive/ui/translations/main_zh-CHS.ts index d284bbac6e..81de7f76b8 100644 --- a/selfdrive/ui/translations/main_zh-CHS.ts +++ b/selfdrive/ui/translations/main_zh-CHS.ts @@ -131,6 +131,14 @@ Enable GitHub runner service + + Hyundai: Enable Radar Tracks + + + + Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance. + + DevicePanel diff --git a/selfdrive/ui/translations/main_zh-CHT.ts b/selfdrive/ui/translations/main_zh-CHT.ts index 37c9d0c70f..0f8a40ed29 100644 --- a/selfdrive/ui/translations/main_zh-CHT.ts +++ b/selfdrive/ui/translations/main_zh-CHT.ts @@ -131,6 +131,14 @@ Enable GitHub runner service + + Hyundai: Enable Radar Tracks + + + + Enable this to attempt to enable radar tracks for Hyundai, Kia, and Genesis models equipped with the supported Mando SCC radar. This allows sunnypilot to use radar data for improved lead tracking and overall longitudinal performance. + + DevicePanel diff --git a/sunnypilot/selfdrive/car/car_specific.py b/sunnypilot/selfdrive/car/car_specific.py new file mode 100644 index 0000000000..5abb5603d6 --- /dev/null +++ b/sunnypilot/selfdrive/car/car_specific.py @@ -0,0 +1,34 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" + +from cereal import log +from opendbc.car import structs + +from openpilot.selfdrive.selfdrived.events import Events + +EventName = log.OnroadEvent.EventName + + +class CarSpecificEventsSP: + def __init__(self, CP: structs.CarParams, params): + self.CP = CP + self.params = params + + self.hyundai_radar_tracks = self.params.get_bool("HyundaiRadarTracks") + self.hyundai_radar_tracks_confirmed = self.params.get_bool("HyundaiRadarTracksConfirmed") + + def read_params(self): + self.hyundai_radar_tracks = self.params.get_bool("HyundaiRadarTracks") + self.hyundai_radar_tracks_confirmed = self.params.get_bool("HyundaiRadarTracksConfirmed") + + def update(self): + events = Events() + if self.CP.carName == 'hyundai': + if self.hyundai_radar_tracks and not self.hyundai_radar_tracks_confirmed: + events.add(EventName.hyundaiRadarTracksConfirmed) + + return events diff --git a/sunnypilot/selfdrive/car/interfaces.py b/sunnypilot/selfdrive/car/interfaces.py new file mode 100644 index 0000000000..a92f8f60be --- /dev/null +++ b/sunnypilot/selfdrive/car/interfaces.py @@ -0,0 +1,41 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +This file is part of sunnypilot and is licensed under the MIT License. +See the LICENSE.md file in the root directory for more details. +""" + +from opendbc.car import Bus, structs +from opendbc.car.can_definitions import CanRecvCallable, CanSendCallable +from opendbc.car.car_helpers import can_fingerprint +from opendbc.car.hyundai.radar_interface import RADAR_START_ADDR +from opendbc.car.hyundai.values import HyundaiFlags, DBC as HYUNDAI_DBC +from opendbc.sunnypilot.car.hyundai.values import HyundaiFlagsSP + + +def setup_car_interface_sp(CP: structs.CarParams, params): + if CP.carName == 'hyundai': + if CP.flags & HyundaiFlags.MANDO_RADAR and CP.radarUnavailable: + # Having this automatic without a toggle causes a weird process replay diff because + # somehow it sees fewer logs than intended + if params.get_bool("HyundaiRadarTracksToggle"): + CP.sunnypilotFlags |= HyundaiFlagsSP.ENABLE_RADAR_TRACKS.value + if params.get_bool("HyundaiRadarTracks"): + CP.radarUnavailable = False + + +def initialize_car_interface_sp(CP: structs.CarParams, params, can_recv: CanRecvCallable, can_send: CanSendCallable): + if CP.carName == 'hyundai': + if CP.sunnypilotFlags & HyundaiFlagsSP.ENABLE_RADAR_TRACKS: + can_recv() + _, fingerprint = can_fingerprint(can_recv) + radar_unavailable = RADAR_START_ADDR not in fingerprint[1] or Bus.radar not in HYUNDAI_DBC[CP.carFingerprint] + + radar_tracks = params.get_bool("HyundaiRadarTracks") + radar_tracks_persistent = params.get_bool("HyundaiRadarTracksPersistent") + + params.put_bool_nonblocking("HyundaiRadarTracksConfirmed", radar_tracks) + + if not radar_tracks_persistent: + params.put_bool_nonblocking("HyundaiRadarTracks", not radar_unavailable) + params.put_bool_nonblocking("HyundaiRadarTracksPersistent", True)