Commit Graph

171 Commits

Author SHA1 Message Date
Jason Wen 1d874be2b7
Safety: unify `controls_allowed` with boolean (#1589) 2023-08-18 13:22:04 -07:00
Justin Newberry f4e63e7da5
Safety: Rename alt transmission rpm (#1583)
* renamre transmision rpm

* consistent whitespace

* rename declarations too
2023-08-15 17:25:44 -07:00
Justin Newberry 05295dc42a
Safety: alternate longitudinal limits (#1577)
alt limits
2023-08-12 19:34:53 -07:00
Shane Smiskol 3c9d277276
safety: always allow inactive gas command (#1418)
* always allow inactive gas

* rewrite this

* revert

* no functional change but test it correctly

* also here
2023-05-17 15:52:50 -07:00
Justin Newberry 0a738b7ee8
Subaru: rename legacy to preglobal (#1415)
* rename

* missing some variables

* fix find/replace error
2023-05-15 17:22:40 -07:00
Shane Smiskol 35609dfdce
safety utils: add ROUND helper (#1397)
* add round macro

* Update board/utils.h

* function

* one line

* misra

* use here too
2023-05-06 21:25:25 -07:00
Shane Smiskol cedb5fd1a6
Ford: remove safety mode from debug flag (#1400)
remove from debug
2023-05-04 06:08:10 +00:00
Shane Smiskol 94cd9a0788
Ford: curvature rate limits (#1258)
* ford curvature rate limits draft

* make common angle tests work with curvature

* comment

* no need for this

* extra line

* fix test

* generic curvature test class

* more reasonable limits

* adjust limits

* draft

* works

* works

* clean up

* add vehicle speed

* works

* clean up

* clean up

* more clean up

* more clean up

* lower

* double

* add updated bp

* remove

* can clean that up

* draft

* this works!

* think that's the correct placement

* try this

* closer

* use min

* add/sub one to not falsely trip

* remove old angle error safety

* i'm not sure if clamp is more readable

* fix that

* fix

* stash

* fix these tests

* ternary

* floats are a pain

* draft, works kinda

* even better

* round that

* need tolerance

* this should work (adding tol=1 wouldn't let us have multiple rate limits)

* test works

* clamp breaks if low is higher than high :(((

down from 150 blocked msgs to 7!

* no blocked msgs!!!

* test a whole bunch

* stash

* stash

* clean up test

* clean up test to be more like torque (+ speeds)

* clean up

* cmt

* test up

* up and down are good

* rename and remove

* this is tested

* uncomment

* this is tested by ensuring we move towards error at a minimum rate

* not used any more

* revert common

* clean up test_ford a bit more

* some clean up (combine variables where it makes sense)

* yeah can't use clamp since min isn't always < max, min(max(.. handles this

* clean up

* revert that

* comments

* cmt

* another

* that's old

* misra!

* Update board/safety/safety_ford.h

* Update board/safety/safety_ford.h

* add todo, fix test case

* more clear, matches panda

* add comment

* Update tests/safety/test_ford.py

* more fine speed increments

* rm comment

* better names

* this is expected behavior (tested by common checks)

* CURVATURE_ERROR_LIMIT_SPEED

* better name?

* pretty clean!

* same for up

* only used in one place now

* these are now clear

* common term

* make vehicle_speed a sample_t

* need to use values[0]

* speed is a float

* Revert "speed is a float"

This reverts commit 01af02f1d3.

* Revert "need to use values[0]"

This reverts commit 8f6d68345a.

* Revert "make vehicle_speed a sample_t"

This reverts commit ecd8dc86b6.

* safety fixes for new speed sample

* test fixes for new speed sample

* fix misra and make intermediate variable

* this isn't needed
2023-05-04 04:59:35 +00:00
Shane Smiskol 3a64b6ccb5
safety: make vehicle_speed a sample (#1391)
* convert vehicle_speed into sample_t, change no behavior

* draft

* round

* test

* clean up

* round

* round all

* use min

* remove round macro from this PR

* reset speed measurement

* debug

* bbd

* rm

* revert

* test above and below

* need this now

* misra pt 1

* misra pt 2

* misra pt 3

* i don't understand this one, not different from other cases

* fix test

* test

* revert that

* draft

* test the sample_t works properly for safety modes that use it (angle only)

* can combine these tests

* test decimals

* global

* misra

comment

* suggestions

* fix

* use new helper
2023-05-04 03:37:56 +00:00
Shane Smiskol aa30b15de5
Ford safety: more clear variable names (#1392)
* that's a better name

* that too
2023-05-03 03:45:33 +00:00
Shane Smiskol 69ad3dd8e8
angle safety: add comment about rate limits at 0 (#1389)
* up when 0

* Revert "up when 0"

This reverts commit fc9b459651.

* add comment

* whoops
2023-05-03 00:07:23 +00:00
Shane Smiskol dbe941004a
safety: reset torque_meas on init properly (#1250)
* reset min torque meas too

* add test that fails

* cmt

* cmt

* clean up test

* don't be random

* above test tests this pretty much

* test angle too

* fix

* also test driver torque

* whoops

* whoops
2023-04-28 17:45:02 -07:00
Shane Smiskol 4160d8d71c
safety: common angle safety function (#1369)
* draft clean up

* always check

* add angle to name

* ford sends curvature when not steering and bit is 0.

it's not torque, curvature of 0 will still apply torque

* need this to be generic

* formatting

* rm

* test that we can send curvature=0 if enabled=False while control_allowed=True (let's say EPS faults, OP doesn't want to actuate)

* revert ford tests to master

* this <i>should</i> preserve behavior

* this is fine to remove

* and this should also be covered

* yeet

* change opt name, combine checks, much better!

* one more

* modes

* Add comment

* misra has a bug :(

* ugh

* make this clear

* ?

* order

* fix

* comments
2023-04-27 23:33:54 -07:00
Shane Smiskol 69a0b6ed34
safety: use max_limit_check helper in angle safety (#1373)
* better

* ?

* ?

* Revert "?"

This reverts commit ae70c7ff3b.

* Revert "?"

This reverts commit db7fd644a9.
2023-04-27 23:19:26 -07:00
Shane Smiskol aac46a2ef2
angle safety: enforce disabled angle when not steering (#1372)
* enforce disabled angle when bit not set, below we enforce bit to be 0 when not controls allowed

* test

* other test

* combine tests

* comment
2023-04-27 21:41:38 -07:00
Shane Smiskol c9c3cb38f6
Ford safety: curvature error limit (#1353)
* set ford vehicle speed

* parse yaw rate signals

* misra

* misra

* misra

* misra

* draft

* update module

* already checked

* and set it properly

* some stuff

* draft

* clean up (will fail tests because we don't send yaw rate yet)

* could do something like this

* this is better and less prone to bugs

* match simple op limiting, debugging

* set checksum for messages in tests

* clean up

* fix that

* one m/s fudge

* fix sign of yaw rate

* interpolate detects size

* forgot OP flips the curvature sign. it matches yaw on can

* all my debugging crap

* make replay work for ford

* fix panda blocking messages (array is fixed size so size-1 is 0 rate at high speed)

* uncomment safety test limits

* revert

* round for zero blocked msgs

* fix limits

* meas safety checks that down rate is >=, not <

* test pass

* lots of comments and draft what one meas torque check would look like

* fix that

* add curvature meas

* add debugging stuff

* Revert "add debugging stuff"

This reverts commit 449783fc62.

* messy but at least one test passes now

* draft

* add max_steer

* some safety clean up

* and that

* start with a test that works

* another test that works (sort of, we need more strict panda safety without false positives)

* no max curvature check (not safety related), allow any rate limits

* add new function

* also need to consider max val here, since OP will send up to that

* and now use the function

* lower to 10

* compilation fixes

* clean up (no rate limiting)

* remove that too

* curvature diff test

* more clean up

* debug

* ?

* better names

* more official

* use _curvature_meas_msg_array here

* bit faster

* no i don't

* revert that

* why not just use angle_meas?

* bb ll

* bb deb

* clean up debug vals

* more

* revert replay drive debugging changes

* Update board/safety.h

* rm line

* only need to round the final thing

* not needed, under 10 ms

* make a class variable

* fix a misra?

* another misra?

better

* ?

* 12.1

* need to explicitly convert

* add one to not false trigger the violation (float rounding)

* not really needed

* rm line

* cmt

* use clamp

* rename

* in struct

* comment

* use max_limit_check

* draft clean up

* Revert "draft clean up"

This reverts commit d1a0e8acd1.

* make a global

make a global

* this is fine
2023-04-27 00:40:29 -07:00
Shane Smiskol 4269b74a84
safety: use max_limit_check (#1368)
use max_limit_check
2023-04-26 23:55:04 -07:00
Shane Smiskol 048ddeea4a
safety: make addr index getter more explicit (#1361)
make this explicit
2023-04-26 21:15:55 -07:00
Shane Smiskol f3d6d613c0
safety: don't check out of bounds array item (#1360)
* safety: don't check out of bounds array item

* better name

* cleanup

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2023-04-26 19:43:30 -07:00
Jason Young fddca54fd6
VW: Allow inactive accel values at all times (#1247)
* allow inactive accel values at all times

* cleaner

* unnecessary, done by default

* better comments

* move test to common class

* fix

* flip

* comment

* append 0 and INACTIVE_ACCEL to test accels + check acc_07 sends if inactive only

* cleanup

* fix that

* copy testing convention of VW and Honda

---------

Co-authored-by: Shane Smiskol <shane@smiskol.com>
2023-04-13 17:28:33 -07:00
Adeeb Shihadeh 85cc70d4aa
safety: only pass addr to fwd hook (#1339) 2023-04-08 16:45:59 -07:00
Shane Smiskol f7ba061279
Ford: test quality flags (#1266)
* adeeb

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>

* check checksum

* think pylint won't like this

* complete test

* do this

* no need

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2023-03-01 19:17:40 -08:00
Shane Smiskol 8bb62cf226
Ford: check quality flag (#1264)
* quality flag support

* add NULL to other safety modes

* add to safety helpers debug print

* comment

* rename to quality_flag and add comment
2023-02-24 22:54:51 -08:00
Shane Smiskol ff39bc472d
Angle control safety: match openpilot limits (#1254)
* make limits match OP

* make tesla match too

* fudge speed

* we reason

* needs to be negative
2023-02-22 20:05:33 -08:00
Shane Smiskol a6d0765b69
safety: common angle checks (#1182)
* common angle checks

* clean up

* clean up check and add comments

* readable

* ints

* tests draft

* clean up

* comment

* pylint exception

* clean up

* duplicate
2022-12-02 16:45:23 -08:00
Shane Smiskol b238d41979
safety: clean up passing in longitudinal_allowed (#1176)
* clean up

* clean up

* and fix that

* interceptor func

* fix

* draft

* fix that
2022-11-30 22:09:13 -08:00
Shane Smiskol a0b1d64e4e
Honda Nidec: max gas safety and common speed cmd checks (#1179)
* limit gas and speed

* gas safety test
2022-11-30 18:56:05 -08:00
Shane Smiskol cb8fc6bd42
safety: common interceptor checks (#1178)
* interceptor checks

* only one line needed for now

* whoops

* misra

* misread as |
2022-11-30 17:22:42 -08:00
Shane Smiskol e8bd1df511
safety: common gas & brake safety checks (#1168)
* do toyota, hyundai, gm

* comments

* honda draft

* Revert "honda draft"

This reverts commit a1f466a5c9.

* do tesla

* vw draft

* finish vw

* fix safety

* clean up

* fix function names

* do honda and fix safety test not checking pos accel for bosch

* clean that up
2022-11-29 23:45:55 -08:00
Shane Smiskol 2baa0ffed5
Safety: common acceleration cmd checks (#1171)
* do toyota, hyundai, gm

* comments

* honda draft

* Revert "honda draft"

This reverts commit a1f466a5c9.

* do tesla

* vw draft

* finish vw

* fix safety

* only accel

* only accel

* some clean up

* fix mqb tests

* rename
2022-11-29 16:46:32 -08:00
Adeeb Shihadeh 80dac4cd94
cleanup CAN definitions (#1170) 2022-11-29 15:56:43 -08:00
Shane Smiskol 0a819ad465
Torque request bit: support multiple invalid frames (#1094)
* h90d safety

* quicker rate

* update comment

* support multi frames?

* stash

* stash

* might work?

* stash

* clean up

* revert that

* add test

* fixup tests

* clean up

* remove test

* try to combine tests

* Revert "try to combine tests"

This reverts commit f147955b94.

* seems simpler

* more explicit

* shouldn't be needed

* no hyundai stuff

* no line

* consecutively

* comment

* comment

* comment

* revert

* comment

* check earlier

check earlier

* ensure we don't set a negative value

* add todo comments

* for loop
2022-10-11 13:20:24 -07:00
Adeeb Shihadeh e987e6c639
add pandaState.safetyRxChecksInvalid field (#1083)
* add fault for invalid safety RX checks

* fix test build

* debug

* fix debug

* fix test

* just a bool in health
2022-10-03 16:05:16 -07:00
Shane Smiskol 788e0b5ac9
GM: same regen check as openpilot (#1026)
* it was only checking a specific bit

* same check as openpilot

* reset on init

* unsigned

* should fix conflicts

* common

* comment

* Add missing function

* Tests

* the alternative is a mess

typo

typo

* draft

* finish common

* works but you need RegenSafetyTest before all other classes

* Revert "works but you need RegenSafetyTest before all other classes"

This reverts commit 256f3be9a8.

* This works too

* need parameterized, subtests nor super() calls correctly reset state

* Fix test and comment

* comment

* another fix...

* subclass

* ABC

* order

* fix static analysis

* can do this

* Revert "can do this"

This reverts commit 6bc63a345a.

* this is nicer, no pylint errors

* Update tests/safety/common.py

* underscore

* dynamically detect and add tests

* simpler

* only for safety modes with a regen message

* check attr

* Revert "check attr"

This reverts commit bc37a7eedd.

* need to check at test time not class init time
2022-09-12 21:32:06 -07:00
Shane Smiskol 0ca23b6778
Toyota: generic steer fault workaround safety (#939)
* toyota steer fault safety

* fix

* alternative safety

* no comment

* should be good

* same behavior, a bit simpler

* better tests

* fix comment

* update safety comment

* const is actual number of messages

* Fix bug

* misra

* Fix test

* clean up logic a bit

clean up logic a bit

fix

* fix

fix

* clean up tests

* unsigned

* forgot to rename message when merged

* Comments

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>

* Update names

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>

* rename rest of variables

* real time checks

* clean up safety tests

* revert

* add this

* clean up

* better name

* use common steering checks

* reverse order

* make common

* re-organize the safety

* clean up safety_toyota

* more clean up

* add comment back

* 19

* recover

* some variable name clean up

* rename and reset `valid_steering_msg_count`, another recover message

* move comment

* remove reset_toyota_timer, minor test clean up

* common test

* use init_tests

* threshold used to be: frame you can cut steer on, now it's min num of valid frames (next frame you can cut, 18+1)

* Update tests/safety/test_toyota.py

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>

* fix realtime

* Update board/safety/safety_toyota.h

* Apply suggestions from code review

* Update board/safety/safety_toyota.h

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2022-09-06 19:12:06 -07:00
Shane Smiskol acff2c8ec8
safety: common cruise checks (#1025)
* add function for common controls allowed setter (PCM cruise)

* Use new function when possible

fix

* consistent variable types
2022-08-12 00:28:08 -07:00
Adeeb Shihadeh 06592b5c0e
Hyundai: rename HDA2 platform to CANFD (#1027)
* Hyundai: rename HDA2 platform to CANFD

* one more
2022-08-11 22:06:54 -07:00
Adeeb Shihadeh 3598e8105b
safety: abstract motor torque limit checks (#1018)
* abstract out motor torque steering safety

* safety: abstract motor torque limit checks

* fix comment
2022-08-09 21:05:36 -07:00
Adeeb Shihadeh 291d9e3eb9
safety: refactor steering safety checks (#1013)
* start with vw

* hyundai

* rest of driver torque cars

* remove hyundai for now

* fix cppcheck crash

* set committer

* revert gm

* remove those
2022-08-09 19:53:15 -07:00
Adeeb Shihadeh f02b43191f
Subaru: split legacy safety into its own file (#990) 2022-07-19 15:53:08 -07:00
Adeeb Shihadeh e51aa5ebce
safety: fix race condition in engagement heartbeat (#988)
* safety: fix race condition in engagement heartbeat

* move that

* fix  that
2022-07-13 14:20:00 -07:00
Adeeb Shihadeh 2652453892
EV6: adjust steering thresholds (#972)
* EV6: match max torque of rest of Hyundais

* update tests

* adjust that

* Apply suggestions from code review

* Update test_hyundai_hda2.py
2022-06-23 13:41:22 -07:00
Adeeb Shihadeh 62f709afd4 fix missing CAN-FD safety modes 2022-05-19 16:55:53 -07:00
Willem Melching 36c62afa0c
Kia EV6 (#905)
* block lkas

* taco time

* local changes

* start

* tx checks

* counter + vehicle moving

* support big can fd

* check crc

* add torque to rx checks

* tests

* little more

* little more

* get some misra coverage

Co-authored-by: Comma Device <device@comma.ai>
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2022-05-19 15:59:58 -07:00
Adeeb Shihadeh 4a5fc24b75
safety: move controls_allowed and relay malfunction reset (#944)
* safety: reset controls allowed and relay malfunction before safety mode init

* add back for all output
2022-05-19 14:03:43 -07:00
Adeeb Shihadeh 69215887dc
safety: prep for CAN FD (#943) 2022-05-15 23:46:04 -07:00
Shane Smiskol eb662e4e50
Make safety param uint16_t (#931)
* change safety param to uint16_t

* accidental paste
2022-05-02 13:36:19 -07:00
Shane Smiskol ee2a4b6b58
sample_t: fixup comments (#921) 2022-04-21 20:11:13 -07:00
Shane Smiskol 7dd9493eb1
safety_param: change to unsigned (#910)
* make safety_param unsigned

* final one

* uint32_t

* change flags as well

* Revert "change flags as well"

This reverts commit ed8897dd86.

* unsigned

* update health packet version

update health packet version

* update struct H->I

* bump health version

* actually used
2022-04-20 23:25:03 -07:00
Robbe Derks cc0fdffee6
Calculate interrupt load and add to health packet (#913)
* calculate interrupt load

* forgot to change this

* being cautious about overflows

* utils

* fix bootstub

* cleanup

* also exclude pedal

* fix misra

Co-authored-by: Comma Device <device@comma.ai>
2022-04-11 11:59:47 +02:00