Skip to content

Commit

Permalink
Safety: alternate longitudinal limits (commaai#1577)
Browse files Browse the repository at this point in the history
alt limits
  • Loading branch information
jnewb1 authored Aug 13, 2023
1 parent a0344a1 commit 05295dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,12 @@ bool longitudinal_speed_checks(int desired_speed, const LongitudinalLimits limit
return !get_longitudinal_allowed() && (desired_speed != limits.inactive_speed);
}

bool longitudinal_alt_checks(int desired_alt, const LongitudinalLimits limits){
bool alt_valid = get_longitudinal_allowed() && !max_limit_check(desired_alt, limits.max_alt, limits.min_alt);
bool alt_inactive = desired_alt == limits.inactive_alt;
return !(alt_valid || alt_inactive);
}

bool longitudinal_gas_checks(int desired_gas, const LongitudinalLimits limits) {
bool gas_valid = get_longitudinal_allowed() && !max_limit_check(desired_gas, limits.max_gas, limits.min_gas);
bool gas_inactive = desired_gas == limits.inactive_gas;
Expand Down
6 changes: 6 additions & 0 deletions board/safety_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ typedef struct {
const int inactive_gas;
const int max_brake;

// alternative cmd limits, ex: transmission rpm on subaru
const int max_alt;
const int min_alt;
const int inactive_alt;

// speed cmd limits
const int inactive_speed;
} LongitudinalLimits;
Expand Down Expand Up @@ -163,6 +168,7 @@ bool steer_angle_cmd_checks(int desired_angle, bool steer_control_enabled, const
bool longitudinal_accel_checks(int desired_accel, const LongitudinalLimits limits);
bool longitudinal_speed_checks(int desired_speed, const LongitudinalLimits limits);
bool longitudinal_gas_checks(int desired_gas, const LongitudinalLimits limits);
bool longitudinal_alt_checks(int desired_alt, const LongitudinalLimits limits);
bool longitudinal_brake_checks(int desired_brake, const LongitudinalLimits limits);
bool longitudinal_interceptor_checks(CANPacket_t *to_send);
void pcm_cruise_check(bool cruise_engaged);
Expand Down

0 comments on commit 05295dc

Please sign in to comment.