Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
integration_test.hpp
Go to the documentation of this file.
1#include "Arduino.h"
2
3#define GREEN_LED_1 4
4#define GREEN_LED_2 5
5#define GREEN_LED_3 6
6#define RED_LED_1 0
7#define RED_LED_2 1
8#define YELLOW_LED_1 2
9#define YELLOW_LED_2 3
10#define BUTTON_1 7
11#define BUTTON_2 8
12#define BUTTON_3 9
13#define BUTTON_4 10
14#define BUTTON_5 11
15#define BUTTON_6 12
16#define POTENCIO 14
17
18#undef R2D_PIN
19
20#define BK_SENSOR_PIN POTENCIO
21#define R2D_PIN BUTTON_1
22#define TSON_PIN BUTTON_2
23#define AS_READY_PIN BUTTON_3
24#define STOP_PIN BUTTON_4
25#define STATE_IDLE_GREEN_LED_1_PIN GREEN_LED_1
26#define STATE_IDLE_GREEN_LED_2_PIN GREEN_LED_2
27#define STATE_IDLE_GREEN_LED_3_PIN GREEN_LED_3
28#define STATE_DRIVING_RED_LED_1_PIN RED_LED_1
29#define STATE_DRIVING_RED_LED_2_PIN RED_LED_2
30#define STATE_ASDRIVING_YELLOW_LED_1_PIN YELLOW_LED_1
31#define STATE_ASDRIVING_YELLOW_LED_2_PIN YELLOW_LED_2
32
33extern volatile bool TSOn;
34extern volatile bool ASReady;
35extern volatile uint16_t brakeValue;
36
37elapsedMillis print_timer;
38
58{
59 uint16_t brakeValue = analogRead(BK_SENSOR_PIN);
60 if (brakeValue > 165)
61 R2DTimer = 0;
62}
63
65{
66 TSOn = not digitalRead(TSON_PIN);
67}
68
70{
71 ASReady = not digitalRead(AS_READY_PIN);
72}
73
75{
76 pinMode(BK_SENSOR_PIN, INPUT);
77 pinMode(R2D_PIN, INPUT);
78 pinMode(TSON_PIN, INPUT);
79 pinMode(AS_READY_PIN, INPUT);
80 pinMode(STATE_IDLE_GREEN_LED_1_PIN, OUTPUT);
81 pinMode(STATE_IDLE_GREEN_LED_2_PIN, OUTPUT);
82 pinMode(STATE_IDLE_GREEN_LED_3_PIN, OUTPUT);
83 pinMode(STATE_DRIVING_RED_LED_1_PIN, OUTPUT);
84 pinMode(STATE_DRIVING_RED_LED_2_PIN, OUTPUT);
85 pinMode(STATE_ASDRIVING_YELLOW_LED_1_PIN, OUTPUT);
86 pinMode(STATE_ASDRIVING_YELLOW_LED_2_PIN, OUTPUT);
87
88 // attachInterrupt(digitalPinToInterrupt(BK_SENSOR_PIN),brakeValueUpdate,CHANGE);
89 attachInterrupt(digitalPinToInterrupt(TSON_PIN), updateTS, CHANGE);
90 attachInterrupt(digitalPinToInterrupt(AS_READY_PIN), updateASReady, CHANGE);
91
92 print_timer = 0;
93}
94
95void state_light(int state)
96{
97 switch (state)
98 {
99 case 0: // idle
100 digitalWrite(STATE_IDLE_GREEN_LED_1_PIN, HIGH);
101 digitalWrite(STATE_IDLE_GREEN_LED_2_PIN, HIGH);
102 digitalWrite(STATE_IDLE_GREEN_LED_3_PIN, HIGH);
103 digitalWrite(STATE_DRIVING_RED_LED_1_PIN, LOW);
104 digitalWrite(STATE_DRIVING_RED_LED_2_PIN, LOW);
105 digitalWrite(STATE_ASDRIVING_YELLOW_LED_1_PIN, LOW);
106 digitalWrite(STATE_ASDRIVING_YELLOW_LED_2_PIN, LOW);
107 break;
108 case 1: // Driving
109 digitalWrite(STATE_IDLE_GREEN_LED_1_PIN, LOW);
110 digitalWrite(STATE_IDLE_GREEN_LED_2_PIN, LOW);
111 digitalWrite(STATE_IDLE_GREEN_LED_3_PIN, LOW);
112 digitalWrite(STATE_DRIVING_RED_LED_1_PIN, HIGH);
113 digitalWrite(STATE_DRIVING_RED_LED_2_PIN, HIGH);
114 digitalWrite(STATE_ASDRIVING_YELLOW_LED_1_PIN, LOW);
115 digitalWrite(STATE_ASDRIVING_YELLOW_LED_2_PIN, LOW);
116 break;
117 case 2: // ASDriving
118 digitalWrite(STATE_IDLE_GREEN_LED_1_PIN, LOW);
119 digitalWrite(STATE_IDLE_GREEN_LED_2_PIN, LOW);
120 digitalWrite(STATE_IDLE_GREEN_LED_3_PIN, LOW);
121 digitalWrite(STATE_DRIVING_RED_LED_1_PIN, LOW);
122 digitalWrite(STATE_DRIVING_RED_LED_2_PIN, LOW);
123 digitalWrite(STATE_ASDRIVING_YELLOW_LED_1_PIN, HIGH);
124 digitalWrite(STATE_ASDRIVING_YELLOW_LED_2_PIN, HIGH);
125 break;
126 default:
127 break;
128 }
129}
130
131void printVariables(int state)
132{
133 printf("TSOn: %d\n", TSOn);
134 printf("ASReady: %d\n", ASReady);
135 printf("BrakeVal: %d\n", brakeValue);
136 switch (state)
137 {
138 case 0:
139 printf("State light -> IDLE\n");
140 break;
141 case 1:
142 printf("State light -> DRIVING\n");
143 break;
144 case 2:
145 printf("State light -> ASDRIVING\n");
146 break;
147 default:
148 break;
149 }
150}
151
153{
156 if (print_timer > 1000)
157 {
158 print_timer = 0;
159 printf("---------------\n");
161 printf("TSON READ: %d\n", digitalRead(TSON_PIN));
162 printf("Brake sensor: %d\n", analogRead(BK_SENSOR_PIN));
163 }
164}
void printVariables(int state)
#define STATE_ASDRIVING_YELLOW_LED_2_PIN
volatile bool ASReady
Definition main.cpp:22
void integrationtest(int R2DStatus)
#define STATE_IDLE_GREEN_LED_1_PIN
void updateTS()
void testing_setup()
void updateASReady()
elapsedMillis print_timer
volatile bool TSOn
Definition main.cpp:19
#define STATE_DRIVING_RED_LED_2_PIN
#define STATE_DRIVING_RED_LED_1_PIN
#define TSON_PIN
#define STATE_IDLE_GREEN_LED_3_PIN
#define STATE_ASDRIVING_YELLOW_LED_1_PIN
void brakeValueUpdate()
Integration test.
volatile uint16_t brakeValue
Definition apps.cpp:11
#define R2D_PIN
void state_light(int state)
#define BK_SENSOR_PIN
#define STATE_IDLE_GREEN_LED_2_PIN
#define AS_READY_PIN
status R2DStatus
elapsedMillis R2DTimer
Definition main.cpp:44