Skip to content

Commit

Permalink
refactor torque measurement reset on violation
Browse files Browse the repository at this point in the history
  • Loading branch information
ntegan1 committed Aug 27, 2022
1 parent a34bddc commit 1708551
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
10 changes: 7 additions & 3 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ void relay_malfunction_reset(void) {
fault_recovered(FAULT_RELAY_MALFUNCTION);
}

void torque_measurements_reset(uint32_t ts) {
desired_torque_last = 0;
rt_torque_last = 0;
ts_last = ts;
}

typedef struct {
uint16_t id;
const safety_hooks *hooks;
Expand Down Expand Up @@ -511,9 +517,7 @@ bool steer_torque_cmd_checks(int desired_torque, int steer_req, const SteeringLi

// reset to 0 if either controls is not allowed or there's a violation
if (violation || !controls_allowed) {
desired_torque_last = 0;
rt_torque_last = 0;
ts_last = ts;
torque_measurements_reset(ts);
}

return violation;
Expand Down
4 changes: 1 addition & 3 deletions board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ static int gm_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {

// reset to 0 if either controls is not allowed or there's a violation
if (violation || !current_controls_allowed) {
desired_torque_last = 0;
rt_torque_last = 0;
ts_last = ts;
torque_measurements_reset(ts);
}

if (violation) {
Expand Down
1 change: 1 addition & 0 deletions board/safety_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ bool addr_safety_check(CANPacket_t *to_push,
void generic_rx_checks(bool stock_ecu_detected);
void relay_malfunction_set(void);
void relay_malfunction_reset(void);
void torque_measurements_reset(uint32_t);
bool steer_torque_cmd_checks(int desired_torque, int steer_req, const SteeringLimits limits);
void pcm_cruise_check(bool cruise_engaged);

Expand Down

0 comments on commit 1708551

Please sign in to comment.