ef880b7 Merge pull request #116 from commaai/buy_panda
9311f0d update readme graphics
4150684 add javascript and bump pandacan version
ace4a22 Ford safety (#115)
git-subtree-dir: panda
git-subtree-split: ef880b76356a992509d809d3369b5954636969f3
old-commit-hash: dcacbf606a
commatwo_master
parent
52c303d3ea
commit
23eeec4531
6 changed files with 128 additions and 9 deletions
@ -0,0 +1,110 @@ |
||||
// board enforces
|
||||
// in-state
|
||||
// accel set/resume
|
||||
// out-state
|
||||
// cancel button
|
||||
// accel rising edge
|
||||
// brake rising edge
|
||||
// brake > 0mph
|
||||
|
||||
int ford_brake_prev = 0; |
||||
int ford_gas_prev = 0; |
||||
int ford_is_moving = 0; |
||||
|
||||
static void ford_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { |
||||
|
||||
if ((to_push->RIR>>21) == 0x217) { |
||||
// wheel speeds are 14 bits every 16
|
||||
ford_is_moving = 0xFCFF & (to_push->RDLR | (to_push->RDLR >> 16) | |
||||
to_push->RDHR | (to_push->RDHR >> 16)); |
||||
} |
||||
|
||||
// state machine to enter and exit controls
|
||||
if ((to_push->RIR>>21) == 0x83) { |
||||
int cancel = ((to_push->RDLR >> 8) & 0x1); |
||||
int set_or_resume = (to_push->RDLR >> 28) & 0x3; |
||||
if (cancel) { |
||||
controls_allowed = 0; |
||||
} else if (set_or_resume) { |
||||
controls_allowed = 1; |
||||
} |
||||
} |
||||
|
||||
// exit controls on rising edge of brake press or on brake press when
|
||||
// speed > 0
|
||||
if ((to_push->RIR>>21) == 0x165) { |
||||
int brake = to_push->RDLR & 0x20; |
||||
if (brake && (!(ford_brake_prev) || ford_is_moving)) { |
||||
controls_allowed = 0; |
||||
} |
||||
ford_brake_prev = brake; |
||||
} |
||||
|
||||
// exit controls on rising edge of gas press
|
||||
if ((to_push->RIR>>21) == 0x204) { |
||||
int gas = to_push->RDLR & 0xFF03; |
||||
if (gas && !(ford_gas_prev)) { |
||||
controls_allowed = 0; |
||||
} |
||||
ford_gas_prev = gas; |
||||
} |
||||
} |
||||
|
||||
// all commands: just steering
|
||||
// if controls_allowed and no pedals pressed
|
||||
// allow all commands up to limit
|
||||
// else
|
||||
// block all commands that produce actuation
|
||||
|
||||
static int ford_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { |
||||
|
||||
// disallow actuator commands if gas or brake (with vehicle moving) are pressed
|
||||
// and the the latching controls_allowed flag is True
|
||||
int pedal_pressed = ford_gas_prev || (ford_brake_prev && ford_is_moving); |
||||
int current_controls_allowed = controls_allowed && !(pedal_pressed); |
||||
|
||||
// STEER: safety check
|
||||
if ((to_send->RIR>>21) == 0x3CA) { |
||||
if (current_controls_allowed) { |
||||
// all messages are fine here
|
||||
} else { |
||||
// bits 7-4 need to be 0xF to disallow lkas commands
|
||||
if (((to_send->RDLR >> 4) & 0xF) != 0xF) return 0; |
||||
} |
||||
} |
||||
|
||||
// FORCE CANCEL: safety check only relevant when spamming the cancel button
|
||||
// ensuring that set and resume aren't sent
|
||||
if ((to_send->RIR>>21) == 0x83) { |
||||
if ((to_send->RDLR >> 28) & 0x3) return 0; |
||||
} |
||||
|
||||
// 1 allows the message through
|
||||
return true; |
||||
} |
||||
|
||||
static int ford_tx_lin_hook(int lin_num, uint8_t *data, int len) { |
||||
// TODO: add safety if using LIN
|
||||
return true; |
||||
} |
||||
|
||||
static void ford_init(int16_t param) { |
||||
controls_allowed = 0; |
||||
} |
||||
|
||||
static int ford_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { |
||||
return -1; |
||||
} |
||||
|
||||
static int ford_ign_hook() { |
||||
return -1; |
||||
} |
||||
|
||||
const safety_hooks ford_hooks = { |
||||
.init = ford_init, |
||||
.rx = ford_rx_hook, |
||||
.tx = ford_tx_hook, |
||||
.tx_lin = ford_tx_lin_hook, |
||||
.ignition = ford_ign_hook, |
||||
.fwd = ford_fwd_hook, |
||||
}; |
@ -1,3 +1,3 @@ |
||||
version https://git-lfs.github.com/spec/v1 |
||||
oid sha256:cbecb2af4e0c8653824353eed703bf6b4caa201940f915f1a7491ab07a42aef4 |
||||
size 4107 |
||||
oid sha256:7e5c26f88d0afd2f2591292dcaa7993f3524e889c4716cfa2294ae6e483e93b3 |
||||
size 12200 |
||||
|
@ -1,3 +1,3 @@ |
||||
version https://git-lfs.github.com/spec/v1 |
||||
oid sha256:5da391df3865ff37c97b3191e5503bcfacee7a4e48285e3e70d41ba3fd9b2c9e |
||||
size 72820 |
||||
oid sha256:4e45179de45d4c10a83dc9407b45434efab3d812733900f955faa2373542705a |
||||
size 72509 |
||||
|
Loading…
Reference in new issue