Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
digitalSender.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "metro.h"
4#include <Arduino.h>
5#include "digitalSettings.hpp"
6
15private:
16 Metro _blinkTimer{LED_BLINK_INTERVAL};
17 Metro _watchdogTimer{WD_PULSE_INTERVAL_MS};
18
22 static void turnOffASSI();
23
24public:
25 // Array of valid output pins
35
42 for (const auto pin: validOutputPins) {
43 pinMode(pin, OUTPUT);
44 }
45 }
46
50 static void openSDC();
51
55 static void closeSDC();
56
60 static void activateEBS();
61
65 static void deactivateEBS();
66
71
75 static void enterManualState();
76
80 static void enterOffState();
81
85 static void enterReadyState();
86
90 void enterDrivingState();
91
95 static void enterFinishState();
96
101 void blinkLED(int pin);
102
106 void toggleWatchdog();
107};
108
110 digitalWrite(SDC_LOGIC_CLOSE_SDC_PIN, LOW);
111 digitalWrite(MASTER_SDC_OUT_PIN, LOW);
112}
113
115 digitalWrite(SDC_LOGIC_CLOSE_SDC_PIN, HIGH);
116 digitalWrite(MASTER_SDC_OUT_PIN, HIGH);
117}
118
120 digitalWrite(EBS_VALVE_1_PIN, HIGH);
121 digitalWrite(EBS_VALVE_2_PIN, HIGH);
122}
123
125 digitalWrite(EBS_VALVE_1_PIN, LOW);
126 digitalWrite(EBS_VALVE_2_PIN, LOW);
127}
128
129inline void DigitalSender::turnOffASSI() {
130 analogWrite(ASSI_YELLOW_PIN, LOW);
131 analogWrite(ASSI_BLUE_PIN, LOW);
132}
133
135 turnOffASSI();
136 _blinkTimer.reset();
137 activateEBS();
138 openSDC();
139}
140
142 turnOffASSI();
144 closeSDC();
145}
146
148 turnOffASSI();
150 openSDC();
151}
152
154 turnOffASSI();
155 analogWrite(ASSI_YELLOW_PIN, 1023); // Analog works better
156 activateEBS();
157 closeSDC();
158}
159
161 turnOffASSI();
162 _blinkTimer.reset();
164 closeSDC();
165}
166
168 turnOffASSI();
169 analogWrite(ASSI_BLUE_PIN, 1023); // Analog works better
170 activateEBS();
171 openSDC();
172}
173
174inline void DigitalSender::blinkLED(const int pin) {
175 static bool blinkState = false;
176 if (_blinkTimer.check()) {
177 blinkState = !blinkState;
178 analogWrite(pin, blinkState * 1023); // Analog works better
179 }
180}
181
183 static bool watchdogState = false;
184 if (_watchdogTimer.check()) {
185 watchdogState = !watchdogState;
186 digitalWrite(SDC_LOGIC_WATCHDOG_OUT_PIN, watchdogState);
187 _watchdogTimer.reset();
188 }
189}
Class responsible for controlling digital outputs in the Master Teensy.
static constexpr std::array< int, 9 > validOutputPins
static void enterReadyState()
ASSI yellow LED on, ebs valves activated, sdc closed.
DigitalSender()
Constructor for the DigitalSender class.
static void deactivateEBS()
Deactivates the solenoid EBS valves.
void toggleWatchdog()
Toggles the watchdog pin, to ensure certify of masters' liveness.
static void enterFinishState()
ASSI blue LED on, ebs valves activated, sdc open.
static void closeSDC()
Closes the SDC in Master and SDC Logic.
static void enterOffState()
Everything off, sdc open.
void enterDrivingState()
ASSI LEDs yellow flashing, ebs valves deactivated, sdc closed.
void enterEmergencyState()
ASSI LEDs blue flashing, sdc open and buzzer ringing.
static void activateEBS()
Activates the solenoid EBS valves.
static void enterManualState()
Everything off, sdc closed.
static void openSDC()
Opens the SDC in Master and SDC Logic.
void blinkLED(int pin)
Blinks the LED at the given pin.
Our own implementation of Metro class.
Definition metro.h:13
void reset()
Resets the timer to the current time.
Definition metro.h:125
bool check()
Checks if the interval has passed and resets the timer if true.
Definition metro.h:91
#define SDC_LOGIC_CLOSE_SDC_PIN
#define EBS_VALVE_2_PIN
#define WD_PULSE_INTERVAL_MS
#define EBS_VALVE_1_PIN
#define SDC_LOGIC_WATCHDOG_OUT_PIN
#define MASTER_SDC_OUT_PIN
#define LED_BLINK_INTERVAL
#define ASSI_BLUE_PIN
#define ASSI_YELLOW_PIN