-
Notifications
You must be signed in to change notification settings - Fork 30
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
MADS: improvements on the state machine #48
Conversation
…ts on replay drive, and optimizations
…n button pressed interchangeably
…at the end of the tests
…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.
… disengagement for toyota
@@ -107,6 +107,7 @@ static void hyundai_canfd_rx_hook(const CANPacket_t *to_push) { | |||
int cruise_status = ((GET_BYTE(to_push, 8) >> 4) & 0x7U); | |||
bool cruise_engaged = (cruise_status == 1) || (cruise_status == 2); | |||
hyundai_common_cruise_state_check(cruise_engaged); | |||
acc_main_on = GET_BIT(to_push, 66U); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sunnyhaibin fyi
MADS Lateral Control: All Critical States1. Final Output Truth Table (mads_is_lateral_control_allowed_by_mads)
2. Control Permission State (m_can_allow_controls_lat) - When system_enabled = true
3. Button Control Request States and TransitionsFrom m_update_button_state(): if (button.transition == MADS_EDGE_RISING) {
const bool acc_active = *m_mads_state.acc_main.current;
m_mads_state.controls_requested_lat = !m_mads_state.controls_allowed_lat;
if (!m_mads_state.controls_requested_lat && !acc_active) {
mads_exit_controls(MADS_DISENGAGE_REASON_BUTTON);
}
}
4. ACC Main State ChangesFrom m_update_binary_state(): static void m_update_binary_state(BinaryStateTracking *state) {
EdgeTransition transition = m_get_edge_transition(*state->current, state->previous);
if (transition == MADS_EDGE_RISING) {
m_mads_state.controls_requested_lat = true;
} else if (transition == MADS_EDGE_FALLING) {
m_mads_state.controls_requested_lat = false;
mads_exit_controls(MADS_DISENGAGE_REASON_ACC_MAIN_OFF);
}
state->previous = *state->current;
}
5. Complete Control Request Resolution
6. Brake Impact States
7. Disengage Reason State Machine7.1 Setting Disengage Reasonsif (m_mads_state.controls_allowed_lat) {
m_mads_state.previous_disengage = m_mads_state.current_disengage;
m_mads_state.current_disengage.reason = reason;
m_mads_state.controls_allowed_lat = false;
} 7.2 Clearing Disengage Reasonsif (m_mads_state.controls_requested_lat && !m_mads_state.controls_allowed_lat && m_can_allow_controls_lat()) {
m_mads_state.controls_allowed_lat = true;
m_mads_state.previous_disengage = m_mads_state.current_disengage;
m_mads_state.current_disengage.reason = MADS_DISENGAGE_REASON_NONE;
} 7.3 Disengage Reason Transitions
Key behavior differences:
8. mads_state_update() Full Sequence8.1 Function Input Parametersvoid mads_state_update(
const bool *op_vehicle_moving,
const bool *op_acc_main,
bool is_braking,
bool cruise_engaged // Currently unused
) 8.2 Initialization Stepsm_mads_state.is_vehicle_moving_ptr = op_vehicle_moving;
m_mads_state.acc_main.current = op_acc_main;
m_mads_state.main_button.current = &main_button_press;
m_mads_state.lkas_button.current = &lkas_button_press; 8.3 Button State Flag Updatesif (!(m_mads_state.state_flags & MADS_STATE_FLAG_MAIN_BUTTON_AVAILABLE) &&
(main_button_press != MADS_BUTTON_UNAVAILABLE)) {
m_mads_state.state_flags |= MADS_STATE_FLAG_MAIN_BUTTON_AVAILABLE;
}
if (!(m_mads_state.state_flags & MADS_STATE_FLAG_LKAS_BUTTON_AVAILABLE) &&
(lkas_button_press != MADS_BUTTON_UNAVAILABLE)) {
m_mads_state.state_flags |= MADS_STATE_FLAG_LKAS_BUTTON_AVAILABLE;
} 8.4 Update Sequence (in order of execution)
m_update_button_state(&m_mads_state.main_button);
m_update_button_state(&m_mads_state.lkas_button); Effects:
m_update_binary_state(&m_mads_state.acc_main); Effects:
m_mads_check_braking(is_braking); Effects:
m_mads_try_allow_controls_lat(); Effects:
8.5 Critical Timing Dependencies
This sequence means:
|
This reverts commit 9bf0de6.
Updated version in #52 |
No description provided.