-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRobotControlEPO2.c
107 lines (80 loc) · 2.83 KB
/
RobotControlEPO2.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
/* Include built in library's */
#include <stdio.h>
#include <stdlib.h>
#include "rs232.c" /* Include serial library */
#include "support.c"
#include "route.c"
#include "communication.c"
#define PRODUCT_VERSION "1.5"
/* Define and initialize variables */
int map[13][13] =
{
{ -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1},
{ -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1},
{ -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1},
{ -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1},
{ -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1},
{ -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1},
{ -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1}
};
int waypoints[4][3], route[100][4], routeLength, robotDone = 0, numWaypoints;
char challengeType;
/* Read start point and 3 end points from the user */
void readInput () {
int rawInput[4], i;
printf("\n\nEnter first the starting point, and then 3 destinations:\n");
for(i = 0; i < 4; i++) {
scanf("%d", &rawInput[i]);
if (rawInput[i] > -1 && rawInput[i] < 13) {
waypoints[i][0] = yPos(rawInput[i]);
waypoints[i][1] = xPos(rawInput[i]);
waypoints[i][2] = richtingStation(rawInput[i]);
} else {
printf("Please check your input!\nTry again: ");
i--;
}
}
}
/* Read which challenge is going to happen */
void readChallenge () {
char inChar;
printf("Please enter the challenge the robot has to complete ('A' or 'B'): ");
scanf("%c", &inChar);
if (inChar == 'a' || inChar == 'A') {
challengeType = 'A';
} else if (inChar == 'b' || inChar == 'B') {
challengeType = 'B';
} else if (inChar == 'c' || inChar == 'C') {
printf("Not yet implemented!\n");
readChallenge();
} else {
printf("Invalid input! Please try again:\n");
readChallenge();
}
}
/* The main program function, which calls other functions */
int main()
{
printf("\nEPO2 Maze router %s\n\n", PRODUCT_VERSION);
printf("Opening serial port:\n");
setupSerial();
readChallenge();
readInput();
printWaypoints();
while (!robotDone) {
sortWaypoints();
printWaypoints();
fillRouteArray();
printRoute();
driveRoute();
}
printf("\nEnd of route! Program exiting :( Bye!\n\n");
stopSerial();
return 0;
}