Skip to content

Commit

Permalink
Squashed 'panda/' changes from 769ade0..b2ffaae
Browse files Browse the repository at this point in the history
b2ffaae Chrysler: disengage on gas press  (#442)
2ebbe36 Subaru: disengage on gas press (#446)
ccf75c4 Volkswagen safety updates: Phase 1 (#444)

git-subtree-dir: panda
git-subtree-split: b2ffaae
  • Loading branch information
Vehicle Researcher committed Feb 20, 2020
1 parent 6b8726e commit c0e2249
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 171 deletions.
4 changes: 2 additions & 2 deletions board/safety.h
Expand Up @@ -31,7 +31,7 @@
#define SAFETY_TESLA 10U
#define SAFETY_SUBARU 11U
#define SAFETY_MAZDA 13U
#define SAFETY_VOLKSWAGEN 15U
#define SAFETY_VOLKSWAGEN_MQB 15U
#define SAFETY_TOYOTA_IPAS 16U
#define SAFETY_ALLOUTPUT 17U
#define SAFETY_GM_ASCM 18U
Expand Down Expand Up @@ -185,7 +185,7 @@ const safety_hook_config safety_hook_registry[] = {
{SAFETY_CHRYSLER, &chrysler_hooks},
{SAFETY_SUBARU, &subaru_hooks},
{SAFETY_MAZDA, &mazda_hooks},
{SAFETY_VOLKSWAGEN, &volkswagen_hooks},
{SAFETY_VOLKSWAGEN_MQB, &volkswagen_mqb_hooks},
{SAFETY_NOOUTPUT, &nooutput_hooks},
#ifdef ALLOW_DEBUG
{SAFETY_CADILLAC, &cadillac_hooks},
Expand Down
25 changes: 22 additions & 3 deletions board/safety/safety_chrysler.h
Expand Up @@ -4,18 +4,23 @@ const uint32_t CHRYSLER_RT_INTERVAL = 250000; // 250ms between real time checks
const int CHRYSLER_MAX_RATE_UP = 3;
const int CHRYSLER_MAX_RATE_DOWN = 3;
const int CHRYSLER_MAX_TORQUE_ERROR = 80; // max torque cmd in excess of torque motor
const int CHRYSLER_GAS_THRSLD = 30; // 7% more than 2m/s
const AddrBus CHRYSLER_TX_MSGS[] = {{571, 0}, {658, 0}, {678, 0}};

// TODO: do checksum and counter checks
AddrCheckStruct chrysler_rx_checks[] = {
{.addr = {544}, .bus = 0, .expected_timestep = 10000U},
{.addr = {514}, .bus = 0, .expected_timestep = 10000U},
{.addr = {500}, .bus = 0, .expected_timestep = 20000U},
{.addr = {308}, .bus = 0, .expected_timestep = 20000U}, // verify ts
};
const int CHRYSLER_RX_CHECK_LEN = sizeof(chrysler_rx_checks) / sizeof(chrysler_rx_checks[0]);

int chrysler_rt_torque_last = 0;
int chrysler_desired_torque_last = 0;
int chrysler_cruise_engaged_last = 0;
bool chrysler_gas_prev = false;
int chrysler_speed = 0;
uint32_t chrysler_ts_last = 0;
struct sample_t chrysler_torque_meas; // last few torques measured

Expand All @@ -29,15 +34,15 @@ static int chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
int addr = GET_ADDR(to_push);

// Measured eps torque
if (addr == 544) {
if ((addr == 544) && (bus == 0)) {
int torque_meas_new = ((GET_BYTE(to_push, 4) & 0x7U) << 8) + GET_BYTE(to_push, 5) - 1024U;

// update array of samples
update_sample(&chrysler_torque_meas, torque_meas_new);
}

// enter controls on rising edge of ACC, exit controls on ACC off
if (addr == 0x1F4) {
if ((addr == 500) && (bus == 0)) {
int cruise_engaged = ((GET_BYTE(to_push, 2) & 0x38) >> 3) == 7;
if (cruise_engaged && !chrysler_cruise_engaged_last) {
controls_allowed = 1;
Expand All @@ -48,7 +53,21 @@ static int chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
chrysler_cruise_engaged_last = cruise_engaged;
}

// TODO: add gas pressed check
// update speed
if ((addr == 514) && (bus == 0)) {
int speed_l = (GET_BYTE(to_push, 0) << 4) + (GET_BYTE(to_push, 1) >> 4);
int speed_r = (GET_BYTE(to_push, 2) << 4) + (GET_BYTE(to_push, 3) >> 4);
chrysler_speed = (speed_l + speed_r) / 2;
}

// exit controls on rising edge of gas press
if ((addr == 308) && (bus == 0)) {
bool gas = (GET_BYTE(to_push, 5) & 0x7F) != 0;
if (gas && !chrysler_gas_prev && (chrysler_speed > CHRYSLER_GAS_THRSLD)) {
controls_allowed = 0;
}
chrysler_gas_prev = gas;
}

// check if stock camera ECU is on bus 0
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == 0) && (addr == 0x292)) {
Expand Down
12 changes: 11 additions & 1 deletion board/safety/safety_subaru.h
Expand Up @@ -12,6 +12,7 @@ const AddrBus SUBARU_TX_MSGS[] = {{0x122, 0}, {0x164, 0}, {0x221, 0}, {0x322, 0}

// TODO: do checksum and counter checks after adding the signals to the outback dbc file
AddrCheckStruct subaru_rx_checks[] = {
{.addr = { 0x40, 0x140}, .bus = 0, .expected_timestep = 10000U},
{.addr = {0x119, 0x371}, .bus = 0, .expected_timestep = 20000U},
{.addr = {0x240, 0x144}, .bus = 0, .expected_timestep = 50000U},
};
Expand All @@ -21,6 +22,7 @@ int subaru_cruise_engaged_last = 0;
int subaru_rt_torque_last = 0;
int subaru_desired_torque_last = 0;
uint32_t subaru_ts_last = 0;
bool subaru_gas_last = false;
struct sample_t subaru_torque_driver; // last few driver torques measured

static int subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
Expand Down Expand Up @@ -53,7 +55,15 @@ static int subaru_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
subaru_cruise_engaged_last = cruise_engaged;
}

// TODO: enforce cancellation on gas pressed
// exit controls on rising edge of gas press
if (((addr == 0x40) || (addr == 0x140)) && (bus == 0)) {
int byte = (addr == 0x40) ? 4 : 0;
bool gas = GET_BYTE(to_push, byte) != 0;
if (gas && !subaru_gas_last) {
controls_allowed = 0;
}
subaru_gas_last = gas;
}

if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && (bus == 0) && ((addr == 0x122) || (addr == 0x164))) {
relay_malfunction = true;
Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_toyota.h
Expand Up @@ -106,7 +106,7 @@ static int toyota_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {

// exit controls on rising edge of gas press
if (addr == 0x2C1) {
int gas = GET_BYTE(to_push, 6) & 0xFF;
int gas = GET_BYTE(to_push, 6);
if ((gas > 0) && (toyota_gas_prev == 0) && !gas_interceptor_detected) {
controls_allowed = 0;
}
Expand Down

0 comments on commit c0e2249

Please sign in to comment.