Skip to content

Commit

Permalink
Honda safety: better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiasini committed Jun 4, 2019
1 parent 95b0109 commit a00a50c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions board/safety/safety_honda.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
// brake > 0mph

// these are set in the Honda safety hooks...this is the wrong place
const int gas_interceptor_threshold = 328;
const int HONDA_GAS_INTERCEPTOR_THRESHOLD = 328;
int gas_interceptor_detected = 0;
int brake_prev = 0;
int gas_prev = 0;
int gas_interceptor_prev = 0;
int honda_gas_prev = 0;
int honda_gas_interceptor_prev = 0;
int ego_speed = 0;
// TODO: auto-detect bosch hardware based on CAN messages?
bool bosch_hardware = false;
Expand Down Expand Up @@ -60,21 +60,21 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
if ((to_push->RIR>>21) == 0x201 && (to_push->RDTR & 0xf) == 6) {
gas_interceptor_detected = 1;
int gas_interceptor = ((to_push->RDLR & 0xFF) << 8) | ((to_push->RDLR & 0xFF00) >> 8);
if ((gas_interceptor > gas_interceptor_threshold) &&
(gas_interceptor_prev <= gas_interceptor_threshold)) {
if ((gas_interceptor > HONDA_GAS_INTERCEPTOR_THRESHOLD) &&
(honda_gas_interceptor_prev <= HONDA_GAS_INTERCEPTOR_THRESHOLD)) {
controls_allowed = 0;
}
gas_interceptor_prev = gas_interceptor;
honda_gas_interceptor_prev = gas_interceptor;
}

// exit controls on rising edge of gas press if no interceptor
if (!gas_interceptor_detected) {
if ((to_push->RIR>>21) == 0x17C) {
int gas = to_push->RDLR & 0xFF;
if (gas && !(gas_prev)) {
if (gas && !(honda_gas_prev)) {
controls_allowed = 0;
}
gas_prev = gas;
honda_gas_prev = gas;
}
}
}
Expand All @@ -89,7 +89,7 @@ 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 > gas_interceptor_threshold) ||
int pedal_pressed = honda_gas_prev || (honda_gas_interceptor_prev > HONDA_GAS_INTERCEPTOR_THRESHOLD) ||
(brake_prev && ego_speed);
int current_controls_allowed = controls_allowed && !(pedal_pressed);

Expand Down
2 changes: 1 addition & 1 deletion tests/safety/libpandasafety_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push);
int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send);
int get_brake_prev(void);
int get_gas_prev(void);
int get_honda_gas_prev(void);
void set_honda_alt_brake_msg(bool);
void set_bosch_hardware(bool);
Expand Down
6 changes: 3 additions & 3 deletions tests/safety/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ int get_brake_prev(void){
return brake_prev;
}

int get_gas_prev(void){
return gas_prev;
int get_honda_gas_prev(void){
return honda_gas_prev;
}

void set_honda_alt_brake_msg(bool c){
Expand Down Expand Up @@ -235,7 +235,7 @@ void init_tests_honda(void){
ego_speed = 0;
gas_interceptor_detected = 0;
brake_prev = 0;
gas_prev = 0;
honda_gas_prev = 0;
}

void set_gmlan_digital_output(int to_set){
Expand Down
4 changes: 2 additions & 2 deletions tests/safety/test_honda.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ def test_not_allow_brake_when_moving(self):
self.assertFalse(self.safety.get_controls_allowed())

def test_prev_gas(self):
self.assertFalse(self.safety.get_gas_prev())
self.assertFalse(self.safety.get_honda_gas_prev())
self.safety.honda_rx_hook(self._gas_msg(True))
self.assertTrue(self.safety.get_gas_prev())
self.assertTrue(self.safety.get_honda_gas_prev())

def test_disengage_on_gas(self):
self.safety.set_controls_allowed(1)
Expand Down

0 comments on commit a00a50c

Please sign in to comment.