From 61a9a12753f2170387c59a3099fdecbed5bda800 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Wed, 25 Mar 2026 08:57:14 -0500 Subject: [PATCH] gas scaling --- opendbc_repo/opendbc/car/gm/gmcan.py | 5 +++-- opendbc_repo/opendbc/safety/modes/gm.h | 18 +++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/opendbc_repo/opendbc/car/gm/gmcan.py b/opendbc_repo/opendbc/car/gm/gmcan.py index b59e5d7e7..df10e8cfd 100644 --- a/opendbc_repo/opendbc/car/gm/gmcan.py +++ b/opendbc_repo/opendbc/car/gm/gmcan.py @@ -118,11 +118,12 @@ def create_adas_keepalive(bus): def create_gas_regen_command(packer, bus, throttle, idx, enabled, at_full_stop, include_always_one3=False): # Keep GM camera-long GasRegen bytes aligned with StarPilot's legacy layout. # The regenerated DBC shape does not pack to the same wire format on Global A. + throttle = int(throttle) dat = bytearray(8) dat[0] = ((idx & 0x3) << 6) | int(enabled) - dat[1] = 0x42 | (0x20 if at_full_stop else 0x00) + dat[1] = 0x42 | (0x20 if at_full_stop else 0x00) | ((throttle >> 13) & 0x1) - cmd = int(throttle) << 3 + cmd = throttle << 3 dat[2] = (cmd >> 8) & 0xFF dat[3] = cmd & 0xFF if include_always_one3: diff --git a/opendbc_repo/opendbc/safety/modes/gm.h b/opendbc_repo/opendbc/safety/modes/gm.h index ef820ae16..d78bb8488 100644 --- a/opendbc_repo/opendbc/safety/modes/gm.h +++ b/opendbc_repo/opendbc/safety/modes/gm.h @@ -383,8 +383,7 @@ static bool gm_tx_hook(const CANPacket_t *msg) { // GAS/REGEN: safety check if (msg->addr == 0x2CBU) { bool apply = GET_BIT(msg, 0U); - // convert float CAN signal to an int for gas checks: 22534 / 0.125 = 180272 - int gas_regen = (((msg->data[1] & 0x7U) << 16) | (msg->data[2] << 8) | msg->data[3]) - 180272U; + int gas_regen = ((msg->data[1] & 0x1U) << 13) | (msg->data[2] << 5) | ((msg->data[3] & 0xF8U) >> 3); bool violation = false; // Allow apply bit in pre-enabled and overriding states @@ -545,13 +544,10 @@ static safety_config gm_init(uint16_t param) { const uint16_t GM_PARAM_PANDA_3D1_SCHED = 16384; const uint16_t GM_PARAM_PANDA_PADDLE_SCHED = 32768; - // common safety checks assume unscaled integer values - static const int GM_GAS_TO_CAN = 8; // 1 / 0.125 - static const LongitudinalLimits GM_ASCM_LONG_LIMITS = { - .max_gas = 1018 * GM_GAS_TO_CAN, - .min_gas = -650 * GM_GAS_TO_CAN, - .inactive_gas = -650 * GM_GAS_TO_CAN, + .max_gas = 8191, + .min_gas = 5500, + .inactive_gas = 5500, .max_brake = 400, }; @@ -566,9 +562,9 @@ static safety_config gm_init(uint16_t param) { static const LongitudinalLimits GM_CAM_LONG_LIMITS = { - .max_gas = 1346 * GM_GAS_TO_CAN, - .min_gas = -540 * GM_GAS_TO_CAN, - .inactive_gas = -500 * GM_GAS_TO_CAN, + .max_gas = 8848, + .min_gas = 5610, + .inactive_gas = 5650, .max_brake = 400, };