Skip to content

Commit

Permalink
Safety: made common the max torque check as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Commaremote committed Jun 13, 2018
1 parent dbc3568 commit dc3cc24
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 5 additions & 0 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last);
int to_signed(int d, int bits);
void update_sample(struct sample_t *sample, int sample_new);
int rt_rate_limit_check(int val, int val_last, const int MAX_RT_DELTA);
int max_limit_check(int val, const int MAX);

typedef void (*safety_hook_init)(int16_t param);
typedef void (*rx_hook)(CAN_FIFOMailBox_TypeDef *to_push);
Expand Down Expand Up @@ -153,3 +154,7 @@ int rt_rate_limit_check(int val, int val_last, const int MAX_RT_DELTA) {
// return 1 if violation
return (val < lowest_val) || (val > highest_val);
}

int max_limit_check(int val, const int MAX) {
return (val > MAX) | (val < -MAX);
}
6 changes: 2 additions & 4 deletions board/safety/safety_cadillac.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ static int cadillac_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
if (controls_allowed) {

// *** global torque limit check ***
if ((desired_torque > CADILLAC_STEER_MAX) || (desired_torque < -CADILLAC_STEER_MAX)) {
violation = 1;
}
violation |= max_limit_check(desired_torque, CADILLAC_STEER_MAX);

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

//// used next time
// used next time
cadillac_desired_torque_last[idx] = desired_torque;

// *** torque real time rate limit check ***
Expand Down
3 changes: 1 addition & 2 deletions board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ static int toyota_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
if (controls_allowed && actuation_limits) {

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

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

0 comments on commit dc3cc24

Please sign in to comment.