Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
checkupManager.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdlib>
4
6#include "debugUtils.hpp"
10
11// Also known as Orchestrator
16private:
17 SystemData *_system_data_;
19 // Metro initialCheckupTimestamp{INITIAL_CHECKUP_STEP_TIMEOUT}; ///< Timer for the initial checkup
20 // sequence.
21
22public:
24
45
50
53
58 explicit CheckupManager(SystemData *system_data) : _system_data_(system_data) {};
59
64
68 [[nodiscard]] bool should_stay_manual_driving() const;
69
74
79
83 [[nodiscard]] bool should_go_ready_from_off() const;
84
88 [[nodiscard]] bool should_stay_ready() const;
89
93 [[nodiscard]] bool should_enter_emergency(State current_state) const;
94
95 [[nodiscard]] bool should_stay_driving() const;
96
100 [[nodiscard]] bool should_stay_mission_finished() const;
101
106 [[nodiscard]] bool emergency_sequence_complete() const;
107
114 [[nodiscard]] bool res_triggered() const;
115};
116
121
123 if (_system_data_->mission_ != Mission::MANUAL ||
124 _system_data_->digital_data_.pneumatic_line_pressure_ != 0 ||
125 _system_data_->digital_data_.asms_on_) {
126 return false;
127 }
128
129 return true;
130}
131
134
135 if (init_sequence_state != CheckupError::SUCCESS) {
136 return true;
137 }
138 return false;
139}
140
143 switch (checkup_state_) {
145 // ASMS Activated?
146 if (_system_data_->digital_data_.asms_on_) {
148 }
149 break;
151 // Close SDC
154
155 break;
157
158 // AATS Activated?
159 if (!_system_data_->digital_data_.sdc_open_) {
160 // At this point, the emergency signal should be set to false, since it is
161 // expected that the RES has already sent all initial emergency signals,
162 // and if RES unexpectedly sends another emergency signal, it will be
163 // set after the AATS button is pressed.
164 _system_data_->failure_detection_.emergency_signal_ = false;
166 }
167 break;
169 if (_system_data_->failure_detection_.ts_on_) {
170 DEBUG_PRINT("TS activated");
171
173 }
174 break;
176 // Toggle EBS Valves
178 DEBUG_PRINT("EBS activated");
180
181 break;
183 // Check hydraulic line pressure and pneumatic line pressure
187 }
188 break;
189
191 // Check if all components have responded and no emergency signal has been sent
193 if (_system_data_->failure_detection_.has_any_component_timed_out() ||
194 _system_data_->failure_detection_.emergency_signal_) {
195 DEBUG_PRINT("Returning ERROR from CHECK_TIMESTAMPS")
196 return CheckupError::ERROR;
197 }
199 DEBUG_PRINT("Checkup complete and returning success");
201 }
202 default:
203 break;
204 }
206}
207
209 if (!_system_data_->digital_data_.asms_on_ || !_system_data_->failure_detection_.ts_on_ ||
210 _system_data_->digital_data_.sdc_open_) {
211 return false;
212 }
213 _system_data_->r2d_logics_.enter_ready_state();
214 return true;
215}
216
218 if (!_system_data_->r2d_logics_.r2d) {
219 return true;
220 }
221 _system_data_->r2d_logics_.enter_driving_state();
222 return false;
223}
224
225inline bool CheckupManager::should_enter_emergency(State current_state) const {
226 if (current_state == State::AS_READY) {
227 return _system_data_->failure_detection_.emergency_signal_ ||
228 (_system_data_->digital_data_.pneumatic_line_pressure_ == 0 &&
229 _system_data_->r2d_logics_.engageEbsTimestamp
230 .checkWithoutReset()) || // 5 seconds have passed since ready state and line
231 // pressure is 0
233 !_system_data_->digital_data_.asms_on_ || !_system_data_->failure_detection_.ts_on_ ||
236 _system_data_->digital_data_.sdc_open_;
237 } else if (current_state == State::AS_DRIVING) {
238 return _system_data_->failure_detection_.has_any_component_timed_out() ||
239 _system_data_->failure_detection_.emergency_signal_ ||
240 _system_data_->digital_data_.sdc_open_ ||
241 (_system_data_->digital_data_.pneumatic_line_pressure_ == 0 &&
242 _system_data_->r2d_logics_.releaseEbsTimestamp
243 .checkWithoutReset()) || // car has one second to make pneumatic pressure 1
245 _system_data_->r2d_logics_.releaseEbsTimestamp
246 .checkWithoutReset()) || // car has 1 second to reduce hydraulic pressure
247 !_system_data_->digital_data_.asms_on_ ||
248 !_system_data_->failure_detection_.ts_on_;
249 }
250
251 return false;
252}
253
255 if (abs(_system_data_->sensors_._left_wheel_rpm) < 0.1 &&
256 abs(_system_data_->sensors_._right_wheel_rpm) < 0.1 && _system_data_->mission_finished_) {
257 return false;
258 }
259 return true;
260}
261
263 if (_system_data_->digital_data_.asms_on_) {
264 return true;
265 }
266 return false;
267}
268
271 return true;
272 }
273 return false;
274}
275
276inline bool CheckupManager::res_triggered() const {
277 if (_system_data_->failure_detection_.emergency_signal_) {
278 return true;
279 }
280 return false;
281}
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.
CheckupError initial_checkup_sequence(DigitalSender *digital_sender)
Performs an initial checkup.
CheckupState checkup_state_
Current state of the checkup process.
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.
CheckupState
The CheckupState enum represents the different states of the initial checkup process....
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
CheckupManager(SystemData *system_data)
Constructor for the CheckupManager class.
Class responsible for controlling digital outputs in the Master Teensy.
static void activate_ebs()
Activates the solenoid EBS valves.
static void close_sdc()
Closes the SDC in Master and SDC Logic.
Our own implementation of Metro class.
Definition metro.h:13
bool checkWithoutReset() const
Checks if the interval has passed without resetting the timer.
Definition metro.h:115
constexpr auto HYDRAULIC_BRAKE_THRESHOLD
#define DEBUG_PRINT(str)
constexpr int EBS_BUZZER_TIMEOUT
SystemData system_data
Definition main.cpp:10
DigitalSender digital_sender
Definition main.cpp:14
bool pneumatic_line_pressure_
void enter_ready_state()
resets timestamps for ready
void enter_driving_state()
resets timestamps for driving
Metro releaseEbsTimestamp
int _hydraulic_line_pressure
Definition sensors.hpp:9
double _right_wheel_rpm
Definition sensors.hpp:7
double _left_wheel_rpm
Definition sensors.hpp:8
The whole model of the system: holds all the data necessary.
Mission mission_
DigitalData digital_data_
R2DLogics r2d_logics_
FailureDetection failure_detection_
bool mission_finished_
Sensors sensors_
State
Definition structure.hpp:8
@ AS_DRIVING
@ AS_READY