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
9#include "debugUtils.hpp"
10
11// Also known as Orchestrator
16private:
17 SystemData *_systemData;
18 Metro initialCheckupTimestamp{INITIAL_CHECKUP_STEP_TIMEOUT};
19
20public:
22
28 return initialCheckupTimestamp;
29 }
30
50
54 enum class CheckupError {
56 ERROR,
58 };
59
61
66 explicit CheckupManager(SystemData *systemData) : _systemData(systemData) {
67 };
68
72 void resetCheckupState();
73
77 [[nodiscard]] bool shouldStayManualDriving() const;
78
83
88
92 [[nodiscard]] bool shouldGoReadyFromOff() const;
93
97 [[nodiscard]] bool shouldStayReady() const;
98
102 [[nodiscard]] bool shouldEnterEmergency(State current_state) const;
103
104 [[nodiscard]] bool shouldStayDriving() const;
105
109 [[nodiscard]] bool shouldStayMissionFinished() const;
110
115 [[nodiscard]] bool emergencySequenceComplete() const;
116
123 [[nodiscard]] bool resTriggered() const;
124};
125
130
132 if (_systemData->mission != MANUAL || _systemData->digitalData.pneumatic_line_pressure != 0
133 || _systemData->digitalData.asms_on) {
134 return false;
135 }
136
137 return true;
138}
139
142
143 if (initSequenceState != CheckupError::SUCCESS) {
144 return true;
145 }
146 return false;
147}
148
150 // DEBUG_PRINT_VAR(static_cast<int>(checkupState));
151 switch (checkupState) {
153 // ASMS Activated?
154 if (_systemData->digitalData.asms_on) {
155 // checkupState = CheckupState::START_TOGGLING_WATCHDOG;
157 }
158 break;
159 // case CheckupState::START_TOGGLING_WATCHDOG:
160 // // Start toggling watchdog
161 // digitalWrite(SDC_LOGIC_WATCHDOG_OUT_PIN, HIGH);
162 // initialCheckupTimestamp.reset();
163 // checkupState = CheckupState::WAIT_FOR_WATCHDOG;
164 // break;
165 // case CheckupState::WAIT_FOR_WATCHDOG:
166 // // Watchdog_is_ready == 1
167 // if (initialCheckupTimestamp.check()) {
168 // return CheckupError::ERROR;
169 // }
170 // if (_systemData->digitalData.watchdog_state) {
171 // checkupState = CheckupState::STOP_TOGGLING_WATCHDOG;
172 // }
173 // break;
174 // case CheckupState::STOP_TOGGLING_WATCHDOG:
175 // // Stop toggling watchdog
176 // digitalWrite(SDC_LOGIC_WATCHDOG_OUT_PIN, LOW);
177 // initialCheckupTimestamp.reset();
178 // checkupState = CheckupState::CHECK_WATCHDOG;
179 // break;
180 // case CheckupState::CHECK_WATCHDOG:
181 // // Watchdog_is_ready == 0
182 // if (initialCheckupTimestamp.check() && !_systemData->digitalData.watchdog_state) {
183 // checkupState = CheckupState::CLOSE_SDC;
184 // //Start toggling watchdog again
185 // }
186 // break;
188 // Close SDC
191 break;
193 // digitalSender->toggleWatchdog();
194
195 // AATS Activated?
196 if (!_systemData->digitalData.sdcState_OPEN) {
197 // At this point, the emergency signal should be set to false, since it is
198 // expected that the RES has already sent all initial emergency signals,
199 // and if RES unexpectedly sends another emergency signal, it will be
200 // set after the AATS button is pressed.
201 _systemData->failureDetection.emergencySignal = false;
203 }
204 break;
206 // digitalSender->toggleWatchdog();
207 // TS Activated?
208 if (_systemData->failureDetection.ts_on) {
210 }
211 break;
213 // digitalSender->toggleWatchdog();
214 // Toggle EBS Valves
216
217 initialCheckupTimestamp.reset();
219 break;
221 // digitalSender->toggleWatchdog();
222 // Check hydraulic line pressure and pneumatic line pressure
223 // DEBUG_PRINT_VAR(_systemData->sensors._hydraulic_line_pressure);
224 // DEBUG_PRINT_VAR(_systemData->digitalData.pneumatic_line_pressure);
225 if (_systemData->sensors._hydraulic_line_pressure >= HYDRAULIC_BRAKE_THRESHOLD && _systemData->digitalData.
226 pneumatic_line_pressure) {
228 }
229 break;
230
232
233 // digitalSender->toggleWatchdog();
234 // Check if all components have responded and no emergency signal has been sent
235 if (_systemData->failureDetection.hasAnyComponentTimedOut()) {
237 }
238 if (_systemData->failureDetection.hasAnyComponentTimedOut() || _systemData->failureDetection.
239 emergencySignal) {
240 return CheckupError::ERROR;
241 }
243 }
244 default:
245 break;
246 }
248}
249
251 if (!_systemData->digitalData.asms_on || !_systemData->failureDetection.ts_on || _systemData->digitalData.sdcState_OPEN) {
252 return false;
253 }
254 _systemData->r2dLogics.enterReadyState();
255 return true;
256}
257
259 if (!_systemData->r2dLogics.r2d) {
260 return true;
261 }
262 _systemData->r2dLogics.enterDrivingState();
263 return false;
264}
265
266inline bool CheckupManager::shouldEnterEmergency(State current_state) const {
267 if (current_state == AS_READY) {
268 if (_systemData->failureDetection.hasAnyComponentTimedOut()) {
270 }
271 if (_systemData->failureDetection.emergencySignal) {
273 }
274 if (_systemData->digitalData.sdcState_OPEN) {
276 }
277 if (!_systemData->digitalData.asms_on) {
278 DEBUG_PRINT_VAR(_systemData->digitalData.asms_on);
279 }
280 if (!_systemData->failureDetection.ts_on) {
282 }
283 if (_systemData->digitalData.pneumatic_line_pressure == 0) {
286 }
290 }
291 return _systemData->failureDetection.emergencySignal ||
292 (_systemData->digitalData.pneumatic_line_pressure == 0
295 // _systemData->digitalData.watchdogTimestamp.check() ||
296 !_systemData->digitalData.asms_on ||
297 !_systemData->failureDetection.ts_on ||
300 _systemData->digitalData.sdcState_OPEN
301 ;
302 } else if (current_state == AS_DRIVING) {
303 if (_systemData->failureDetection.hasAnyComponentTimedOut()) {
305 }
306 if (_systemData->failureDetection.emergencySignal) {
308 }
309 if (_systemData->digitalData.sdcState_OPEN) {
311 }
312 if (!_systemData->digitalData.asms_on) {
313 DEBUG_PRINT_VAR(_systemData->digitalData.asms_on);
314 }
315 if (!_systemData->failureDetection.ts_on) {
317 }
318 if (_systemData->digitalData.pneumatic_line_pressure == 0) {
321 }
325 }
326 return _systemData->failureDetection.hasAnyComponentTimedOut() ||
327 _systemData->failureDetection.emergencySignal ||
328 _systemData->digitalData.sdcState_OPEN ||
329 (_systemData->digitalData.pneumatic_line_pressure == 0
333 !_systemData->digitalData.asms_on ||
334 // _systemData->digitalData.watchdogTimestamp.check() ||
335 !_systemData->failureDetection.ts_on;
336 }
337
338 return false;
339}
340
342 if (abs(_systemData->sensors._left_wheel_rpm) < 0.1 && abs(_systemData->sensors._right_wheel_rpm) < 0.1 && _systemData->missionFinished) {
343 return false;
344 }
345 return true;
346}
347
349 if (_systemData->digitalData.asms_on) {
350 return true;
351 }
352 return false;
353}
354
357 return true;
358 }
359 return false;
360}
361
362inline bool CheckupManager::resTriggered() const {
363 if (_systemData->failureDetection.emergencySignal) {
364 return true;
365 }
366 return false;
367}
368
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.
Metro & getInitialCheckupTimestamp()
Provides access to the initial checkup timestamp timer.
CheckupState
The CheckupState enum represents the different states of the initial checkup process....
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.
CheckupManager(SystemData *systemData)
Constructor for the CheckupManager class.
bool shouldGoReadyFromOff() const
Performs a last re-check for off to ready transition.
bool shouldStayDriving() const
CheckupState checkupState
Current state of the checkup process.
bool shouldStayMissionFinished() const
Performs a mission finished checkup.
CheckupError initialCheckupSequence(DigitalSender *digitalSender)
Performs an initial checkup.
Class responsible for controlling digital outputs in the Master Teensy.
static void closeSDC()
Closes the SDC in Master and SDC Logic.
static void activateEBS()
Activates the solenoid EBS valves.
Our own implementation of Metro class.
Definition metro.h:13
void reset()
Resets the timer to the current time.
Definition metro.h:125
bool checkWithoutReset() const
Checks if the interval has passed without resetting the timer.
Definition metro.h:116
constexpr auto HYDRAULIC_BRAKE_THRESHOLD
#define DEBUG_PRINT_VAR(var)
#define EBS_BUZZER_TIMEOUT
#define INITIAL_CHECKUP_STEP_TIMEOUT
DigitalSender digitalSender
Definition main.cpp:12
SystemData systemData
Definition main.cpp:9
bool pneumatic_line_pressure
void enterReadyState()
resets timestamps for ready
Metro releaseEbsTimestamp
void enterDrivingState()
resets timestamps for driving
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.
Sensors sensors
DigitalData digitalData
Mission mission
bool missionFinished
FailureDetection failureDetection
R2DLogics r2dLogics
State
Definition structure.hpp:8
@ AS_DRIVING
Definition structure.hpp:12
@ AS_READY
Definition structure.hpp:11
@ MANUAL
Definition structure.hpp:18