Ready-to-Drive (R2D) FSM
The R2D FSM (r2d_fsm.c) implements the strict safety sequence required for a driver to transition the vehicle from an inactive state to an active driving state.
Flow Diagram
States
| State | Description |
|---|---|
SYSTEM_R2D_IDLE | FSM is inactive. |
SYSTEM_R2D_FIRST_BTN | The driver has pressed the R2D button for the first time to initiate the sequence. |
SYSTEM_R2D_PRECH_ONGOING | Waiting for the precharge circuit to close and stabilize via a non-blocking step sequencer. |
SYSTEM_R2D_SECOND_BTN | Precharge is complete; waiting for the driver to press the R2D button a second time while holding the brake pedal. |
SYSTEM_R2D_BUZZING | The R2D sequence is successful. The vehicle sounds the R2D buzzer for a mandated duration to alert bystanders. |
Transitions & Events
The sequence flows linearly through the states if conditions are met:
- First Button Press: Initiates the transition from
IDLEtoFIRST_BTN, which immediately falls through toPRECH_ONGOING. - Precharge Completion: While in
PRECH_ONGOING, the FSM executes a non-blocking step-sequencer usingHAL_GetTick()to manage contactor and relay settling times (AIR- closed → 300ms → Precharge closed → wait for voltage comparator (>1s minimum) → AIR+ closed → 300ms → Precharge opened → 300ms → done). Once complete, it moves toSECOND_BTN.- Timeout: If precharge takes too long (
precharge_timeoutof 15 seconds), the FSM flags anECU_FSM_REASON_FAULT_PRECHARGE_TIMEOUTand forces the ECU FSM toSYSTEM_SHUTDOWN.
- Timeout: If precharge takes too long (
- Second Button & Brake: In
SECOND_BTN, the FSM waits forbutton_pressedandbrake_okto be true simultaneously. When this happens, it transitions toBUZZING. - Buzzer Completion: In
BUZZING, it waits forbuzzer_elapsed. Once finished, it requests the ECU FSM to transition toSYSTEM_CONTROL(vehicle is now active).
