Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
test_C3.cpp
Go to the documentation of this file.
1#include "unity.h"
2#include "statemachine.hpp"
3#include "Arduino.h"
4
5#define GREEN_LED_1 4
6#define GREEN_LED_2 5
7#define GREEN_LED_3 6
8#define RED_LED_1 0
9#define RED_LED_2 1
10#define YELLOW_LED_1 2
11#define YELLOW_LED_2 3
12#define BUTTON_1 7
13#define BUTTON_2 8
14#define BUTTON_3 9
15#define BUTTON_4 10
16#define BUTTON_5 11
17#define BUTTON_6 12
18#define POTENCIO 14
19
20#undef R2D_PIN
21
22#define BK_SENSOR_PIN POTENCIO
23#define R2D_PIN BUTTON_1
24#define TSON_PIN BUTTON_2
25#define AS_READY_PIN BUTTON_3
26#define STOP_PIN BUTTON_4
27#define STATE_IDLE_GREEN_LED_1_PIN GREEN_LED_1
28#define STATE_IDLE_GREEN_LED_2_PIN GREEN_LED_2
29#define STATE_IDLE_GREEN_LED_3_PIN GREEN_LED_3
30#define STATE_DRIVING_RED_LED_1_PIN RED_LED_1
31#define STATE_DRIVING_RED_LED_2_PIN RED_LED_2
32#define STATE_ASDRIVING_YELLOW_LED_1_PIN YELLOW_LED_1
33#define STATE_ASDRIVING_YELLOW_LED_2_PIN YELLOW_LED_2
34
35volatile bool TSOn;
36
37
38
39
41 uint16_t brakeValue = analogRead(BK_SENSOR_PIN);
42 if (brakeValue > 165)
43 R2DTimer = 0;
44}
45
46void updateTS(){
47 TSOn = not digitalRead(TSON_PIN);
48}
49
51 ASReady = not digitalRead(AS_READY_PIN);
52}
53
54void stopTest(){
55 if (not digitalRead(STOP_PIN))
56 TEST_ASSERT(1 == 1);
57
58}
59
61 while(1){
63 }
64}
65
68 TSOn = true;
69 while(R2DStatus != DRIVING){
71 Serial.println(R2DStatus);
72 }
73 TEST_ASSERT_EQUAL(DRIVING, R2DStatus);
74}
75
78 TSOn = true;
79 ASReady = true;
81 TEST_ASSERT_EQUAL(ASDRIVING, R2DStatus);
82}
83
86 TSOn = false;
88 TEST_ASSERT_EQUAL(IDLE, R2DStatus);
89}
90
93 TSOn = false;
95 TEST_ASSERT_EQUAL(IDLE, R2DStatus);
96}
97
98void Setup(){
99 Serial.begin(9600);
100
101 pinMode(BK_SENSOR_PIN, INPUT);
102 pinMode(R2D_PIN, INPUT);
103 pinMode(TSON_PIN, INPUT);
104 pinMode(AS_READY_PIN, INPUT);
105 pinMode(STOP_PIN, INPUT);
106 pinMode(STATE_IDLE_GREEN_LED_1_PIN, OUTPUT);
107 pinMode(STATE_IDLE_GREEN_LED_2_PIN, OUTPUT);
108 pinMode(STATE_IDLE_GREEN_LED_3_PIN, OUTPUT);
109 pinMode(STATE_DRIVING_RED_LED_1_PIN, OUTPUT);
110 pinMode(STATE_DRIVING_RED_LED_2_PIN, OUTPUT);
111 pinMode(STATE_ASDRIVING_YELLOW_LED_1_PIN, OUTPUT);
112 pinMode(STATE_ASDRIVING_YELLOW_LED_2_PIN, OUTPUT);
113
114 attachInterrupt(digitalPinToInterrupt(BK_SENSOR_PIN),brakeValueUpdate,CHANGE);
115 attachInterrupt(digitalPinToInterrupt(TSON_PIN),updateTS,CHANGE);
116 attachInterrupt(digitalPinToInterrupt(AS_READY_PIN),updateASReady,CHANGE);
117 attachInterrupt(digitalPinToInterrupt(STOP_PIN),stopTest,CHANGE);
118
119
120 r2dButton.attach(R2D_PIN, INPUT);
121 r2dButton.interval(0.1);
122}
123
124int main(int argc, char **argv) {
125 UNITY_BEGIN();
126 RUN_TEST(test_state_machine);
127 //RUN_TEST(test_DRIVING_2_IDLE);
128 //RUN_TEST(test_IDLE_2_ASDRIVING);
129 //RUN_TEST(test_ASDRIVING_2_IDLE);
130 UNITY_END();
131
132 return 0;
133}
volatile bool ASReady
Definition main.cpp:22
volatile uint16_t brakeValue
Definition apps.cpp:11
@ ASDRIVING
@ DRIVING
@ IDLE
void statemachine()
status R2DStatus
Bounce r2dButton
Definition main.cpp:42
elapsedMillis R2DTimer
Definition main.cpp:44
#define STATE_ASDRIVING_YELLOW_LED_2_PIN
Definition test_C3.cpp:33
#define STATE_IDLE_GREEN_LED_1_PIN
Definition test_C3.cpp:27
void updateTS()
Definition test_C3.cpp:46
void updateASReady()
Definition test_C3.cpp:50
volatile bool TSOn
Definition test_C3.cpp:35
#define STATE_DRIVING_RED_LED_2_PIN
Definition test_C3.cpp:31
#define STOP_PIN
Definition test_C3.cpp:26
void test_IDLE_2_ASDRIVING()
Definition test_C3.cpp:76
#define STATE_DRIVING_RED_LED_1_PIN
Definition test_C3.cpp:30
#define TSON_PIN
Definition test_C3.cpp:24
#define STATE_IDLE_GREEN_LED_3_PIN
Definition test_C3.cpp:29
#define STATE_ASDRIVING_YELLOW_LED_1_PIN
Definition test_C3.cpp:32
void Setup()
Definition test_C3.cpp:98
void brakeValueUpdate()
Definition test_C3.cpp:40
void stopTest()
Definition test_C3.cpp:54
void test_IDLE_2_DRIVING()
Definition test_C3.cpp:66
void test_ASDRIVING_2_IDLE()
Definition test_C3.cpp:84
void test_state_machine()
Definition test_C3.cpp:60
#define R2D_PIN
Definition test_C3.cpp:23
#define BK_SENSOR_PIN
Definition test_C3.cpp:22
void test_DRIVING_2_IDLE()
Definition test_C3.cpp:91
#define STATE_IDLE_GREEN_LED_2_PIN
Definition test_C3.cpp:28
#define AS_READY_PIN
Definition test_C3.cpp:25
int main()