Skip to content

Commit

Permalink
Squashed 'panda/' changes from f2292e4..5253ab0
Browse files Browse the repository at this point in the history
5253ab0 bump panda
6277139 GM Volt: allowing 300 max steer
63b7926 Hyundai safety: temporarily disabled button spam check to avoid camera faults
53aef76 GM: passive on LKA-only cars (commaai#135)
01b5235 bumped panda version
1c0ffd1 Hyundai safety: simplifications
56794d6 Hyundai Safety Auto-Detect which CAN bus Camera is on (commaai#134)

git-subtree-dir: panda
git-subtree-split: 5253ab0
  • Loading branch information
Vehicle Researcher committed Sep 25, 2018
1 parent c4bba32 commit 5c0935d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.1.3
v1.1.5
11 changes: 7 additions & 4 deletions board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// brake rising edge
// brake > 0mph

const int GM_MAX_STEER = 255;
const int GM_MAX_STEER = 300;
const int GM_MAX_RT_DELTA = 128; // max delta torque allowed for real time checks
const int32_t GM_RT_INTERVAL = 250000; // 250ms between real time checks
const int GM_MAX_RATE_UP = 7;
Expand All @@ -22,7 +22,7 @@ const int GM_MAX_BRAKE = 350;
int gm_brake_prev = 0;
int gm_gas_prev = 0;
int gm_speed = 0;
// silence everything if stock ECUs are still online
// silence everything if stock car control ECUs are still online
int gm_ascm_detected = 0;
int gm_ignition_started = 0;
int gm_rt_torque_last = 0;
Expand Down Expand Up @@ -63,8 +63,11 @@ static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
gm_speed = to_push->RDLR & 0xFFFF;
}

// check if stock ASCM ECU is still online
if (bus_number == 0 && addr == 715) {
// Check if ASCM or LKA camera are online
// on powertrain bus.
// 384 = ASCMLKASteeringCmd
// 715 = ASCMGasRegenCmd
if (bus_number == 0 && (addr == 384 || addr == 715)) {
gm_ascm_detected = 1;
controls_allowed = 0;
}
Expand Down
27 changes: 17 additions & 10 deletions board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const int HYUNDAI_DRIVER_TORQUE_ALLOWANCE = 50;
const int HYUNDAI_DRIVER_TORQUE_FACTOR = 2;

int hyundai_camera_detected = 0;
int hyundai_camera_bus = 0;
int hyundai_giraffe_switch_2 = 0; // is giraffe switch 2 high?
int hyundai_rt_torque_last = 0;
int hyundai_desired_torque_last = 0;
Expand Down Expand Up @@ -39,6 +40,11 @@ static void hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
controls_allowed = 0;
}

// Find out which bus the camera is on
if (addr == 832) {
hyundai_camera_bus = bus;
}

// enter controls on rising edge of ACC, exit controls on ACC off
if ((to_push->RIR>>21) == 1057) {
// 2 bits: 13-14
Expand All @@ -51,8 +57,8 @@ static void hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
hyundai_cruise_engaged_last = cruise_engaged;
}

// 832 is lkas cmd. If it is on bus 2, then giraffe switch 2 is high
if ((to_push->RIR>>21) == 832 && (bus == 2)) {
// 832 is lkas cmd. If it is on camera bus, then giraffe switch 2 is high
if ((to_push->RIR>>21) == 832 && (bus == hyundai_camera_bus) && (hyundai_camera_bus != 0)) {
hyundai_giraffe_switch_2 = 1;
}
}
Expand Down Expand Up @@ -123,21 +129,22 @@ static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
// FORCE CANCEL: safety check only relevant when spamming the cancel button.
// ensuring that only the cancel button press is sent (VAL 4) when controls are off.
// This avoids unintended engagements while still allowing resume spam
if (((to_send->RIR>>21) == 1265) && !controls_allowed && ((to_send->RDTR >> 4) & 0xFF) == 0) {
if ((to_send->RDLR & 0x7) != 4) return 0;
}
// TODO: fix bug preventing the button msg to be fwd'd on bus 2
//if (((to_send->RIR>>21) == 1265) && !controls_allowed && ((to_send->RDTR >> 4) & 0xFF) == 0) {
// if ((to_send->RDLR & 0x7) != 4) return 0;
//}

// 1 allows the message through
return true;
}

static int hyundai_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {

// forward cam to ccan and viceversa, except lkas cmd
if ((bus_num == 0 || bus_num == 2) && hyundai_giraffe_switch_2) {
int addr = to_fwd->RIR>>21;
bool is_lkas_msg = addr == 832 && bus_num == 2;
return is_lkas_msg? -1 : (uint8_t)(~bus_num & 0x2);
if ((bus_num == 0 || bus_num == hyundai_camera_bus) && hyundai_giraffe_switch_2) {

if ((to_fwd->RIR>>21) == 832 && bus_num == hyundai_camera_bus) return -1;
if (bus_num == 0) return hyundai_camera_bus;
if (bus_num == hyundai_camera_bus) return 0;
}
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/safety/test_gm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

MAX_RATE_UP = 7
MAX_RATE_DOWN = 17
MAX_STEER = 255
MAX_STEER = 300
MAX_BRAKE = 350
MAX_GAS = 3072
MAX_REGEN = 1404
Expand Down
24 changes: 12 additions & 12 deletions tests/safety/test_hyundai.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,18 @@ def test_realtime_limits(self):
self.assertTrue(self.safety.hyundai_tx_hook(self._torque_msg(sign * (MAX_RT_DELTA + 1))))


def test_spam_cancel_safety_check(self):
RESUME_BTN = 1
SET_BTN = 2
CANCEL_BTN = 4
BUTTON_MSG = 1265
self.safety.set_controls_allowed(0)
self.assertTrue(self.safety.hyundai_tx_hook(self._button_msg(CANCEL_BTN)))
self.assertFalse(self.safety.hyundai_tx_hook(self._button_msg(RESUME_BTN)))
self.assertFalse(self.safety.hyundai_tx_hook(self._button_msg(SET_BTN)))
# do not block resume if we are engaged already
self.safety.set_controls_allowed(1)
self.assertTrue(self.safety.hyundai_tx_hook(self._button_msg(RESUME_BTN)))
#def test_spam_cancel_safety_check(self):
# RESUME_BTN = 1
# SET_BTN = 2
# CANCEL_BTN = 4
# BUTTON_MSG = 1265
# self.safety.set_controls_allowed(0)
# self.assertTrue(self.safety.hyundai_tx_hook(self._button_msg(CANCEL_BTN)))
# self.assertFalse(self.safety.hyundai_tx_hook(self._button_msg(RESUME_BTN)))
# self.assertFalse(self.safety.hyundai_tx_hook(self._button_msg(SET_BTN)))
# # do not block resume if we are engaged already
# self.safety.set_controls_allowed(1)
# self.assertTrue(self.safety.hyundai_tx_hook(self._button_msg(RESUME_BTN)))


if __name__ == "__main__":
Expand Down

0 comments on commit 5c0935d

Please sign in to comment.