Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
systemDiagnostics.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdlib>
4#include "metro.h"
5#include "Arduino.h"
6
8#include "debugUtils.hpp"
9
10constexpr unsigned long READY_TIMEOUT_MS = 5000;
11constexpr unsigned long RELEASE_EBS_TIMEOUT_MS = 1000;
12constexpr unsigned long ENGAGE_EBS_TIMEOUT_MS = 5000;
13
14struct R2DLogics {
16
20
24 bool r2d{false};
25
32 r2d = false;
33 }
34
35
42
43
54 // If r2d is not received or received before 5 seconds, return false
55 if (readyTimestamp.check()) {
56 r2d = true;
57 return EXIT_SUCCESS;
58 }
59 // If r2d is received after the timeout duration, return true
60 r2d = false;
61 return EXIT_FAILURE;
62 }
63};
64
70 bool emergencySignal{false};
71 bool ts_on{false};
72 double radio_quality{0};
73
74 [[nodiscard]] bool hasAnyComponentTimedOut() {
75 bool steer_dead = steerAliveTimestamp.checkWithoutReset();
76 bool pc_dead = pcAliveTimestamp.checkWithoutReset();
77 bool inversor_dead = inversorAliveTimestamp.checkWithoutReset();
79 if (steer_dead) {
80 DEBUG_PRINT_VAR(steer_dead);
81 }
82 if (pc_dead) {
83 DEBUG_PRINT_VAR(pc_dead);
84 }
85 if (inversor_dead) {
86 DEBUG_PRINT_VAR(inversor_dead);
87 }
88 if (res_dead) {
89 DEBUG_PRINT_VAR(res_dead);
90 }
91 return steer_dead || pc_dead || inversor_dead || res_dead;
92 // pcAliveTimestamp.check() ||
93 // steerAliveTimestamp.check();
94 // inversorAliveTimestamp.check();
95 // resSignalLossTimestamp.check();
96 }
97};
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
bool check()
Checks if the interval has passed and resets the timer if true.
Definition metro.h:91
#define DEBUG_PRINT_VAR(var)
#define COMPONENT_TIMESTAMP_TIMEOUT
#define RES_TIMESTAMP_TIMEOUT
void enterReadyState()
resets timestamps for ready
Metro releaseEbsTimestamp
bool processGoSignal()
Processes the go signal.
void enterDrivingState()
resets timestamps for driving
constexpr unsigned long READY_TIMEOUT_MS
constexpr unsigned long RELEASE_EBS_TIMEOUT_MS
constexpr unsigned long ENGAGE_EBS_TIMEOUT_MS