Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor torque measurement reset on violation #1046

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ts);
bool steer_torque_cmd_checks(int desired_torque, int steer_req, const SteeringLimits limits);
void pcm_cruise_check(bool cruise_engaged);

Expand Down