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
5#include "Arduino.h"
6#include "debugUtils.hpp"
8#include "metro.h"
9
10struct R2DLogics {
12
16
20 bool r2d{false};
21
28 r2d = false;
29 }
30
35
45 //if 5 seconds have passed all good, VVVRRRUUUMMMMM
46 if (readyTimestamp.check()) {
47 r2d = true;
48 return;
49 }
50 r2d = false;
51 return;
52 }
53};
54
60 Metro dc_voltage_drop_timestamp_{DC_VOLTAGE_TIMEOUT}; // timer to check if dc voltage drops below
61 // threshold for more than 150ms
63 DC_VOLTAGE_HOLD}; // timer for ts on, only after enough voltage for 1 sec
64 bool steer_dead_{true};
65 bool pc_dead_{true};
66 bool inversor_dead_{true};
67 bool res_dead_{true};
68 bool emergency_signal_{false};
69 bool ts_on_{false};
70 double radio_quality_{0};
71 unsigned dc_voltage_{0};
72
73 [[nodiscard]] bool has_any_component_timed_out() { // no discard makes return value non ignorable
74
79 DEBUG_PRINT("=== System Component Status Check ===");
80 DEBUG_PRINT("Steering System: " + String(steer_dead_ ? "DEAD" : "ALIVE"));
81 DEBUG_PRINT("PC Connection: " + String(pc_dead_ ? "DEAD" : "ALIVE"));
82 DEBUG_PRINT("Inverter Status: " + String(inversor_dead_ ? "DEAD" : "ALIVE"));
83 DEBUG_PRINT("RES Signal: " + String(res_dead_ ? "DEAD" : "ALIVE"));
84 // Print final result
85 DEBUG_PRINT("Overall System Status: " +
86 String((steer_dead_ || pc_dead_ || inversor_dead_ || res_dead_) ? "FAULT DETECTED"
87 : "ALL OK"));
88
90 }
91};
Our own implementation of Metro class.
Definition metro.h:13
void reset()
Resets the timer to the current time.
Definition metro.h:124
bool checkWithoutReset() const
Checks if the interval has passed without resetting the timer.
Definition metro.h:115
bool check()
Checks if the interval has passed and resets the timer if true.
Definition metro.h:90
#define DEBUG_PRINT(str)
constexpr unsigned long READY_TIMEOUT_MS
constexpr unsigned long RELEASE_EBS_TIMEOUT_MS
constexpr int RES_TIMESTAMP_TIMEOUT
constexpr unsigned long ENGAGE_EBS_TIMEOUT_MS
constexpr int COMPONENT_TIMESTAMP_TIMEOUT
constexpr int DC_VOLTAGE_HOLD
constexpr int DC_VOLTAGE_TIMEOUT
void reset_ebs_timestamp()
resets timestamps for driving
void enter_ready_state()
resets timestamps for ready
Metro releaseEbsTimestamp
void process_go_signal()
Processes the go signal.