Skip to content

Commit dc3cc24

Browse files
author
Commaremote
committed
Safety: made common the max torque check as well
1 parent dbc3568 commit dc3cc24

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

board/safety.h

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last);
1313
int to_signed(int d, int bits);
1414
void update_sample(struct sample_t *sample, int sample_new);
1515
int rt_rate_limit_check(int val, int val_last, const int MAX_RT_DELTA);
16+
int max_limit_check(int val, const int MAX);
1617

1718
typedef void (*safety_hook_init)(int16_t param);
1819
typedef void (*rx_hook)(CAN_FIFOMailBox_TypeDef *to_push);
@@ -153,3 +154,7 @@ int rt_rate_limit_check(int val, int val_last, const int MAX_RT_DELTA) {
153154
// return 1 if violation
154155
return (val < lowest_val) || (val > highest_val);
155156
}
157+
158+
int max_limit_check(int val, const int MAX) {
159+
return (val > MAX) | (val < -MAX);
160+
}

board/safety/safety_cadillac.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
7171
if (controls_allowed) {
7272

7373
// *** global torque limit check ***
74-
if ((desired_torque > CADILLAC_STEER_MAX) || (desired_torque < -CADILLAC_STEER_MAX)) {
75-
violation = 1;
76-
}
74+
violation |= max_limit_check(desired_torque, CADILLAC_STEER_MAX);
7775

7876
// *** torque rate limit check ***
7977
int highest_allowed_torque = max(cadillac_desired_torque_last[idx], 0) + CADILLAC_MAX_RATE_UP;
@@ -99,7 +97,7 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
9997
violation = 1;
10098
}
10199

102-
//// used next time
100+
// used next time
103101
cadillac_desired_torque_last[idx] = desired_torque;
104102

105103
// *** torque real time rate limit check ***

board/safety/safety_toyota.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
8989
if (controls_allowed && actuation_limits) {
9090

9191
// *** global torque limit check ***
92-
if (desired_torque < -MAX_TORQUE) violation = 1;
93-
if (desired_torque > MAX_TORQUE) violation = 1;
92+
violation |= max_limit_check(desired_torque, MAX_TORQUE);
9493

9594
// *** torque rate limit check ***
9695
int16_t highest_allowed_torque = max(desired_torque_last, 0) + MAX_RATE_UP;

0 commit comments

Comments
 (0)