Acceleration/deceleration profiles

Added toggle to use DragonPilot's acceleration/deceleration profiles.

Credit goes to DragonPilot!

https: //github.com/dragonpilot-community/dragonpilot
Co-Authored-By: eFini <16603033+efinilan@users.noreply.github.com>
Co-Authored-By: Kumar <36933347+rav4kumar@users.noreply.github.com>
This commit is contained in:
FrogAi
2024-03-06 17:50:06 -07:00
parent f01d5fb25a
commit 121fd2d246
30 changed files with 259 additions and 31 deletions

View File

@@ -16,6 +16,13 @@ const LongitudinalLimits GM_ASCM_LONG_LIMITS = {
.max_brake = 400,
};
const LongitudinalLimits GM_ASCM_LONG_LIMITS_SPORT = {
.max_gas = 8191,
.min_gas = 1404,
.inactive_gas = 1404,
.max_brake = 400,
};
const LongitudinalLimits GM_CAM_LONG_LIMITS = {
.max_gas = 3400,
.min_gas = 1514,
@@ -23,6 +30,13 @@ const LongitudinalLimits GM_CAM_LONG_LIMITS = {
.max_brake = 400,
};
const LongitudinalLimits GM_CAM_LONG_LIMITS_SPORT = {
.max_gas = 8848,
.min_gas = 1514,
.inactive_gas = 1554,
.max_brake = 400,
};
const LongitudinalLimits *gm_long_limits;
const int GM_STANDSTILL_THRSLD = 10; // 0.311kph
@@ -215,12 +229,22 @@ static int gm_fwd_hook(int bus_num, int addr) {
}
static safety_config gm_init(uint16_t param) {
sport_mode = alternative_experience & ALT_EXP_RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX;
gm_hw = GET_FLAG(param, GM_PARAM_HW_CAM) ? GM_CAM : GM_ASCM;
if (gm_hw == GM_ASCM) {
gm_long_limits = &GM_ASCM_LONG_LIMITS;
if (sport_mode) {
gm_long_limits = &GM_ASCM_LONG_LIMITS_SPORT;
} else {
gm_long_limits = &GM_ASCM_LONG_LIMITS;
}
} else if (gm_hw == GM_CAM) {
gm_long_limits = &GM_CAM_LONG_LIMITS;
if (sport_mode) {
gm_long_limits = &GM_CAM_LONG_LIMITS_SPORT;
} else {
gm_long_limits = &GM_CAM_LONG_LIMITS;
}
} else {
}

View File

@@ -19,6 +19,14 @@ const LongitudinalLimits HONDA_BOSCH_LONG_LIMITS = {
.inactive_gas = -30000,
};
const LongitudinalLimits HONDA_BOSCH_LONG_LIMITS_SPORT = {
.max_accel = 400, // accel is used for brakes
.min_accel = -350,
.max_gas = 2000,
.inactive_gas = -30000,
};
const LongitudinalLimits HONDA_NIDEC_LONG_LIMITS = {
.max_gas = 198, // 0xc6
.max_brake = 255,
@@ -270,6 +278,8 @@ static void honda_rx_hook(const CANPacket_t *to_push) {
}
static bool honda_tx_hook(const CANPacket_t *to_send) {
sport_mode = alternative_experience & ALT_EXP_RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX;
bool tx = true;
int addr = GET_ADDR(to_send);
int bus = GET_BUS(to_send);
@@ -310,8 +320,13 @@ static bool honda_tx_hook(const CANPacket_t *to_send) {
gas = to_signed(gas, 16);
bool violation = false;
violation |= longitudinal_accel_checks(accel, HONDA_BOSCH_LONG_LIMITS);
violation |= longitudinal_gas_checks(gas, HONDA_BOSCH_LONG_LIMITS);
if (sport_mode) {
violation |= longitudinal_accel_checks(accel, HONDA_BOSCH_LONG_LIMITS_SPORT);
violation |= longitudinal_gas_checks(gas, HONDA_BOSCH_LONG_LIMITS_SPORT);
} else {
violation |= longitudinal_accel_checks(accel, HONDA_BOSCH_LONG_LIMITS);
violation |= longitudinal_gas_checks(gas, HONDA_BOSCH_LONG_LIMITS);
}
if (violation) {
tx = false;
}
@@ -323,7 +338,11 @@ static bool honda_tx_hook(const CANPacket_t *to_send) {
accel = to_signed(accel, 12);
bool violation = false;
violation |= longitudinal_accel_checks(accel, HONDA_BOSCH_LONG_LIMITS);
if (sport_mode) {
violation |= longitudinal_accel_checks(accel, HONDA_BOSCH_LONG_LIMITS_SPORT);
} else {
violation |= longitudinal_accel_checks(accel, HONDA_BOSCH_LONG_LIMITS);
}
if (violation) {
tx = false;
}

View File

@@ -25,6 +25,11 @@ const LongitudinalLimits HYUNDAI_LONG_LIMITS = {
.min_accel = -350, // 1/100 m/s2
};
const LongitudinalLimits HYUNDAI_LONG_LIMITS_SPORT = {
.max_accel = 400, // 1/100 m/s2
.min_accel = -350, // 1/100 m/s2
};
const CanMsg HYUNDAI_TX_MSGS[] = {
{0x340, 0, 8}, // LKAS11 Bus 0
{0x4F1, 0, 4}, // CLU11 Bus 0
@@ -215,6 +220,8 @@ static void hyundai_rx_hook(const CANPacket_t *to_push) {
}
static bool hyundai_tx_hook(const CANPacket_t *to_send) {
sport_mode = alternative_experience & ALT_EXP_RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX;
bool tx = true;
int addr = GET_ADDR(to_send);
@@ -239,8 +246,13 @@ static bool hyundai_tx_hook(const CANPacket_t *to_send) {
bool violation = false;
violation |= longitudinal_accel_checks(desired_accel_raw, HYUNDAI_LONG_LIMITS);
violation |= longitudinal_accel_checks(desired_accel_val, HYUNDAI_LONG_LIMITS);
if (sport_mode) {
violation |= longitudinal_accel_checks(desired_accel_raw, HYUNDAI_LONG_LIMITS_SPORT);
violation |= longitudinal_accel_checks(desired_accel_val, HYUNDAI_LONG_LIMITS_SPORT);
} else {
violation |= longitudinal_accel_checks(desired_accel_raw, HYUNDAI_LONG_LIMITS);
violation |= longitudinal_accel_checks(desired_accel_val, HYUNDAI_LONG_LIMITS);
}
violation |= (aeb_decel_cmd != 0);
violation |= aeb_req;

View File

@@ -37,6 +37,11 @@ const LongitudinalLimits TOYOTA_LONG_LIMITS = {
.min_accel = -3500, // -3.5 m/s2
};
const LongitudinalLimits TOYOTA_LONG_LIMITS_SPORT = {
.max_accel = 4000, // 4.0 m/s2
.min_accel = -3500, // -3.5 m/s2
};
// panda interceptor threshold needs to be equivalent to openpilot threshold to avoid controls mismatches
// If thresholds are mismatched then it is possible for panda to see the gas fall and rise while openpilot is in the pre-enabled state
// Threshold calculated from DBC gains: round((((15 + 75.555) / 0.159375) + ((15 + 151.111) / 0.159375)) / 2) = 805
@@ -228,6 +233,8 @@ static void toyota_rx_hook(const CANPacket_t *to_push) {
}
static bool toyota_tx_hook(const CANPacket_t *to_send) {
sport_mode = alternative_experience & ALT_EXP_RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX;
bool tx = true;
int addr = GET_ADDR(to_send);
int bus = GET_BUS(to_send);
@@ -248,7 +255,11 @@ static bool toyota_tx_hook(const CANPacket_t *to_send) {
desired_accel = to_signed(desired_accel, 16);
bool violation = false;
violation |= longitudinal_accel_checks(desired_accel, TOYOTA_LONG_LIMITS);
if (sport_mode) {
violation |= longitudinal_accel_checks(desired_accel, TOYOTA_LONG_LIMITS_SPORT);
} else {
violation |= longitudinal_accel_checks(desired_accel, TOYOTA_LONG_LIMITS);
}
// only ACC messages that cancel are allowed when openpilot is not controlling longitudinal
if (toyota_stock_longitudinal) {

View File

@@ -20,6 +20,12 @@ const LongitudinalLimits VOLKSWAGEN_MQB_LONG_LIMITS = {
.inactive_accel = 3010, // VW sends one increment above the max range when inactive
};
const LongitudinalLimits VOLKSWAGEN_MQB_LONG_LIMITS_SPORT = {
.max_accel = 4000,
.min_accel = -3500,
.inactive_accel = 3010, // VW sends one increment above the max range when inactive
};
#define MSG_ESP_19 0x0B2 // RX from ABS, for wheel speeds
#define MSG_LH_EPS_03 0x09F // RX from EPS, for driver steering torque
#define MSG_ESP_05 0x106 // RX from ABS, for brake switch state
@@ -197,6 +203,8 @@ static void volkswagen_mqb_rx_hook(const CANPacket_t *to_push) {
}
static bool volkswagen_mqb_tx_hook(const CANPacket_t *to_send) {
sport_mode = alternative_experience & ALT_EXP_RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX;
int addr = GET_ADDR(to_send);
bool tx = true;
@@ -234,7 +242,15 @@ static bool volkswagen_mqb_tx_hook(const CANPacket_t *to_send) {
desired_accel = (((GET_BYTE(to_send, 7) << 3) | ((GET_BYTE(to_send, 6) & 0xE0U) >> 5)) * 5U) - 7220U;
}
violation |= longitudinal_accel_checks(desired_accel, VOLKSWAGEN_MQB_LONG_LIMITS);
if (sport_mode) {
if (desired_accel != 0) {
violation |= longitudinal_accel_checks(desired_accel, VOLKSWAGEN_MQB_LONG_LIMITS_SPORT);
}
} else {
if (desired_accel != 0) {
violation |= longitudinal_accel_checks(desired_accel, VOLKSWAGEN_MQB_LONG_LIMITS);
}
}
if (violation) {
tx = false;

View File

@@ -20,6 +20,12 @@ const LongitudinalLimits VOLKSWAGEN_PQ_LONG_LIMITS = {
.inactive_accel = 3010, // VW sends one increment above the max range when inactive
};
const LongitudinalLimits VOLKSWAGEN_PQ_LONG_LIMITS_SPORT = {
.max_accel = 4000,
.min_accel = -3500,
.inactive_accel = 3010, // VW sends one increment above the max range when inactive
};
#define MSG_LENKHILFE_3 0x0D0 // RX from EPS, for steering angle and driver steering torque
#define MSG_HCA_1 0x0D2 // TX by OP, Heading Control Assist steering torque
#define MSG_BREMSE_1 0x1A0 // RX from ABS, for ego speed
@@ -170,6 +176,8 @@ static void volkswagen_pq_rx_hook(const CANPacket_t *to_push) {
}
static bool volkswagen_pq_tx_hook(const CANPacket_t *to_send) {
sport_mode = alternative_experience & ALT_EXP_RAISE_LONGITUDINAL_LIMITS_TO_ISO_MAX;
int addr = GET_ADDR(to_send);
bool tx = true;
@@ -198,8 +206,14 @@ static bool volkswagen_pq_tx_hook(const CANPacket_t *to_send) {
// Signal: ACC_System.ACS_Sollbeschl (acceleration in m/s2, scale 0.005, offset -7.22)
int desired_accel = ((((GET_BYTE(to_send, 4) & 0x7U) << 8) | GET_BYTE(to_send, 3)) * 5U) - 7220U;
if (longitudinal_accel_checks(desired_accel, VOLKSWAGEN_PQ_LONG_LIMITS)) {
tx = false;
if (sport_mode) {
if (longitudinal_accel_checks(desired_accel, VOLKSWAGEN_PQ_LONG_LIMITS_SPORT)) {
tx = false;
}
} else {
if (longitudinal_accel_checks(desired_accel, VOLKSWAGEN_PQ_LONG_LIMITS)) {
tx = false;
}
}
}

View File

@@ -220,6 +220,7 @@ bool brake_pressed_prev = false;
bool regen_braking = false;
bool regen_braking_prev = false;
bool cruise_engaged_prev = false;
bool sport_mode = false;
struct sample_t vehicle_speed;
bool vehicle_moving = false;
bool acc_main_on = false; // referred to as "ACC off" in ISO 15622:2018