From e16d422cf4499c57efdb546eeda33dbd3d60304f Mon Sep 17 00:00:00 2001 From: stef <19478336+stefpi@users.noreply.github.com> Date: Tue, 14 Apr 2026 19:13:57 -0700 Subject: [PATCH] body quality of life (#37803) * turn off ir leds on notCar * reduce startup time on notCar * fix: check notCar once after onroad is true * save a disk read by using existing is_onroad --- selfdrive/pandad/pandad.cc | 25 +++++++++++++++++++++---- selfdrive/selfdrived/selfdrived.py | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/selfdrive/pandad/pandad.cc b/selfdrive/pandad/pandad.cc index 28d459f458..f0f13d32e7 100644 --- a/selfdrive/pandad/pandad.cc +++ b/selfdrive/pandad/pandad.cc @@ -285,7 +285,7 @@ void process_panda_state(Panda *panda, PubMaster *pm, bool engaged, bool is_onro panda->send_heartbeat(engaged); } -void process_peripheral_state(Panda *panda, PubMaster *pm, bool no_fan_control) { +void process_peripheral_state(Panda *panda, PubMaster *pm, bool no_fan_control, bool is_onroad) { static Params params; static SubMaster sm({"deviceState", "driverCameraState"}); @@ -295,6 +295,8 @@ void process_peripheral_state(Panda *panda, PubMaster *pm, bool no_fan_control) static int prev_ir_pwr = 999; static uint32_t prev_frame_id = UINT32_MAX; static bool driver_view = false; + static bool not_car = false; + static bool not_car_checked = false; // TODO: can we merge these? static FirstOrderFilter integ_lines_filter(0, 30.0, 0.05); @@ -340,10 +342,25 @@ void process_peripheral_state(Panda *panda, PubMaster *pm, bool no_fan_control) ir_pwr = 0; } + // turn off IR leds if body + if (!not_car_checked && is_onroad) { + std::string cp_bytes = params.get("CarParams"); + if (cp_bytes.size() > 0) { + AlignedBuffer aligned_buf; + capnp::FlatArrayMessageReader cmsg(aligned_buf.align(cp_bytes.data(), cp_bytes.size())); + cereal::CarParams::Reader CP = cmsg.getRoot(); + not_car = CP.getNotCar(); + not_car_checked = true; + } + } + if (not_car) { + ir_pwr = 0; + } + if (ir_pwr != prev_ir_pwr || sm.frame % 100 == 0) { - int16_t ir_panda = util::map_val(ir_pwr, 0, 100, 0, MAX_IR_PANDA_VAL); + int16_t ir_panda = util::map_val(ir_pwr, 0, 100, 0, MAX_IR_PANDA_VAL); panda->set_ir_pwr(ir_panda); - Hardware::set_ir_power(ir_pwr); + Hardware::set_ir_power(ir_pwr); prev_ir_pwr = ir_pwr; } } @@ -371,7 +388,7 @@ void pandad_run(Panda *panda) { // Process peripheral state at 20 Hz if (rk.frame() % 5 == 0) { - process_peripheral_state(panda, &pm, no_fan_control); + process_peripheral_state(panda, &pm, no_fan_control, is_onroad); } // Process panda state at 10 Hz diff --git a/selfdrive/selfdrived/selfdrived.py b/selfdrive/selfdrived/selfdrived.py index 6a294ca8d8..dbc3174af7 100755 --- a/selfdrive/selfdrived/selfdrived.py +++ b/selfdrive/selfdrived/selfdrived.py @@ -192,7 +192,7 @@ class SelfdriveD: if self.CP.notCar: # wait for everything to init first - if self.sm.frame > int(5. / DT_CTRL) and self.initialized: + if self.sm.frame > int(2. / DT_CTRL) and self.initialized: # body always wants to enable self.events.add(EventName.pcmEnable)