-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanson_main_skeleton.c
99 lines (86 loc) · 2.74 KB
/
anson_main_skeleton.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
// NOTE: THIS FILE IS JUST BARE SKELETON FOR THE HEAD AND TURN LIGHTS
// WILL BE INTEGRATED INTO COMPLETE FILE
#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
light_state_t light_state = OFF;
turn_light_state_t turn_light_state = OFF;
// Initialize senors here
int main(void) {
// Initialize EVERYTHING - Left blank for now
// Board, different sensors, display, etc
// FSMs GO HERE ===================================================================
// FSM for headlight -- Note: We can simplify this, as we don't really need a FSM...
switch (light_state) {
case OFF: {
// If current light is above threshold
if () {
// TURN LIGHT ON
light_state = ON;
} else {
// KEEP LIGHT OFF
light_state = OFF;
}
}
case ON: {
// If current light is below threshold
if () {
// TURN LIGHT OFF
light_state = OFF;
} else {
// KEEP LIGHT ON
light_state = ON;
}
}
}
// FSM for turnlights. Again it seems like each state has the same thing...
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;
} else if () {
// If current roll and yaw are greater than right thresholds
// Will call function to handle lights to blink
turn_light_state = RIGHT;
} else {
// If neither, then not turning
turn_light_state = OFF:
}
}
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;
} else if () {
// If current roll and yaw are greater than right thresholds
// Will call function to handle lights to blink
turn_light_state = RIGHT;
} else {
// If neither, then not turning
turn_light_state = OFF:
}
}
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;
} else if () {
// If current roll and yaw are greater than right thresholds
// Will call function to handle lights to blink
turn_light_state = RIGHT;
} else {
// If neither, then not turning
turn_light_state = OFF:
}
}
}
}