-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_front.c
165 lines (143 loc) · 4.28 KB
/
main_front.c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include types.h
// Dummy values for now
const float HEADLIGHT_THRESHOLD = 123456789;
const float TURNLIGHT_ROLL_LEFT_THRESHOLD = -123456789;
const float TURNLIGHT_ROLL_RIGHT_THRESHOLD = 123456789;
const float TURNLIGHT_YAW_LEFT_THRESHOLD = -123456789;
const float TURNLIGHT_YAW_RIGHT_THRESHOLD = 123456789;
// configure initial state
head_light_state_t head_light_state = OFF;
turn_light_state_t turn_light_state = OFF;
navigation_state_t nav_state = OFF;
// global variables
struct navigation_update_t nav_update;
float dst;
char loc[64];
// booleans to be set by BLE interrupt handler for maps API
bool start_nav = false;
bool stop_nav = false;
bool update_nav = false;
// Initialize senors here
// Initialize BLE, connect to BACK module
// TODO: handle BLE notification with interrrupt, set boolean values, or update with new instruction
int main(void) {
// Initialize EVERYTHING - Left blank for now
// Board, different sensors, display, etc
// FSMs GO HERE ===================================================================
// FSM for headlight
switch (head_light_state) {
case OFF: {
// If current light is above threshold
if () {
// TURN LIGHT ON
head_light_state = ON;
} else {
// KEEP LIGHT OFF
head_light_state = OFF;
}
}
case ON: {
// If current light is below threshold
if () {
// TURN LIGHT OFF
head_light_state = OFF;
} else {
// KEEP LIGHT ON
head_light_state = ON;
}
}
}
// FSM for turnlights.
switch (turn_light_state) {
case OFF: {
if () {
// If current roll and yaw are less than left thresholds
// Will call function to handle lights to blink
turn_light_state = LEFT;
// Send update to BACK module
} else if () {
// If current roll and yaw are greater than right thresholds
// Will call function to handle lights to blink
turn_light_state = RIGHT;
// Send update to BACK module
} else {
// If neither, then not turning
turn_light_state = OFF;
// Send update to BACK module
}
}
case LEFT: {
if () {
// If current roll and yaw are less than left thresholds
// Will call function to handle lights to blink
turn_light_state = LEFT;
// Send update to BACK module
} else if () {
// If current roll and yaw are greater than right thresholds
// Will call function to handle lights to blink
turn_light_state = RIGHT;
// Send update to BACK module
} else {
// If neither, then not turning
turn_light_state = OFF;
// Send update to BACK module
}
}
case RIGHT: {
if () {
// If current roll and yaw are less than left thresholds
// Will call function to handle lights to blink
turn_light_state = LEFT;
// Send update to BACK module
} else if () {
// If current roll and yaw are greater than right thresholds
// Will call function to handle lights to blink
turn_light_state = RIGHT;
// Send update to BACK module
} else {
// If neither, then not turning
turn_light_state = OFF;
// Send update to BACK module
}
}
}
// FSM for nav system
switch (nav_state) {
case OFF: {
// If we recieve a BLE notification from the phone to start navigation
dst = 0.0;
loc = "";
if (start_nav) {
// Start navigating
nav_state = ON;
start_nav = false;
} else {
// Remain with no navigataion
head_light_state = OFF;
}
}
case ON: {
// If we recieve arrived notification from the phone, stop navigation
if (stop_nav) {
// Turn off navigation
nav_state = OFF;
stop_nav = false;
}
if (update_nav) {
// Keep navigation on
nav_state = ON;
update_nav = false;
// parse update
dst = nav_update.dst;
loc = nav_update.loc;
// update display to show new turn location, new distance
} else {
// Keep navigation on
nav_state = ON;
// Update distance
dst = update_distance(); // TODO: define function
// Refresh display
}
}
}
}