Skip to content

Commit f5fa15e

Browse files
author
Vehicle Researcher
committed
Squashed 'panda/' changes from 0696730..0c2c149
0c2c149 Fixing libusb busy error (#174) 753c42c Update Board Mac SDK Install script to work on clean mac (#146) b9a9ea3 Unsafe gas disengage mods, fix test compile warning (#481) 08ef92d Safety model for Volkswagen PQ35/PQ46/NMS (#474) 51e0a55 Support code for unsafe mode unit tests (#478) 5325b62 current_safety_mode 7908b72 update updating unsafe mode 98503e8 disable stock honda AEB in unsafe mode (#477) 01b2ccb one more 9a30265 weak steering while not engaged 577f10b added options for unsafe mode 83cf7bf update comment 4556e74 enable unsafe mode, toggle for use by forks that so choose de89fcd Nissan leaf (#473) git-subtree-dir: panda git-subtree-split: 0c2c149
1 parent a3690e4 commit f5fa15e

17 files changed

+682
-90
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.7.3
1+
v1.7.4

board/get_sdk_mac.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22
# Need formula for gcc
3+
sudo easy_install pip
4+
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
35
brew tap ArmMbed/homebrew-formulae
46
brew install python dfu-util arm-none-eabi-gcc
57
pip install --user libusb1 pycrypto requests

board/main.c

+9
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,15 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
469469
can_init(CAN_NUM_FROM_BUS_NUM(setup->b.wValue.w));
470470
}
471471
break;
472+
// **** 0xdf: set unsafe mode
473+
case 0xdf:
474+
// you can only set this if you are in a non car safety mode
475+
if ((current_safety_mode == SAFETY_SILENT) ||
476+
(current_safety_mode == SAFETY_NOOUTPUT) ||
477+
(current_safety_mode == SAFETY_ELM327)) {
478+
unsafe_mode = setup->b.wValue.w;
479+
}
480+
break;
472481
// **** 0xe0: uart read
473482
case 0xe0:
474483
ur = get_ring_by_number(setup->b.wValue.w);

board/safety.h

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#define SAFETY_GM_ASCM 18U
3838
#define SAFETY_NOOUTPUT 19U
3939
#define SAFETY_HONDA_BOSCH_HARNESS 20U
40+
#define SAFETY_VOLKSWAGEN_PQ 21U
4041
#define SAFETY_SUBARU_LEGACY 22U
4142

4243
uint16_t current_safety_mode = SAFETY_SILENT;
@@ -203,6 +204,7 @@ const safety_hook_config safety_hook_registry[] = {
203204
{SAFETY_SUBARU_LEGACY, &subaru_legacy_hooks},
204205
{SAFETY_MAZDA, &mazda_hooks},
205206
{SAFETY_VOLKSWAGEN_MQB, &volkswagen_mqb_hooks},
207+
{SAFETY_VOLKSWAGEN_PQ, &volkswagen_pq_hooks},
206208
{SAFETY_NOOUTPUT, &nooutput_hooks},
207209
#ifdef ALLOW_DEBUG
208210
{SAFETY_CADILLAC, &cadillac_hooks},

board/safety/safety_honda.h

+16-12
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,22 @@ static int honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
138138
gas_pressed_prev = gas_pressed;
139139
}
140140
}
141-
if ((bus == 2) && (addr == 0x1FA)) {
142-
bool honda_stock_aeb = GET_BYTE(to_push, 3) & 0x20;
143-
int honda_stock_brake = (GET_BYTE(to_push, 0) << 2) + ((GET_BYTE(to_push, 1) >> 6) & 0x3);
144-
145-
// Forward AEB when stock braking is higher than openpilot braking
146-
// only stop forwarding when AEB event is over
147-
if (!honda_stock_aeb) {
148-
honda_fwd_brake = false;
149-
} else if (honda_stock_brake >= honda_brake) {
150-
honda_fwd_brake = true;
151-
} else {
152-
// Leave Honda forward brake as is
141+
142+
// disable stock Honda AEB in unsafe mode
143+
if ( !(unsafe_mode & UNSAFE_DISABLE_STOCK_AEB) ) {
144+
if ((bus == 2) && (addr == 0x1FA)) {
145+
bool honda_stock_aeb = GET_BYTE(to_push, 3) & 0x20;
146+
int honda_stock_brake = (GET_BYTE(to_push, 0) << 2) + ((GET_BYTE(to_push, 1) >> 6) & 0x3);
147+
148+
// Forward AEB when stock braking is higher than openpilot braking
149+
// only stop forwarding when AEB event is over
150+
if (!honda_stock_aeb) {
151+
honda_fwd_brake = false;
152+
} else if (honda_stock_brake >= honda_brake) {
153+
honda_fwd_brake = true;
154+
} else {
155+
// Leave Honda forward brake as is
156+
}
153157
}
154158
}
155159

board/safety/safety_nissan.h

+47-41
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@ const struct lookup_t NISSAN_LOOKUP_ANGLE_RATE_DOWN = {
99
{2., 7., 17.},
1010
{5., 3.5, .5}};
1111

12-
const struct lookup_t NISSAN_LOOKUP_MAX_ANGLE = {
13-
{3.3, 12, 32},
14-
{540., 120., 23.}};
15-
1612
const int NISSAN_DEG_TO_CAN = 100;
1713

18-
const AddrBus NISSAN_TX_MSGS[] = {{0x169, 0}, {0x2b1, 0}, {0x4cc, 0}, {0x20b, 2}};
14+
const AddrBus NISSAN_TX_MSGS[] = {{0x169, 0}, {0x2b1, 0}, {0x4cc, 0}, {0x20b, 2}, {0x280, 2}};
1915

2016
AddrCheckStruct nissan_rx_checks[] = {
21-
{.addr = {0x2}, .bus = 0, .expected_timestep = 10000U},
22-
{.addr = {0x29a}, .bus = 0, .expected_timestep = 20000U},
23-
{.addr = {0x1b6}, .bus = 1, .expected_timestep = 10000U},
17+
{.addr = {0x2}, .bus = 0, .expected_timestep = 10000U}, // STEER_ANGLE_SENSOR (100Hz)
18+
{.addr = {0x285}, .bus = 0, .expected_timestep = 20000U}, // WHEEL_SPEEDS_REAR (50Hz)
19+
{.addr = {0x30f}, .bus = 2, .expected_timestep = 100000U}, // CRUISE_STATE (10Hz)
20+
{.addr = {0x15c, 0x239}, .bus = 0, .expected_timestep = 20000U}, // GAS_PEDAL (100Hz / 50Hz)
21+
{.addr = {0x454, 0x1cc}, .bus = 0, .expected_timestep = 100000U}, // DOORS_LIGHTS (10Hz) / BRAKE (100Hz)
2422
};
2523
const int NISSAN_RX_CHECK_LEN = sizeof(nissan_rx_checks) / sizeof(nissan_rx_checks[0]);
2624

@@ -54,15 +52,22 @@ static int nissan_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
5452
update_sample(&nissan_angle_meas, angle_meas_new);
5553
}
5654

57-
if (addr == 0x29a) {
55+
if (addr == 0x285) {
5856
// Get current speed
59-
// Factor 0.00555
60-
nissan_speed = ((GET_BYTE(to_push, 2) << 8) | (GET_BYTE(to_push, 3))) * 0.00555 / 3.6;
57+
// Factor 0.005
58+
nissan_speed = ((GET_BYTE(to_push, 2) << 8) | (GET_BYTE(to_push, 3))) * 0.005 / 3.6;
6159
}
6260

6361
// exit controls on rising edge of gas press
64-
if (addr == 0x15c) {
65-
bool gas_pressed = ((GET_BYTE(to_push, 5) << 2) | ((GET_BYTE(to_push, 6) >> 6) & 0x3));
62+
// X-Trail 0x15c, Leaf 0x239
63+
if ((addr == 0x15c) || (addr == 0x239)) {
64+
bool gas_pressed = true;
65+
if (addr == 0x15c){
66+
gas_pressed = ((GET_BYTE(to_push, 5) << 2) | ((GET_BYTE(to_push, 6) >> 6) & 0x3)) > 1;
67+
} else {
68+
gas_pressed = GET_BYTE(to_push, 0) > 3;
69+
}
70+
6671
if (gas_pressed && !gas_pressed_prev) {
6772
controls_allowed = 0;
6873
}
@@ -75,26 +80,34 @@ static int nissan_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
7580
}
7681
}
7782

78-
if (bus == 1) {
79-
if (addr == 0x1b6) {
80-
int cruise_engaged = (GET_BYTE(to_push, 4) >> 6) & 1;
81-
if (cruise_engaged && !nissan_cruise_engaged_last) {
82-
controls_allowed = 1;
83-
}
84-
if (!cruise_engaged) {
85-
controls_allowed = 0;
86-
}
87-
nissan_cruise_engaged_last = cruise_engaged;
83+
// exit controls on rising edge of brake press, or if speed > 0 and brake
84+
// X-trail 0x454, Leaf 0x1cc
85+
if ((addr == 0x454) || (addr == 0x1cc)) {
86+
bool brake_pressed = true;
87+
if (addr == 0x454){
88+
brake_pressed = (GET_BYTE(to_push, 2) & 0x80) != 0;
89+
} else {
90+
brake_pressed = GET_BYTE(to_push, 0) > 3;
8891
}
8992

90-
// exit controls on rising edge of brake press, or if speed > 0 and brake
91-
if (addr == 0x454) {
92-
bool brake_pressed = (GET_BYTE(to_push, 2) & 0x80) != 0;
93-
if (brake_pressed && (!brake_pressed_prev || (nissan_speed > 0.))) {
94-
controls_allowed = 0;
95-
}
96-
brake_pressed_prev = brake_pressed;
93+
if (brake_pressed && (!brake_pressed_prev || (nissan_speed > 0.))) {
94+
controls_allowed = 0;
95+
}
96+
brake_pressed_prev = brake_pressed;
97+
}
98+
99+
100+
// Handle cruise enabled
101+
if ((bus == 2) && (addr == 0x30f)) {
102+
bool cruise_engaged = (GET_BYTE(to_push, 0) >> 3) & 1;
103+
104+
if (cruise_engaged && !nissan_cruise_engaged_last) {
105+
controls_allowed = 1;
97106
}
107+
if (!cruise_engaged) {
108+
controls_allowed = 0;
109+
}
110+
nissan_cruise_engaged_last = cruise_engaged;
98111
}
99112
}
100113
return valid;
@@ -133,16 +146,6 @@ static int nissan_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
133146
int highest_desired_angle = nissan_desired_angle_last + ((nissan_desired_angle_last > 0) ? delta_angle_up : delta_angle_down);
134147
int lowest_desired_angle = nissan_desired_angle_last - ((nissan_desired_angle_last >= 0) ? delta_angle_down : delta_angle_up);
135148

136-
// Limit maximum steering angle at current speed
137-
int maximum_angle = ((int)interpolate(NISSAN_LOOKUP_MAX_ANGLE, nissan_speed));
138-
139-
if (highest_desired_angle > (maximum_angle * NISSAN_DEG_TO_CAN)) {
140-
highest_desired_angle = (maximum_angle * NISSAN_DEG_TO_CAN);
141-
}
142-
if (lowest_desired_angle < (-maximum_angle * NISSAN_DEG_TO_CAN)) {
143-
lowest_desired_angle = (-maximum_angle * NISSAN_DEG_TO_CAN);
144-
}
145-
146149
// check for violation;
147150
violation |= max_limit_check(desired_angle, highest_desired_angle, lowest_desired_angle);
148151

@@ -183,7 +186,10 @@ static int nissan_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
183186
int addr = GET_ADDR(to_fwd);
184187

185188
if (bus_num == 0) {
186-
bus_fwd = 2; // ADAS
189+
int block_msg = (addr == 0x280); // CANCEL_MSG
190+
if (!block_msg) {
191+
bus_fwd = 2; // ADAS
192+
}
187193
}
188194

189195
if (bus_num == 2) {

0 commit comments

Comments
 (0)