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

safety: add longitudinal pre-enable state for brake at a standstill #1123

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
95a5148
disallow longitudinal at a stop with brake held
sshane Oct 28, 2022
8563b63
comment
sshane Oct 28, 2022
b4b89dc
Merge remote-tracking branch 'upstream/master' into brake-preenable
sshane Nov 29, 2022
f66a28f
stash what we got so far
sshane Nov 29, 2022
a905664
so far
sshane Nov 29, 2022
c1df489
Merge remote-tracking branch 'upstream/master' into brake-preenable
sshane Nov 30, 2022
85235a7
stash
sshane Dec 1, 2022
1bc58d6
Merge remote-tracking branch 'upstream/master' into brake-preenable
sshane Dec 1, 2022
a0d1286
clean up
sshane Dec 1, 2022
5daf884
Merge remote-tracking branch 'upstream/master' into brake-preenable
sshane Dec 3, 2022
fc5c43f
lateral allowed
sshane Dec 3, 2022
7824cb0
Merge remote-tracking branch 'upstream/master' into brake-preenable
sshane Dec 15, 2022
7afb897
Merge remote-tracking branch 'upstream/master' into brake-preenable
sshane Oct 4, 2023
42c0c27
don't change lat
sshane Oct 4, 2023
e689d51
rename
sshane Oct 4, 2023
97f403c
this should work
sshane Oct 4, 2023
813750e
draft
sshane Oct 4, 2023
3c22fdb
need to do this for tesla to know where 0 accel point is
sshane Oct 4, 2023
8065c64
this is cleaner
sshane Oct 4, 2023
65aa62b
oh wait it does
sshane Oct 4, 2023
b5eaf9f
use _generic_limit_safety_check in ford
sshane Oct 4, 2023
a880f46
tests
sshane Oct 4, 2023
2e0e7a9
Revert "use _generic_limit_safety_check in ford"
sshane Oct 4, 2023
4fe2baa
all good
sshane Oct 4, 2023
60d5052
ford
sshane Oct 4, 2023
4c59318
messy
sshane Oct 4, 2023
c48473d
clean up
sshane Oct 4, 2023
40dcb1b
Merge remote-tracking branch 'upstream/master' into brake-preenable
sshane Nov 11, 2023
1c1c6c1
cando this, but this seems more confusing now
sshane Nov 11, 2023
423fe3e
or...
sshane Nov 11, 2023
55681c1
better
sshane Nov 11, 2023
57122bb
comments
sshane Nov 11, 2023
024663a
winning
sshane Nov 11, 2023
26a45ca
remove get_decel_allowed
sshane Nov 11, 2023
7ce2100
space up here
sshane Nov 11, 2023
2965bca
overkill
sshane Nov 11, 2023
31955d8
tests
sshane Nov 11, 2023
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
Prev Previous commit
Next Next commit
this is cleaner
  • Loading branch information
sshane committed Oct 4, 2023
commit 8065c6460f461f7c16e575abfadb935dc058513f
4 changes: 2 additions & 2 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ int ROUND(float val) {

// Safety checks for longitudinal actuation
bool longitudinal_accel_checks(int desired_accel, const LongitudinalLimits limits) {
bool accel_valid = get_accel_allowed() && !max_limit_check(desired_accel, limits.max_accel, 0);
bool decel_valid = get_decel_allowed() && !max_limit_check(desired_accel, 0, limits.min_accel);
bool accel_valid = get_accel_allowed() && !max_limit_check(desired_accel, limits.max_accel, limits.zero_accel);
bool decel_valid = get_decel_allowed() && !max_limit_check(desired_accel, limits.zero_accel, limits.min_accel);
bool accel_inactive = desired_accel == limits.inactive_accel;
print("here: "); puth(accel_valid); print(" "); puth(accel_valid); print(" "); puth(decel_valid); print(" "); puth(accel_inactive); print("\n");
return !(accel_valid || decel_valid || accel_inactive);
Expand Down
1 change: 1 addition & 0 deletions board/safety/safety_ford.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const LongitudinalLimits FORD_LONG_LIMITS = {
.max_accel = 5641, // 1.9999 m/s^s
.min_accel = 4231, // -3.4991 m/s^2
.inactive_accel = 5128, // -0.0008 m/s^2
// TODO: why do tests pass without zero_accel set

// gas cmd limits
// Signal: AccPrpl_A_Rq
Expand Down
12 changes: 6 additions & 6 deletions board/safety/safety_tesla.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const SteeringLimits TESLA_STEERING_LIMITS = {
},
};


const LongitudinalLimits TESLA_LONG_LIMITS = {
.max_accel = 425 - 375, // 2. m/s^2
.min_accel = 287 - 375, // -3.52 m/s^2 // TODO: limit to -3.48
.inactive_accel = 375 - 375, // 0. m/s^2 (15 / .04)
.max_accel = 425, // 2. m/s^2
.min_accel = 287, // -3.52 m/s^2 // TODO: limit to -3.48
.inactive_accel = 375, // 0. m/s^2
.zero_accel = 375,
};


Expand Down Expand Up @@ -178,8 +178,8 @@ static int tesla_tx_hook(CANPacket_t *to_send) {
}

// Don't allow any acceleration limits above the safety limits
int raw_accel_max = (((GET_BYTE(to_send, 6) & 0x1FU) << 4) | (GET_BYTE(to_send, 5) >> 4)) - 375;
int raw_accel_min = (((GET_BYTE(to_send, 5) & 0x0FU) << 5) | (GET_BYTE(to_send, 4) >> 3)) - 375;
int raw_accel_max = ((GET_BYTE(to_send, 6) & 0x1FU) << 4) | (GET_BYTE(to_send, 5) >> 4);
int raw_accel_min = ((GET_BYTE(to_send, 5) & 0x0FU) << 5) | (GET_BYTE(to_send, 4) >> 3);
violation |= longitudinal_accel_checks(raw_accel_max, TESLA_LONG_LIMITS);
violation |= longitudinal_accel_checks(raw_accel_min, TESLA_LONG_LIMITS);
} else {
Expand Down
1 change: 1 addition & 0 deletions board/safety_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef struct {
const int max_accel;
const int min_accel;
const int inactive_accel;
const int zero_accel;

// gas & brake cmd limits
// inactive and min gas are 0 on most safety modes
Expand Down
Loading