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

Modular Assistive Driving System (MADS) #57

Merged
merged 166 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
166 commits
Select commit Hold shift + click to select a range
267bd1d
improvements on the state machine for exiting controls and improvemen…
devtekve Dec 6, 2024
cbfe42b
New tests on hyundai for now to see how they behave with lkas and ma…
devtekve Dec 6, 2024
bc07cb4
cleaning up hyundai tests and ensuring we always cleanup mads states …
devtekve Dec 6, 2024
ef8a0af
Adjusting tests
devtekve Dec 6, 2024
2e41345
Adjusting the tests a bit more to ensure clean states
devtekve Dec 6, 2024
35c3b85
Cleaning up and simplifying logic
devtekve Dec 6, 2024
7a8ab71
ensuring all tests always cleanup
devtekve Dec 6, 2024
0cc9c8e
improving the state
devtekve Dec 6, 2024
1ba0198
make static happy
devtekve Dec 6, 2024
ada269d
Merge branch 'master-new' into mads-new-improvement-v1
sunnyhaibin Dec 7, 2024
be5e6ab
Refactor safety replay script for better debugging and update Honda s…
devtekve Dec 7, 2024
2bcdf59
Introduce 'ACC_MAIN_OFF' as a new disengagement reason in Sunnypilot'…
devtekve Dec 7, 2024
c4224bc
simpler logic cleaner
devtekve Dec 7, 2024
cbf2705
reorder code for readability
devtekve Dec 7, 2024
1283efb
tmp
devtekve Dec 7, 2024
fbb1828
Refactor state transitions and add event handlers
devtekve Dec 7, 2024
d82f423
reorder
devtekve Dec 7, 2024
2d3a9be
Refactor MADS state handling logic
devtekve Dec 7, 2024
31eaa77
adding some more tests
devtekve Dec 7, 2024
00a9515
split init
sunnyhaibin Dec 7, 2024
8830a45
format
sunnyhaibin Dec 7, 2024
bc5df99
update naming
sunnyhaibin Dec 8, 2024
5171ef0
Refine lateral control request logic in safety_mads.h
devtekve Dec 8, 2024
074b726
Fix button state handling in mads_exit_controls logic.
devtekve Dec 8, 2024
8e5cfe4
Add test for LKAS button press with ACC main on
devtekve Dec 8, 2024
ff6e7a4
Add mismatch detection and change mads_acc_main to bool
devtekve Dec 8, 2024
fa44daf
update controls_allowed_lat_pkt on health pkt to actually follow is_l…
devtekve Dec 8, 2024
929d00c
Can't perform this test on toyota as we never really process a button…
devtekve Dec 8, 2024
fcfe87c
wow, we forgot about pcm hyundai can-fd
sunnyhaibin Dec 8, 2024
9bf0de6
nuke nuke nuke
devtekve Dec 8, 2024
e94cd17
Revert "nuke nuke nuke"
sunnyhaibin Dec 8, 2024
a35a930
update name
sunnyhaibin Dec 8, 2024
6d24480
event driven update states
sunnyhaibin Dec 9, 2024
3a1a4e8
add get_pcm_main_cruise_available
sunnyhaibin Dec 9, 2024
a232fca
split PCM and non-PCM main cruise tets
sunnyhaibin Dec 9, 2024
36cf90b
fix some
sunnyhaibin Dec 9, 2024
cfc8258
pcm main cruise availability mutation
sunnyhaibin Dec 9, 2024
e4fca0c
toyota pass fake lkas btn pressed
sunnyhaibin Dec 9, 2024
55fdf2b
more
sunnyhaibin Dec 9, 2024
c28aa9b
make pcm acc main rising edge on init
sunnyhaibin Dec 9, 2024
1fd1a48
only falling edge when actually 0 (need test for mutation)
sunnyhaibin Dec 9, 2024
1340dcb
misra
sunnyhaibin Dec 9, 2024
3995c21
remove state flags, main button related
sunnyhaibin Dec 9, 2024
e394d28
skip lkas related tests with toyota and subaru fake button
sunnyhaibin Dec 9, 2024
bc30f69
need for honda
sunnyhaibin Dec 9, 2024
e4db8c7
static
sunnyhaibin Dec 9, 2024
11acf0c
mutation
sunnyhaibin Dec 9, 2024
13a0b37
misra
sunnyhaibin Dec 9, 2024
95c157f
skip nidec pcm alt
sunnyhaibin Dec 9, 2024
19bd7c1
engage mads if controls allowed rising
sunnyhaibin Dec 9, 2024
162c290
static
sunnyhaibin Dec 9, 2024
419d84d
remove non pcm properties
sunnyhaibin Dec 9, 2024
76471c6
fixup! engage mads if controls allowed rising
sunnyhaibin Dec 9, 2024
61d5477
move back
sunnyhaibin Dec 9, 2024
fa1ba8c
fix static
sunnyhaibin Dec 9, 2024
3f39f8f
move around
sunnyhaibin Dec 9, 2024
e3b426a
Hyundai openpilot longitudinal main cruise button state handling
sunnyhaibin Dec 9, 2024
4b09b1b
main button unit test
sunnyhaibin Dec 9, 2024
b55a085
acc_main_on mismatch unit tests
sunnyhaibin Dec 9, 2024
6260954
clean up old main cruise button unit tests
sunnyhaibin Dec 9, 2024
2ccbaee
add more reasons
sunnyhaibin Dec 9, 2024
8cfdfd5
cleanup
sunnyhaibin Dec 9, 2024
1481362
rename
sunnyhaibin Dec 9, 2024
f07caaa
rearrange
sunnyhaibin Dec 9, 2024
6b385d0
Revert "rearrange"
sunnyhaibin Dec 9, 2024
52487d8
more rearrange
sunnyhaibin Dec 9, 2024
65d2435
rename
sunnyhaibin Dec 9, 2024
def81f1
Merge branch 'master-new' into mads-new-diff-2
sunnyhaibin Dec 9, 2024
572833b
more
sunnyhaibin Dec 9, 2024
31a249a
too slow
sunnyhaibin Dec 10, 2024
ffa6082
Revert "too slow"
sunnyhaibin Dec 10, 2024
482551d
too slow v2
sunnyhaibin Dec 10, 2024
002ac58
cleanup
sunnyhaibin Dec 10, 2024
b3913db
rename
sunnyhaibin Dec 10, 2024
3e6c41d
more cleanup
sunnyhaibin Dec 10, 2024
5ab437f
Parse more flags from alt exp, more tests, hyundai main cruise allowed
sunnyhaibin Dec 10, 2024
11bb231
missed
sunnyhaibin Dec 10, 2024
6f1aadf
mutation for controls allowed rising edge
sunnyhaibin Dec 10, 2024
5c028b3
ford mutation
sunnyhaibin Dec 10, 2024
0da2247
Update tests/safety/test.sh
sunnyhaibin Dec 10, 2024
116e12b
license
sunnyhaibin Dec 10, 2024
0a2e576
unused
sunnyhaibin Dec 10, 2024
e1a0318
remove
sunnyhaibin Dec 10, 2024
7b2d666
comment
sunnyhaibin Dec 10, 2024
659ecd5
Apply suggestions from code review
sunnyhaibin Dec 10, 2024
d93b6eb
Merge remote-tracking branch 'sunnypilot/panda/mads-new-diff-2' into …
sunnyhaibin Dec 10, 2024
9e9b9da
comment
sunnyhaibin Dec 10, 2024
5347396
refactor alternative experience handling with helper function
sunnyhaibin Dec 10, 2024
bb2b686
use always allowed mads button alt exp
sunnyhaibin Dec 11, 2024
d148694
rename
sunnyhaibin Dec 11, 2024
311b9fa
parenthesis
sunnyhaibin Dec 11, 2024
52f7898
use alternative experience for unit tests inits
sunnyhaibin Dec 11, 2024
935dc8a
cleanup
sunnyhaibin Dec 11, 2024
93d1f19
rename
sunnyhaibin Dec 11, 2024
67ef224
mutation tests for alternative experience flags
sunnyhaibin Dec 11, 2024
02320b4
bump timer
sunnyhaibin Dec 11, 2024
210f1f5
test for disengage and no disengage lateral on brake
sunnyhaibin Dec 11, 2024
ff17a58
test allow MADS engage with brake pressed
sunnyhaibin Dec 11, 2024
a86e4ee
rename
sunnyhaibin Dec 11, 2024
bd9e789
move around
sunnyhaibin Dec 11, 2024
bdeb1c2
button combo test
sunnyhaibin Dec 11, 2024
346964f
use acc_main_on directly from global
sunnyhaibin Dec 11, 2024
6ab43d4
fix caught failures from last commit's fix
sunnyhaibin Dec 11, 2024
e7ab56b
Revert "use acc_main_on directly from global"
devtekve Dec 11, 2024
b6f13b5
Properly fix lmao
devtekve Dec 11, 2024
999b6e4
Add support for LKAS button handling across Chrysler platforms
devtekve Dec 11, 2024
5bd37e1
Dockerfile: point to sunnypilot/opendbc
sunnyhaibin Dec 11, 2024
f6cbb6c
Merge remote-tracking branch 'origin/sunnypilot-ref' into mads-new-di…
devtekve Dec 11, 2024
7ea27b5
Happy days :)
devtekve Dec 11, 2024
3d6c5f3
Merge remote-tracking branch 'origin/sunnypilot-ref' into mads-new-di…
devtekve Dec 11, 2024
a9b580d
clean
devtekve Dec 11, 2024
ab4b767
testx
devtekve Dec 11, 2024
6cf78ec
Revert "Happy days :)"
sunnyhaibin Dec 11, 2024
047d47f
symlink prior building
sunnyhaibin Dec 11, 2024
d97b371
Merge branch 'sunnypilot-ref' into mads-new-diff-2
devtekve Dec 11, 2024
526b032
Merge branch 'master-new' into mads-new-diff-2
sunnyhaibin Dec 11, 2024
54cfb7b
comment
sunnyhaibin Dec 12, 2024
987627b
only parse mads lateral, not stock op's lateral
sunnyhaibin Dec 12, 2024
a9f95a6
do not allow controls allowed if acc_main_on is off
sunnyhaibin Dec 12, 2024
ecef1d4
expose system_enabled, do not allow controls allowed to steer if syst…
sunnyhaibin Dec 12, 2024
d476d03
fix hyundai tests with acc_main_on requirement
sunnyhaibin Dec 12, 2024
47a7a18
fix test with new controls allowed with system_mads off
sunnyhaibin Dec 12, 2024
941c742
fix replay drive
devtekve Dec 12, 2024
a879b79
Change 'DISABLE_DISENGAGE_LATERAL_ON_BRAKE' to 'DISENGAGE_LATERAL_ON_…
devtekve Dec 12, 2024
78279ee
Adding some more debug printouts on replay drive
devtekve Dec 12, 2024
a870259
remove unified engagement mode in panda
sunnyhaibin Dec 12, 2024
9d09e92
treat MADS button as user entry
sunnyhaibin Dec 12, 2024
2c8bc9a
controls allow should be allowed at all times
sunnyhaibin Dec 12, 2024
390de3b
squash! treat MADS button as user entry
sunnyhaibin Dec 12, 2024
700cc3c
heartbeat for mads
sunnyhaibin Dec 12, 2024
ab66fea
heartbeat mismatch exit control
sunnyhaibin Dec 12, 2024
fbea545
remove always allow mads button from alt
sunnyhaibin Dec 12, 2024
aed626a
move to safety_mads
sunnyhaibin Dec 12, 2024
c1d78f9
check heartbeat directly in main
sunnyhaibin Dec 12, 2024
f4cb90d
remove main cruise allowed from alt
sunnyhaibin Dec 12, 2024
3760f38
uint
sunnyhaibin Dec 12, 2024
67cf5da
squash! check heartbeat directly in main
sunnyhaibin Dec 12, 2024
0cd9f85
update tests
sunnyhaibin Dec 12, 2024
b42d578
not needed
sunnyhaibin Dec 13, 2024
888df7e
fix mads_exit_controls sometimes not assigning disengage reason
sunnyhaibin Dec 13, 2024
6b84314
more disengage lateral on brake tests
sunnyhaibin Dec 13, 2024
77373ec
extern
sunnyhaibin Dec 13, 2024
955aaa2
missesd
sunnyhaibin Dec 13, 2024
f5f93bb
honda mutation test
sunnyhaibin Dec 13, 2024
acd546d
again
sunnyhaibin Dec 13, 2024
2c0bdbb
rename
sunnyhaibin Dec 13, 2024
8bd216c
more dlob test
sunnyhaibin Dec 13, 2024
1c1b9be
update name
sunnyhaibin Dec 13, 2024
41fd543
fix tests
sunnyhaibin Dec 13, 2024
b8c0d09
fix panda tests
sunnyhaibin Dec 13, 2024
c1f91c7
Refactor MADS state management to simplify pointer usage.
devtekve Dec 13, 2024
9897067
Simplify braking logic in m_mads_check_braking function
devtekve Dec 13, 2024
8cfb454
Prevent lateral control engagement during braking
devtekve Dec 13, 2024
a522ef5
Refactor MADS state handling and fix type consistency
devtekve Dec 13, 2024
a355672
Why MISRA, why!? WHY!???? I DIDNT EVEN TOUCH THIS FILE OR NOWHERE NEAR!
devtekve Dec 13, 2024
1d0eda0
Some format
devtekve Dec 13, 2024
6dab7bb
no more messing with misra
sunnyhaibin Dec 13, 2024
9a176ea
const
sunnyhaibin Dec 13, 2024
e9a6079
more generic names
sunnyhaibin Dec 13, 2024
2e117aa
revert to validate
sunnyhaibin Dec 14, 2024
5fcc10b
are you srs
sunnyhaibin Dec 14, 2024
958ddfe
make gpio.h stock again and add to supression lists the check on gpio…
devtekve Dec 14, 2024
af0a1b6
hard code to skip heartbeat check
sunnyhaibin Dec 15, 2024
3b8d42b
update comment
sunnyhaibin Dec 15, 2024
f837618
cleanup
sunnyhaibin Dec 15, 2024
d91653b
Update tests/safety/test_honda.py
sunnyhaibin Dec 15, 2024
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
2 changes: 1 addition & 1 deletion board/drivers/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void set_gpio_alternate(GPIO_TypeDef *GPIO, unsigned int pin, unsigned int mode)
void set_gpio_pullup(GPIO_TypeDef *GPIO, unsigned int pin, unsigned int mode) {
ENTER_CRITICAL();
uint32_t tmp = GPIO->PUPDR;
tmp &= ~((uint32_t)3U << ((uint32_t)(pin * 2U)));
tmp &= ~(3U << (pin * 2U));
tmp |= (mode << (pin * 2U));
register_set(&(GPIO->PUPDR), tmp, 0xFFFFFFFFU);
EXIT_CRITICAL();
Expand Down
36 changes: 21 additions & 15 deletions board/sunnypilot/safety_mads.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ ButtonState mads_button_press = MADS_BUTTON_UNAVAILABLE;
MADSState m_mads_state;

// state for mads controls_allowed_lat timeout logic
bool heartbeat_engaged_mads = false; // MADS enabled, passed in heartbeat USB command
uint32_t heartbeat_engaged_mads_mismatches = 0U; // count of mismatches between heartbeat_engaged_mads and controls_allowed_lat
bool heartbeat_engaged_mads = false; // MADS enabled, passed in heartbeat USB command
uint32_t heartbeat_engaged_mads_mismatches = 0U; // count of mismatches between heartbeat_engaged_mads and controls_allowed_lat

// ===============================
// State Update Helpers
Expand Down Expand Up @@ -100,8 +100,8 @@ static void m_update_binary_state(BinaryStateTracking *state) {
*
* @return void
*/
static void m_update_control_state(void) {
bool process_controls = true;
static bool m_update_control_state(void) {
bool allowed = true;

// Initial control requests from button or ACC transitions
if ((m_mads_state.acc_main.transition == MADS_EDGE_RISING) || (m_mads_state.mads_button.transition == MADS_EDGE_RISING)) {
Expand All @@ -111,28 +111,32 @@ static void m_update_control_state(void) {
// Primary control blockers - these prevent any further control processing
if (m_mads_state.acc_main.transition == MADS_EDGE_FALLING) {
mads_exit_controls(MADS_DISENGAGE_REASON_ACC_MAIN_OFF);
process_controls = false; // No matter what, no further control processing on this cycle
allowed = false; // No matter what, no further control processing on this cycle
}

// Secondary control conditions - only checked if primary conditions don't block further control processing
if (process_controls && m_mads_state.disengage_lateral_on_brake) {
if (allowed && m_mads_state.disengage_lateral_on_brake) {
// Brake rising edge immediately blocks controls
// Brake release might request controls if brake was the ONLY reason for disengagement
if (m_mads_state.braking.transition == MADS_EDGE_RISING) {
mads_exit_controls(MADS_DISENGAGE_REASON_BRAKE);
process_controls = false;
}
// Brake release might request controls if brake was the ONLY reason for disengagement
else if ((m_mads_state.braking.transition == MADS_EDGE_FALLING) && (m_mads_state.current_disengage.active_reason == MADS_DISENGAGE_REASON_BRAKE) && (m_mads_state.current_disengage.pending_reasons == MADS_DISENGAGE_REASON_BRAKE)) {
allowed = false;
} else if ((m_mads_state.braking.transition == MADS_EDGE_FALLING) &&
(m_mads_state.current_disengage.active_reason == MADS_DISENGAGE_REASON_BRAKE) &&
(m_mads_state.current_disengage.pending_reasons == MADS_DISENGAGE_REASON_BRAKE)) {
m_mads_state.controls_requested_lat = true;
} else if (m_mads_state.braking.current) {
process_controls = false;
allowed = false;
} else {
// Do nothing
}
}

return allowed;
}

static void m_publish_state(bool allowed) {
sunnyhaibin marked this conversation as resolved.
Show resolved Hide resolved
// Process control request if conditions allow
if (process_controls && m_mads_state.controls_requested_lat && !m_mads_state.controls_allowed_lat) {
if (allowed && m_mads_state.controls_requested_lat && !m_mads_state.controls_allowed_lat) {
m_mads_state.controls_requested_lat = false;
m_mads_state.controls_allowed_lat = true;
m_mads_state.current_disengage.active_reason = MADS_DISENGAGE_REASON_NONE;
Expand Down Expand Up @@ -174,8 +178,8 @@ inline void mads_exit_controls(const DisengageReason reason) {

if (m_mads_state.controls_allowed_lat) {
m_mads_state.current_disengage.active_reason = reason;
m_mads_state.controls_allowed_lat = false;
m_mads_state.controls_requested_lat = false;
m_mads_state.controls_allowed_lat = false;
}
}

Expand All @@ -195,5 +199,7 @@ inline void mads_state_update(const bool op_vehicle_moving, const bool op_acc_ma
m_update_binary_state(&m_mads_state.braking);
m_update_button_state(&m_mads_state.mads_button);

m_update_control_state();
const bool mads_allowed = m_update_control_state();

m_publish_state(mads_allowed);
sunnyhaibin marked this conversation as resolved.
Show resolved Hide resolved
}
16 changes: 8 additions & 8 deletions board/sunnypilot/safety_mads_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ typedef enum __attribute__((packed)) {
} EdgeTransition;

typedef enum __attribute__((packed)) {
MADS_DISENGAGE_REASON_NONE = 0, ///< No disengagement
MADS_DISENGAGE_REASON_BRAKE = 1, ///< Brake pedal pressed
MADS_DISENGAGE_REASON_LAG = 2, ///< System lag detected
MADS_DISENGAGE_REASON_BUTTON = 4, ///< User button press
MADS_DISENGAGE_REASON_ACC_MAIN_OFF = 8, ///< ACC system turned off
MADS_DISENGAGE_REASON_NON_PCM_ACC_MAIN_DESYNC = 16, ///< ACC sync error
MADS_DISENGAGE_REASON_HEARTBEAT_ENGAGED_MISMATCH = 32, ///< Heartbeat mismatch
MADS_DISENGAGE_REASON_NONE = 0, ///< No disengagement
MADS_DISENGAGE_REASON_BRAKE = 1, ///< Brake pedal pressed
MADS_DISENGAGE_REASON_LAG = 2, ///< System lag detected
MADS_DISENGAGE_REASON_BUTTON = 4, ///< User button press
MADS_DISENGAGE_REASON_ACC_MAIN_OFF = 8, ///< ACC system turned off
MADS_DISENGAGE_REASON_NON_PCM_ACC_MAIN_DESYNC = 16, ///< ACC sync error
MADS_DISENGAGE_REASON_HEARTBEAT_ENGAGED_MISMATCH = 32, ///< Heartbeat mismatch
} DisengageReason;

// ===============================
Expand All @@ -66,7 +66,7 @@ typedef enum __attribute__((packed)) {
// ===============================

typedef struct {
DisengageReason active_reason; // The reason that actually disengaged controls
DisengageReason active_reason; // The reason that actually disengaged controls
DisengageReason pending_reasons; // All conditions that would've prevented engagement while controls were disengaged
} DisengageState;

Expand Down
Loading