From fd2209b01c18b0123d6cb7a7c5c2df0ed587e464 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Tue, 31 Mar 2026 19:54:42 -0500 Subject: [PATCH] panda and stats --- opendbc_repo/opendbc/safety/modes/gm.h | 32 +++++++++++++++--------- starpilot/system/starpilot_stats.py | 34 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/opendbc_repo/opendbc/safety/modes/gm.h b/opendbc_repo/opendbc/safety/modes/gm.h index cfc6694d..d698c1a8 100644 --- a/opendbc_repo/opendbc/safety/modes/gm.h +++ b/opendbc_repo/opendbc/safety/modes/gm.h @@ -606,10 +606,16 @@ static safety_config gm_init(uint16_t param) { }; static RxCheck gm_pedal_rx_checks[] = { - GM_COMMON_RX_CHECKS - {.msg = {{0xBD, 0, 7, 40U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, - {.msg = {{0x3D1, 0, 8, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // Non-ACC PCM - {.msg = {{0x201, 0, 6, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // pedal + {.msg = {{0x184, 0, 8, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, + {.msg = {{0x34A, 0, 5, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, + {.msg = {{0x1E1, 0, 7, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, + {0x1E1, 2, 7, 100000U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, + { 0 }}}, + {.msg = {{0xF1, 0, 6, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, + {0xF1, 2, 6, 100000U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, + { 0 }}}, + {.msg = {{0x1C4, 0, 8, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, + {.msg = {{0xC9, 0, 8, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, }; static RxCheck gm_cam_acc_rx_checks[] = { @@ -619,11 +625,16 @@ static safety_config gm_init(uint16_t param) { }; static RxCheck gm_cam_acc_pedal_rx_checks[] = { - GM_COMMON_RX_CHECKS - GM_ACC_RX_CHECKS - {.msg = {{0xBD, 0, 7, 40U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, - {.msg = {{0x201, 0, 6, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // pedal - {.msg = {{0x370, 2, 6, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // camera ACC status + {.msg = {{0x184, 0, 8, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, + {.msg = {{0x34A, 0, 5, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, + {.msg = {{0x1E1, 0, 7, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, + {0x1E1, 2, 7, 100000U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, + { 0 }}}, + {.msg = {{0xF1, 0, 6, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, + {0xF1, 2, 6, 100000U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, + { 0 }}}, + {.msg = {{0x1C4, 0, 8, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, + {.msg = {{0xC9, 0, 8, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, }; static RxCheck gm_sdgm_acc_rx_checks[] = { @@ -650,8 +661,7 @@ static safety_config gm_init(uint16_t param) { gm_cc_long = GET_FLAG(param, GM_PARAM_CC_LONG); gm_has_acc = !GET_FLAG(param, GM_PARAM_NO_ACC); gm_pedal_long = GET_FLAG(param, GM_PARAM_PEDAL_LONG); - // Keep pedal-long behavior robust even if only PEDAL_LONG is present during transitions. - enable_gas_interceptor = GET_FLAG(param, GM_PARAM_PEDAL_INTERCEPTOR) || gm_pedal_long; + enable_gas_interceptor = GET_FLAG(param, GM_PARAM_PEDAL_INTERCEPTOR); gm_force_ascm = GET_FLAG(param, GM_PARAM_HW_ASCM_LONG); gm_force_brake_c9 = GET_FLAG(param, GM_PARAM_FORCE_BRAKE_C9); gm_bolt_2022_pedal = GET_FLAG(param, GM_PARAM_BOLT_2022_PEDAL); diff --git a/starpilot/system/starpilot_stats.py b/starpilot/system/starpilot_stats.py index 41e378d1..527b7bf4 100644 --- a/starpilot/system/starpilot_stats.py +++ b/starpilot/system/starpilot_stats.py @@ -8,6 +8,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), "..", "third_party")) from collections import Counter from datetime import datetime, timezone +from cereal import log from influxdb_client import InfluxDBClient, Point from influxdb_client.client.write_api import SYNCHRONOUS @@ -50,6 +51,33 @@ def _json_object(value): return {} return {} +def get_live_delay_stats(): + defaults = { + "lagd_calibration_percent": 0, + "lagd_valid_blocks": 0, + "lagd_applied_delay_seconds": 0.0, + "lagd_learned_delay_seconds": 0.0, + "lagd_learned_delay_std_seconds": 0.0, + } + + live_delay_data = params.get("LiveDelay") + if not live_delay_data: + return defaults + + try: + with log.Event.from_bytes(live_delay_data) as live_delay_msg: + live_delay = live_delay_msg.liveDelay + return { + "lagd_calibration_percent": int(getattr(live_delay, "calPerc", 0)), + "lagd_valid_blocks": int(getattr(live_delay, "validBlocks", 0)), + "lagd_applied_delay_seconds": float(getattr(live_delay, "lateralDelay", 0.0)), + "lagd_learned_delay_seconds": float(getattr(live_delay, "lateralDelayEstimate", 0.0)), + "lagd_learned_delay_std_seconds": float(getattr(live_delay, "lateralDelayEstimateStd", 0.0)), + } + except Exception as exception: + print(f"Failed to parse LiveDelay stats: {exception}") + return defaults + def get_population_value(population_str): if population_str is None: return None @@ -209,6 +237,7 @@ def send_stats(): device_type = HARDWARE.get_device_type() stats_dongle_id = params.get("StarPilotDongleId", encoding="utf-8") or params.get("DongleId", encoding="utf-8") or "unknown" + live_delay_stats = get_live_delay_stats() user_point = ( Point("user_stats") @@ -238,6 +267,11 @@ def send_stats(): .field("has_sascm", getattr(starpilot_toggles, "has_sascm", False)) .field("has_zss", starpilot_toggles.has_zss) .field("latitude", latitude) + .field("lagd_applied_delay_seconds", live_delay_stats["lagd_applied_delay_seconds"]) + .field("lagd_calibration_percent", live_delay_stats["lagd_calibration_percent"]) + .field("lagd_learned_delay_seconds", live_delay_stats["lagd_learned_delay_seconds"]) + .field("lagd_learned_delay_std_seconds", live_delay_stats["lagd_learned_delay_std_seconds"]) + .field("lagd_valid_blocks", live_delay_stats["lagd_valid_blocks"]) .field("longitude", longitude) .field("rainbow_path", starpilot_toggles.rainbow_path) .field("random_events", starpilot_toggles.random_events)