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) #52

Closed
wants to merge 143 commits into from

Conversation

sunnyhaibin
Copy link
Collaborator

@sunnyhaibin sunnyhaibin commented Dec 9, 2024

Description

  • Remove explicit main cruise button state handling
  • Handle explicit main cruise button state handling for affected brands
  • Add tests for disengage lateral on brake press, and resume lateral on brake release

Reimplementation of

TODO

  • Inherit MadsCommonNonPCMMainCruiseBase in longitudinal unit tests

devtekve and others added 30 commits December 6, 2024 11:47
…afety code

The commit performs a comprehensive revision of the safety replay script, specifically focusing on introducing debug variables and enhancing the logging capabilities for improved debugging. Furthermore, changes were made to the Honda safety code. The test helpers within libpanda were also expanded for inclusion of additional test conditions.
…s 'safety_mads.h'

The Sunnypilot's 'safety_mads.h' file has been updated to include 'ACC_MAIN_OFF' as a new cause for disconnection in the 'DisengageReason' enumeration. If an 'acc_main_off' signal is received, the 'mads_exit_controls' function halts all requests for lateral control engagement. Additionally, the status of 'controls_requested_lat' now mirrors 'controls_allowed_lat' after a button press.
Renamed StateTransition to EdgeTransition for clarity and updated related logic. Introduced event handlers for button presses and ACC state changes, reducing duplicated control flow code. Improved encapsulation and maintainability by restructuring state update functions.
Removed redundant event handler functions and unnecessary timestamp fields to streamline the code. Simplified button and binary state updates by integrating logic directly into transition checks. Commented out unused fields
The logic for setting the `controls_requested_lat` variable in safety_mads.h has been refined. Previously, it switched state based on the current value of `controls_allowed_lat`. Now, it also takes into account the current state of `acc_main`, ensuring a more nuanced control request mechanism that accounts for different operational scenarios.
Refactor button state transitions to better handle lateral control requests when ACC is active. Ensure controls are correctly disengaged under specific conditions, by setting `controls_requested_lat` more reliably during state transitions. This change improves safety by preventing inadvertent disengagement when ACC is not active.
This commit introduces a new test to ensure that controls remain enabled when the LKAS/LFA button is pressed while ACC main is on. It checks that LKAS button operations don't interfere with control permissions in this specific configuration, improving test coverage and preventing potential safety issues.
Enhanced mismatch detection logic by tracking cases where 'controls_allowed' is true while 'controls_allowed_lat' is false, updating the script to print relevant debug information. Additionally, changed the data type of 'mads_acc_main' and 'mads_acc_main_prev' from int to bool for improved type accuracy and consistency.
…at_active() which has the final word on whether we can allow lat or not.
…BRAKE'

The commit modifies the usage of the 'DISABLE_DISENGAGE_LATERAL_ON_BRAKE' variable globally and replaces it with 'DISENGAGE_LATERAL_ON_BRAKE'. This change promotes correct and clear semantics, since the variable now indicates a state rather than the negation of a state.
board/safety.h Outdated
@@ -114,7 +114,7 @@ static const safety_hooks *current_hooks = &nooutput_hooks;
safety_config current_safety_config;

static bool is_lat_active(void) {
return controls_allowed || mads_is_lateral_control_allowed_by_mads();
return (controls_allowed && !mads_system_enabled()) || mads_is_lateral_control_allowed_by_mads();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (controls_allowed && !mads_system_enabled()) || mads_is_lateral_control_allowed_by_mads();
return controls_allowed || mads_is_lateral_control_allowed_by_mads();

This is not supposed to happen. Do the whole "decision" if lat is active inside the MADS method instead

Comment on lines 155 to 159

// Unified Engagement Mode
if ((m_mads_state.op_controls_allowed.transition == MADS_EDGE_RISING) && m_mads_state.unified_engagement_mode) {
m_mads_state.controls_requested_lat = true;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Unified Engagement Mode
if ((m_mads_state.op_controls_allowed.transition == MADS_EDGE_RISING) && m_mads_state.unified_engagement_mode) {
m_mads_state.controls_requested_lat = true;
}

// Use buttons or main cruise state transition properties to request lateral control
static void m_mads_update_state(void) {
// Main cruise
if ((m_mads_state.acc_main.transition == MADS_EDGE_RISING) && m_mads_state.main_cruise_allowed) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ((m_mads_state.acc_main.transition == MADS_EDGE_RISING) && m_mads_state.main_cruise_allowed) {
if (m_mads_state.acc_main.transition == MADS_EDGE_RISING) {

Comment on lines 148 to 154
if ((m_mads_state.mads_button.transition == MADS_EDGE_RISING) && (*m_mads_state.acc_main.current || m_mads_state.always_allow_mads_button)) {
m_mads_state.controls_requested_lat = !m_mads_state.controls_allowed_lat;

if (!m_mads_state.controls_requested_lat) {
mads_exit_controls(MADS_DISENGAGE_REASON_BUTTON);
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ((m_mads_state.mads_button.transition == MADS_EDGE_RISING) && (*m_mads_state.acc_main.current || m_mads_state.always_allow_mads_button)) {
m_mads_state.controls_requested_lat = !m_mads_state.controls_allowed_lat;
if (!m_mads_state.controls_requested_lat) {
mads_exit_controls(MADS_DISENGAGE_REASON_BUTTON);
}
}
if (m_mads_state.mads_button.transition == MADS_EDGE_RISING) {
m_mads_state.controls_requested_lat = true;
if (!m_mads_state.controls_requested_lat) {
mads_exit_controls(MADS_DISENGAGE_REASON_BUTTON);
}
}

@sunnyhaibin
Copy link
Collaborator Author

Need to fix tests with the new changes.

@sunnyhaibin sunnyhaibin marked this pull request as draft December 12, 2024 15:53
sunnyhaibin and others added 12 commits December 12, 2024 11:10
The mads_state_update function has been refactored to improve its readability and performance. The changes include the modification of how binary state and button state are updated, along with how vehicle movement and braking are evaluated. Additionally, the acc_main, mads_button, and braking members of the MADSState struct now store values instead of pointers to values, which should boost execution speed.
@sunnyhaibin
Copy link
Collaborator Author

Superseded by #57

@sunnyhaibin sunnyhaibin deleted the mads-new-diff-2 branch December 13, 2024 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants