-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
100 lines (76 loc) · 2.75 KB
/
main.cpp
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
#include <main.h>
//Construct instances of robot systems and sequences
Sensors sensors = Sensors();
Drivetrain drivetrain = Drivetrain(sensors);
Arm arm = Arm(sensors);
DriveRoutes routes = DriveRoutes(drivetrain);
TaskSequences tasks = TaskSequences(drivetrain, arm);
//Define RCS constants
int leverNo = 0;
const char *teamKey = "A6TTeNLB5";
int initialize();
int main(void){
//Define time and state control variables
int step = 0, timeStep = 0;
long startTime = TimeNowMSec(), timeStamp = TimeNowMSec();
//Connect to RCS
initialize();
int x = 0, y = 0;
//Wait for start light or touch (for testing purposes only)
while(!sensors.isRed() && !LCD.Touch(&x,&y)){
//Display CDS data to check calibration
LCD.WriteLine(sensors.getRawColor());
Sleep(1);
}
//Main robot loop: Run until timeout or shutdown
while(TimeNowMSec() - startTime < MAX_TIME){
//Display robot state
LCD.WriteLine(step);
//Reset timing control after a time-controlled step has executed (Such a step was not used in the final main loop)
if(timeStep != step){
timeStep = step;
timeStamp = TimeNowMSec();
}
//Execute a sequence of commands based on robot state
switch(step){
case 0:
step = 1; //Skip the 0th step
break;
case 1:
step += routes.startToLuggage(); //Press start button and deposit luggage
break;
case 2:
step += routes.luggageToLevers(leverNo); //Move from luggage depot to fuel levers
break;
case 3:
step += tasks.fuelLever(leverNo); //Flip fuel lever task
break;
case 4:
step += routes.leversToKiosk(); //Move from fuel levers to kiosk button press
break;
case 5:
step += routes.kioskToPassport(); //Move from kiosk to in front of passport
break;
case 6:
step += tasks.stampPassport(); //Stamp passport task
break;
case 7:
step += routes.passportToFinal(); //Move from passport to hit final button
break;
case 8: //Stop all motors
arm.stop();
drivetrain.stop();
break;
}
//Wait min cycle time to reduce unnecessary load on proteus
Sleep(1);
}
//Success error code
return 0;
}
//Connect to RCS and run RCS initialization
int initialize(){
RCS.InitializeTouchMenu(teamKey);
leverNo = RCS.GetCorrectLever();
return 1;
}