-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBrakes.cpp
More file actions
70 lines (63 loc) · 1.99 KB
/
Brakes.cpp
File metadata and controls
70 lines (63 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Settings.h"
#include "Brakes.h"
#ifndef TESTING
#include <Arduino.h>
#endif
Brakes::Brakes(){
pinMode( BrakeOnPin, OUTPUT);
pinMode( BrakeVoltPin, OUTPUT);
clock_hi_ms = millis();
state = BR_OFF;
Release();
if(DEBUG)
Serial.println("Brake Setup Complete");
}
/* Expected behavior:
* LEDs go off for relays 2 and 3;
* Relay 2 has NO (connected to solenoids) open, and there is no power to solenoids.
* Relay 3 connects COM (other end of solenoid) to NO (12V)
*/
void Brakes::Release(){
if (DEBUG)
//Serial.println("release");
digitalWrite(BrakeOnPin, RELAYInversion ? HIGH : LOW);
digitalWrite(BrakeVoltPin, RELAYInversion ? HIGH : LOW);
noInterrupts();
state = BR_OFF;
interrupts();
}
/* Expected behavior:
* Both LEDs come on for Relays 2 and 3
* Relay 2 connects NO (solenoids) to COM (ground)
* Relay 3 connects COM (other end of solenoids) to NC (36V)
*/
void Brakes::Stop(){
noInterrupts();
digitalWrite(BrakeVoltPin, RELAYInversion ? LOW :HIGH); // Need the higher voltage to activate the solenoid.
if (state != BR_HI_VOLTS){
clock_hi_ms = millis(); // keep track of when the higher voltage was applied.
}
digitalWrite(BrakeOnPin, RELAYInversion ? LOW : HIGH); // Activate solenoid to apply brakes.
state = BR_HI_VOLTS;
interrupts();
}
/* Expected behavior
* If 36V has been on too long, relay 3 changes LED on to off, switching from 24 to 12V
* If the switch is high, brakes will be released, with both LEDs off.
*/
void Brakes::Update(){
noInterrupts();
brake_state tempState = state;
uint32_t tempClock = clock_hi_ms;
interrupts();
unsigned long tick = millis();
if (tempState == BR_HI_VOLTS && tick - tempClock > MaxHi_ms){
// Have reached maximum time to keep voltage high
if (DEBUG)
Serial.println("BRAKE SWITCH");
digitalWrite(BrakeVoltPin, RELAYInversion ? HIGH : LOW); // Set to lower voltage, which will keep brakes applied
noInterrupts();
state = BR_LO_VOLTS;
interrupts();
}
}