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
5#include <model/structure.hpp>
6
15class ASState {
16private:
18 *_digital_sender_;
20 *_communicator_;
21
22public:
26
39
43 void calculate_state();
44};
45
47 switch (state_) {
50
51 DEBUG_PRINT("Entering OFF state from MANUAL");
53
55 break;
56
57 case State::AS_OFF:
58
59 // If manual driving checkup fails, the car can't be in OFF state, so it goes back to MANUAL
61 DEBUG_PRINT("Entering MANUAL state from OFF");
64 break;
65 }
66
67 if (_checkup_manager_.should_stay_off(_digital_sender_)) break;
68 if (!_checkup_manager_.should_go_ready_from_off()) break; // recheck all states
69
70 DEBUG_PRINT("Entering READY state from OFF");
73 DEBUG_PRINT("READY state entered...");
74 break;
75
76 case State::AS_READY:
78 DEBUG_PRINT("Entering EMERGENCY state from READY");
79 _digital_sender_->enter_emergency_state();
82 break;
83 }
85 break;
86 }
87
88 DEBUG_PRINT("Entering DRIVING state from READY");
89 _digital_sender_->enter_driving_state();
91 break;
93 _digital_sender_->blink_led(ASSI_YELLOW_PIN);
94
96 DEBUG_PRINT("Entering EMERGENCY state from DRIVING");
97 _digital_sender_->enter_emergency_state();
100 break;
101 }
103
104 DEBUG_PRINT("Entering FINISHED state from DRIVING");
107 break;
110 DEBUG_PRINT("Entering EMERGENCY state from FINISHED");
111
112 _digital_sender_->enter_emergency_state();
115 break;
116 }
118
119 DEBUG_PRINT("Entering OFF state from FINISHED");
123 break;
125 _digital_sender_->blink_led(ASSI_BLUE_PIN);
126
128 DEBUG_PRINT("Entering OFF state from EMERGENCY");
132 break;
133 }
134 break;
135 default:
136 break;
137 }
138}
The ASState class manages and transitions between different states of the vehicle system.
ASState(SystemData *system_data, Communicator *communicator, DigitalSender *digital_sender)
Constructor for the ASState class.
void calculate_state()
Calculates the state of the vehicle.
CheckupManager _checkup_manager_
CheckupManager object for handling various checkup operations.
State state_
Current state of the vehicle system, initialized to OFF.
The CheckupManager class handles various checkup operations.
bool should_stay_manual_driving() const
Performs a manual driving checkup.
bool should_enter_emergency(State current_state) const
Performs an emergency checkup.
bool should_stay_off(DigitalSender *digital_sender)
Performs an off checkup.
Metro _ebs_sound_timestamp_
Timer for the EBS buzzer sound check.
bool emergency_sequence_complete() const
Checks if the emergency sequence is complete and the vehicle can transition to AS_OFF.
bool should_stay_ready() const
Performs a ready to drive checkup.
bool should_go_ready_from_off() const
Performs a last re-check for off to ready transition.
void reset_checkup_state()
Resets the checkup state to the initial state.
bool should_stay_mission_finished() const
Performs a mission finished checkup.
bool res_triggered() const
Checks if the RES has been triggered.
bool should_stay_driving() const
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.
void enter_emergency_state()
ASSI LEDs blue flashing, sdc open and buzzer ringing.
void blink_led(int pin)
Blinks the LED at the given pin.
static void enter_finish_state()
ASSI blue LED on, ebs valves activated, sdc open.
static void enter_manual_state()
Everything off, sdc closed.
void enter_driving_state()
ASSI LEDs yellow flashing, ebs valves deactivated, sdc closed.
static void enter_ready_state()
ASSI yellow LED on, ebs valves activated, sdc closed.
static void enter_off_state()
Everything off, sdc open.
void reset()
Resets the timer to the current time.
Definition metro.h:124
#define DEBUG_PRINT(str)
constexpr int ASSI_BLUE_PIN
constexpr int ASSI_YELLOW_PIN
Communicator communicator
Definition main.cpp:11
SystemData system_data
Definition main.cpp:10
DigitalSender digital_sender
Definition main.cpp:14
The whole model of the system: holds all the data necessary.
State
Definition structure.hpp:8
@ AS_DRIVING
@ AS_MANUAL
@ AS_READY
@ AS_FINISHED
@ AS_EMERGENCY