gas scaling

This commit is contained in:
firestar5683
2026-03-25 08:57:14 -05:00
parent c726bf2b98
commit 61a9a12753
2 changed files with 10 additions and 13 deletions
+3 -2
View File
@@ -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:
+7 -11
View File
@@ -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,
};