-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.c
More file actions
76 lines (71 loc) · 2.05 KB
/
state.c
File metadata and controls
76 lines (71 loc) · 2.05 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
71
72
73
74
75
#include "state.h"
#include "motor_logic.h"
#include "states.h"
#include "script.h"
#include "input.h"
#include <string.h>
#include <stdlib.h>
/* private method */
bool is_State(char * state_name, State * cs) {
if (strcmp(state_name, cs->state_name) == 0) return true;
return false;
}
void set_State(char * name, State * current) {
/* TODO: for some reason is broken */
for (int i = 0; i < MAX_STATES; i++) {
if (is_State(name, &STATES[i])) {
*current = STATES[i];
return;
}
}
/* impossible code path */
}
void populate_States(State * next_states) {
// TODO: implement all states
}
void execute_State(Robot * robot, State * current_state) {
/* do the action associated the the current state */
if (is_State("move_forward", current_state)) {
move_Forward(robot, current_state);
}
else if (is_State("start", current_state)) {
start_Robot(robot, current_state);
}
else if (is_State("turn_right", current_state)) {
turn_Right(robot, current_state);
}
else if (is_State("turn_left", current_state)) {
turn_Left(robot, current_state);
}
else if (is_State("reverse_robot", current_state)) {
reverse_Robot(robot, current_state);
}
else if (is_State("reverse_right", current_state)) {
reverse_Right(robot, current_state);
}
else if (is_State("reverse_left", current_state)) {
reverse_Left(robot, current_state);
}
else if (is_State("delay_robot", current_state)) {
delay_Robot(robot, current_state);
}
else if (is_State("stop_robot", current_state)) {
stop_Robot(robot, current_state);
}
else if (is_State("correct_right", current_state)) {
correct_Right(robot, current_state);
}
else if (is_State("correct_left", current_state)) {
correct_Left(robot, current_state);
}
else if (is_State("turn_around", current_state)) {
turn_Around(robot, current_state);
}
else if (is_State("goal", current_state)) {
victory_Dance(robot, current_state);
}
else {
/* This else block should be unreachable */
/* TODO: implement some sort of error reporting */
}
}