mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-18 17:23:52 +08:00
* alternative experience * safety init * fix * more update * not really * misra * Add Custom MIT License (#38) * brake check was not handled * revert * alt -> lkas * explicit checks * support toyota and ford * rename * hyundai can-fd support * only allow lkas if enabled * hyundai: main button handling * revert * hyundai: main button heartbeat * add logging for controls allowed lateral * fix panda safety * ford btn * toyota btn * fca btn * honda btn * mads safety tests * more tests * safety misra * safety mutation * misra * mutation experiment * fix * ford test main button * ford test lkas button * more ford test * hyundai lkas and main * more ford * hyundai canfd * rename * rename * cleaner * more fixes * more hyundai tests * no longer needed * thanks for tests! * more tests for lat * more explicit * make sure to reset * try this out * probably needed * move * misra * not needed * move to safety_mads * not really needed * remove * MADS: Refactor MADS safety with improved state management (pull request #46) Refactor MADS safety with improved state management This commit introduces a major refactoring of the MADS safety module, improving state management and control flow. Key changes include: Core Changes: - Introduced a MADSState struct to centralize state management - Removed global state variables in favor of structured state - Implemented button transition handling with explicit state tracking (PRESSED/RELEASED/NO_CHANGE) - Added state flags for button availability detection - Simplified lateral control permission logic Button Handling: - Separated main button and LKAS button state tracking - Added independent engagement states for each button - Improved button press detection across multiple platforms - Added support for main and LKAS buttons on Hyundai platforms - Modified ACC main state handling Testing: - Added comprehensive test coverage for MADS state transitions - Added new MADS-specific test base class for consistent testing across platforms - Added mutation testing for state management - Extended timeout for mutation tests from 5 to 8 minutes - Added extensive button press validation tests - Enhanced debugging output in replay drive tests The refactored code provides a more organized implementation of MADS safety features while maintaining compatibility with existing safety checks. * adding note * adding ford (WIP) * adding honda (WIP) * adding toyota (WIP) * adding chrysler (WIP) * Standardize Button State Handling Across Platforms Refactor button state handling by replacing integer constants with an enumerated `ButtonState` type and updating logic to improve readability and maintainability. This change affects button press detection in Ford, Honda, Hyundai, and Toyota safety modules and aligns them with a unified MADS button state approach. Enums provide a clearer understanding of button states and transitions, facilitating easier maintenance and future enhancements. * Disable LKAS button press logic in Honda and Toyota safety. The code for processing LKAS button presses has been commented out in both Honda and Toyota safety implementations. This change aims to investigate or temporarily halt the button press effects without removing the logic altogether. It will be important to test for any impacts this may have on vehicle control functionality. * Remove commented out code in toyota_rx_hook function This commit cleans up the toyota_rx_hook function by removing unnecessary commented-out code that checks for LKAS button presses on bus 2. This helps improve code readability and maintainability without altering the existing functionality. * GM, mazda, nissan, subaru (global & preglobal) * Honda LKAS * Revert "Remove commented out code in toyota_rx_hook function" This reverts commit d6b012c01a08118d91fad56c9f6ac2f92b671968. * Toyota, Subaru Global LKAS * nissan fix * gm fix * use speed msg to force rx * im bored * misra * subaru/toyota/honda * nope * attempt * go through all buttons * try nissan * more nissan * nissan tests passed! * subaru lkas test (not sure why it's not passing 2 and 3 values) * Improved code organization in safety_subaru.h and test_subaru.py This commit includes a minor restructuring in safety_subaru.h and test_subaru.py for better readability and flow. The condition check in safety_subaru.h for lkas_hud now has explicit parentheses. With regard to test_subaru.py, an unnecessary import was removed, and the sequence of steps in the test was reordered - now enabling mads and cleaning up mads_states happens before each subtest. * Refactor tests to use _speed_msg instead of _user_brake_msg. Updated the MADS safety tests to utilize the _speed_msg(0) function call in place of _user_brake_msg(False). * Reworking the tests a little for clarity * disabling lkas again on toyota temporarily * fix mads condition to engage * hyundai and honda good with new tests * Redoing more tests * update for safety tick ensuring mads control is exited while lagging * Updating tests for toyota * cleaning up tests on hkg * commenting out temp_debug for future use * revert * constants * cleanup * format! * match yota * Apply suggestions from code review * force * explicit checks * revert --------- Co-authored-by: Jason Wen <haibin.wen3@gmail.com>
154 lines
5.8 KiB
Python
154 lines
5.8 KiB
Python
# panda safety helpers, from safety_helpers.c
|
|
from typing import Protocol
|
|
|
|
def setup_safety_helpers(ffi):
|
|
ffi.cdef("""
|
|
void set_controls_allowed(bool c);
|
|
bool get_controls_allowed(void);
|
|
bool get_lat_active(void);
|
|
bool get_controls_allowed_lat(void);
|
|
bool get_longitudinal_allowed(void);
|
|
void set_alternative_experience(int mode);
|
|
int get_alternative_experience(void);
|
|
void set_relay_malfunction(bool c);
|
|
bool get_relay_malfunction(void);
|
|
bool get_gas_pressed_prev(void);
|
|
void set_gas_pressed_prev(bool);
|
|
bool get_brake_pressed_prev(void);
|
|
bool get_regen_braking_prev(void);
|
|
bool get_acc_main_on(void);
|
|
int get_vehicle_speed_min(void);
|
|
int get_vehicle_speed_max(void);
|
|
int get_vehicle_speed_last(void);
|
|
int get_current_safety_mode(void);
|
|
int get_current_safety_param(void);
|
|
|
|
void set_torque_meas(int min, int max);
|
|
int get_torque_meas_min(void);
|
|
int get_torque_meas_max(void);
|
|
void set_torque_driver(int min, int max);
|
|
int get_torque_driver_min(void);
|
|
int get_torque_driver_max(void);
|
|
void set_desired_torque_last(int t);
|
|
void set_rt_torque_last(int t);
|
|
void set_desired_angle_last(int t);
|
|
int get_desired_angle_last();
|
|
void set_angle_meas(int min, int max);
|
|
int get_angle_meas_min(void);
|
|
int get_angle_meas_max(void);
|
|
|
|
bool get_cruise_engaged_prev(void);
|
|
void set_cruise_engaged_prev(bool engaged);
|
|
bool get_vehicle_moving(void);
|
|
int get_hw_type(void);
|
|
void set_timer(uint32_t t);
|
|
|
|
void safety_tick_current_safety_config();
|
|
bool safety_config_valid();
|
|
|
|
void init_tests(void);
|
|
|
|
void set_honda_fwd_brake(bool c);
|
|
bool get_honda_fwd_brake(void);
|
|
void set_honda_alt_brake_msg(bool c);
|
|
void set_honda_bosch_long(bool c);
|
|
int get_honda_hw(void);
|
|
|
|
void set_enable_mads(bool enable_mads, bool disengage_lat_on_brake);
|
|
bool get_enable_mads(void);
|
|
bool get_disengage_lat_on_brake(void);
|
|
int get_main_button_press(void);
|
|
void set_mads_state_flags(int flags);
|
|
int get_mads_state_flags(void);
|
|
int get_mads_main_button_transition(void);
|
|
int get_mads_main_button_current(void);
|
|
int get_mads_main_button_last(void);
|
|
void set_main_button_press(int main_button_press);
|
|
void set_lkas_button_press(int lkas_button_press);
|
|
void set_controls_allowed_lat(bool c);
|
|
|
|
bool get_main_button_engaged(void);
|
|
bool get_lkas_button_engaged(void);
|
|
void set_main_button_engaged(bool engaged);
|
|
void set_lkas_button_engaged(bool engaged);
|
|
|
|
int get_mads_acc_main(void);
|
|
void set_acc_main_on(bool c);
|
|
int get_lkas_button_press(void);
|
|
// int get_temp_debug(void);
|
|
""")
|
|
|
|
class PandaSafety(Protocol):
|
|
def set_controls_allowed(self, c: bool) -> None: ...
|
|
def get_controls_allowed(self) -> bool: ...
|
|
def set_controls_allowed_lat(self, c: bool) -> None: ...
|
|
def get_lat_active(self) -> bool: ...
|
|
def get_controls_allowed_lat(self) -> bool: ...
|
|
def get_main_button_press(self) -> int: ...
|
|
def set_mads_state_flags(self, flags: int) -> None: ...
|
|
def get_mads_state_flags(self) -> int: ...
|
|
def get_mads_main_button_transition(self) -> int: ...
|
|
def get_mads_main_button_current(self) -> int: ...
|
|
def get_mads_main_button_last(self) -> int: ...
|
|
def get_mads_acc_main(self) -> int: ...
|
|
def get_longitudinal_allowed(self) -> bool: ...
|
|
def set_alternative_experience(self, mode: int) -> None: ...
|
|
def get_alternative_experience(self) -> int: ...
|
|
def set_relay_malfunction(self, c: bool) -> None: ...
|
|
def get_relay_malfunction(self) -> bool: ...
|
|
def get_gas_pressed_prev(self) -> bool: ...
|
|
def set_gas_pressed_prev(self, c: bool) -> None: ...
|
|
def get_brake_pressed_prev(self) -> bool: ...
|
|
def get_regen_braking_prev(self) -> bool: ...
|
|
def get_acc_main_on(self) -> bool: ...
|
|
def set_acc_main_on(self, c: bool) -> None: ...
|
|
def get_vehicle_speed_min(self) -> int: ...
|
|
def get_vehicle_speed_max(self) -> int: ...
|
|
def get_vehicle_speed_last(self) -> int: ...
|
|
def get_current_safety_mode(self) -> int: ...
|
|
def get_current_safety_param(self) -> int: ...
|
|
|
|
def set_torque_meas(self, min: int, max: int) -> None: ... # noqa: A002
|
|
def get_torque_meas_min(self) -> int: ...
|
|
def get_torque_meas_max(self) -> int: ...
|
|
def set_torque_driver(self, min: int, max: int) -> None: ... # noqa: A002
|
|
def get_torque_driver_min(self) -> int: ...
|
|
def get_torque_driver_max(self) -> int: ...
|
|
def set_desired_torque_last(self, t: int) -> None: ...
|
|
def set_rt_torque_last(self, t: int) -> None: ...
|
|
def set_desired_angle_last(self, t: int) -> None: ...
|
|
def get_desired_angle_last(self) -> int: ...
|
|
def set_angle_meas(self, min: int, max: int) -> None: ... # noqa: A002
|
|
def get_angle_meas_min(self) -> int: ...
|
|
def get_angle_meas_max(self) -> int: ...
|
|
|
|
def get_cruise_engaged_prev(self) -> bool: ...
|
|
def set_cruise_engaged_prev(self, enabled: bool) -> None: ...
|
|
def get_vehicle_moving(self) -> bool: ...
|
|
def get_hw_type(self) -> int: ...
|
|
def set_timer(self, t: int) -> None: ...
|
|
|
|
def safety_tick_current_safety_config(self) -> None: ...
|
|
def safety_config_valid(self) -> bool: ...
|
|
|
|
def init_tests(self) -> None: ...
|
|
|
|
def set_honda_fwd_brake(self, c: bool) -> None: ...
|
|
def get_honda_fwd_brake(self) -> bool: ...
|
|
def set_honda_alt_brake_msg(self, c: bool) -> None: ...
|
|
def set_honda_bosch_long(self, c: bool) -> None: ...
|
|
def get_honda_hw(self) -> int: ...
|
|
|
|
def set_enable_mads(self, enable_mads: bool, disengage_lat_on_brake: bool) -> None: ...
|
|
def set_main_button_press(self, main_button_press: int) -> None: ...
|
|
def set_lkas_button_press(self, lkas_button_press: int) -> None: ...
|
|
def get_enable_mads(self) -> bool: ...
|
|
def get_disengage_lat_on_brake(self) -> bool: ...
|
|
def set_main_button_engaged(self, engaged: bool) -> None: ...
|
|
def get_main_button_engaged(self) -> bool: ...
|
|
def set_lkas_button_engaged(self, engaged: bool) -> None: ...
|
|
def get_lkas_button_engaged(self) -> bool: ...
|
|
|
|
def get_lkas_button_press(self) -> int: ...
|
|
# def get_temp_debug(self) -> int: ...
|