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
This commit is contained in:
stef
2026-04-14 19:13:57 -07:00
committed by GitHub
parent f70a156c7e
commit e16d422cf4
2 changed files with 22 additions and 5 deletions

View File

@@ -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<cereal::CarParams>();
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

View File

@@ -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)