Pre enable (#41)

* added rising edge cancellation to accomodate pre-enable state
* disallowing actuators when pedals are pressed
master
rbiasini 2017-09-14 20:23:20 -07:00 committed by GitHub
parent 303c7f6a82
commit 9e5c385def
1 changed files with 42 additions and 16 deletions

View File

@ -3,17 +3,25 @@
// accel set/resume
// out-state
// cancel button
// accel rising edge
// brake rising edge
// brake > 0mph
// these are set in the Honda safety hooks...this is the wrong place
int gas_interceptor_detected = 0;
// all commands: brake and steering
// if controls_allowed
// allow all commands up to limit
// else
// block all commands that produce actuation
int brake_prev = 0;
int gas_prev = 0;
int gas_interceptor_prev = 0;
int speed = 0;
static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
// sample speed
if ((to_push->RIR>>21) == 0x158) {
// first 2 bytes
speed = to_push->RDLR & 0xFFFF;
}
// state machine to enter and exit controls
// 0x1A6 for the ILX, 0x296 for the Civic Touring
if ((to_push->RIR>>21) == 0x1A6 || (to_push->RIR>>21) == 0x296) {
@ -25,37 +33,55 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
}
}
// exit controls on brake press
// exit controls on rising edge of brake press or on brake press when
// speed > 0
if ((to_push->RIR>>21) == 0x17C) {
// bit 53
if (to_push->RDHR & 0x200000) {
int brake = to_push->RDHR & 0x200000;
if (brake && (!(brake_prev) || speed)) {
controls_allowed = 0;
}
brake_prev = brake;
}
// exit controls on gas press if interceptor
// exit controls on rising edge of gas press if interceptor
if ((to_push->RIR>>21) == 0x201) {
gas_interceptor_detected = 1;
int gas = ((to_push->RDLR & 0xFF) << 8) | ((to_push->RDLR & 0xFF00) >> 8);
if (gas > 328) {
int gas_interceptor = ((to_push->RDLR & 0xFF) << 8) | ((to_push->RDLR & 0xFF00) >> 8);
if ((gas_interceptor > 328) && (gas_interceptor_prev <= 328)) {
controls_allowed = 0;
}
gas_interceptor_prev = gas_interceptor;
}
// exit controls on gas press if no interceptor
// exit controls on rising edge of gas press if no interceptor
if (!gas_interceptor_detected) {
if ((to_push->RIR>>21) == 0x17C) {
if (to_push->RDLR & 0xFF) {
int gas = to_push->RDLR & 0xFF;
if (gas && !(gas_prev)) {
controls_allowed = 0;
}
gas_prev = gas;
}
}
}
// all commands: gas, brake and steering
// if controls_allowed and no pedals pressed
// allow all commands up to limit
// else
// block all commands that produce actuation
static int honda_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 = gas_prev || gas_interceptor_prev || (brake_prev && speed);
int current_controls_allowed = controls_allowed && !(pedal_pressed);
// BRAKE: safety check
if ((to_send->RIR>>21) == 0x1FA) {
if (controls_allowed) {
if (current_controls_allowed) {
if ((to_send->RDLR & 0xFFFFFF3F) != to_send->RDLR) return 0;
} else {
if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) return 0;
@ -64,7 +90,7 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
// STEER: safety check
if ((to_send->RIR>>21) == 0xE4 || (to_send->RIR>>21) == 0x194) {
if (controls_allowed) {
if (current_controls_allowed) {
// all messages are fine here
} else {
if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) return 0;
@ -73,7 +99,7 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
// GAS: safety check
if ((to_send->RIR>>21) == 0x200) {
if (controls_allowed) {
if (current_controls_allowed) {
// all messages are fine here
} else {
if ((to_send->RDLR & 0xFFFF0000) != to_send->RDLR) return 0;