diff --git a/cereal/log.capnp b/cereal/log.capnp index d5fbad6fe..fb38185df 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 7c1b21c00..d86dd58c9 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 6ddebc9a0..6a2ad131e 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 1852dccf7..e093b5e0d 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 672d809dd..481a33079 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 8328bf67f..759682f44 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 eee48a6bd..1a362f62c 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 0351cd045..5dc5a5c49 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 bd1452612..482893fae 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 f015d2ea5..3129b79f0 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 658f131a3..dd58f9ddb 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 7e2f6649d..dac8c0373 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 0229a36bd..28a4db8a8 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 0b1c82e92..af62de8bd 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 2a2693961..004f03aff 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 c2557a6fa..1c28c0ebd 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 ac22574b9..81bc70e15 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 d284bbac6..81de7f76b 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 37c9d0c70..0f8a40ed2 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 000000000..5abb5603d --- /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 000000000..a92f8f60b --- /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)