Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
stateLogic.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <model/structure.hpp>
6
14class ASState {
15private:
16 DigitalSender *_digitalSender;
17 Communicator *_communicator;
18
19public:
22
29 explicit ASState(SystemData *system_data, Communicator *communicator,
30 DigitalSender *digital_sender) :
31 _digitalSender(digital_sender), _communicator(communicator), _checkupManager(system_data) {}
32
36 void calculateState();
37};
38
40 switch (state) {
41 case AS_MANUAL:
43
44 DEBUG_PRINT("Entering OFF state from MANUAL");
46
47 state = AS_OFF;
48 break;
49
50 case AS_OFF:
51
52 // If manual driving checkup fails, the car can't be in OFF state, so it goes back to MANUAL
54 DEBUG_PRINT("Entering MANUAL state from OFF");
57 break;
58 }
59
60 if (_checkupManager.shouldStayOff(_digitalSender)) break;
61 if (!_checkupManager.shouldGoReadyFromOff()) break; // recheck all states
62
63 DEBUG_PRINT("Entering READY state from OFF");
66 break;
67
68 case AS_READY:
69 // _digitalSender->toggleWatchdog();
70
72 DEBUG_PRINT("Entering EMERGENCY state from READY");
73 _digitalSender->enterEmergencyState();
76 break;
77 }
79
80
81 DEBUG_PRINT("Entering DRIVING state from READY");
82 _digitalSender->enterDrivingState();
84 break;
85 case AS_DRIVING:
86 // _digitalSender->toggleWatchdog();
87 _digitalSender->blinkLED(ASSI_YELLOW_PIN);
88
90 DEBUG_PRINT("Entering EMERGENCY state from DRIVING");
91 _digitalSender->enterEmergencyState();
94 break;
95 }
97
98
99 DEBUG_PRINT("Entering FINISHED state from DRIVING");
102 break;
103 case AS_FINISHED:
105 DEBUG_PRINT("Entering EMERGENCY state from FINISHED");
106
107 _digitalSender->enterEmergencyState();
110 break;
111 }
113 break;
114
115
116 DEBUG_PRINT("Entering OFF state from FINISHED");
119 state = AS_OFF;
120 break;
121 case AS_EMERGENCY:
122 _digitalSender->blinkLED(ASSI_BLUE_PIN);
123
125 DEBUG_PRINT("Entering OFF state from EMERGENCY");
128 state = AS_OFF;
129 break;
130 }
131 break;
132 default:
133 break;
134 }
135}
136
137
The ASState class manages and transitions between different states of the vehicle system.
void calculateState()
Calculates the state of the vehicle.
CheckupManager _checkupManager
CheckupManager object for handling various checkup operations.
ASState(SystemData *system_data, Communicator *communicator, DigitalSender *digital_sender)
Constructor for the ASState class.
State state
Current state of the vehicle system, initialized to OFF.
The CheckupManager class handles various checkup operations.
bool shouldEnterEmergency(State current_state) const
Performs an emergency checkup.
Metro _ebsSoundTimestamp
Timer for the EBS buzzer sound check.
bool emergencySequenceComplete() const
Checks if the emergency sequence is complete and the vehicle can transition to AS_OFF.
bool shouldStayManualDriving() const
Performs a manual driving checkup.
void resetCheckupState()
Resets the checkup state to the initial state.
bool shouldStayOff(DigitalSender *digitalSender)
Performs an off checkup.
bool resTriggered() const
Checks if the RES has been triggered.
bool shouldStayReady() const
Performs a ready to drive checkup.
bool shouldGoReadyFromOff() const
Performs a last re-check for off to ready transition.
bool shouldStayDriving() const
bool shouldStayMissionFinished() const
Performs a mission finished checkup.
Class that contains definitions of typical messages to send via CAN It serves only as an example of t...
Class responsible for controlling digital outputs in the Master Teensy.
static void enterReadyState()
ASSI yellow LED on, ebs valves activated, sdc closed.
static void enterFinishState()
ASSI blue LED on, ebs valves activated, sdc open.
static void enterOffState()
Everything off, sdc open.
void enterDrivingState()
ASSI LEDs yellow flashing, ebs valves deactivated, sdc closed.
void enterEmergencyState()
ASSI LEDs blue flashing, sdc open and buzzer ringing.
static void enterManualState()
Everything off, sdc closed.
void blinkLED(int pin)
Blinks the LED at the given pin.
void reset()
Resets the timer to the current time.
Definition metro.h:125
#define DEBUG_PRINT(str)
#define ASSI_BLUE_PIN
#define ASSI_YELLOW_PIN
Communicator communicator
Definition main.cpp:10
The whole model of the system: holds all the data necessary.
State
Definition structure.hpp:8
@ AS_DRIVING
Definition structure.hpp:12
@ AS_READY
Definition structure.hpp:11
@ AS_MANUAL
Definition structure.hpp:9
@ AS_FINISHED
Definition structure.hpp:13
@ AS_EMERGENCY
Definition structure.hpp:14
@ AS_OFF
Definition structure.hpp:10