This repository has been archived by the owner on Feb 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RobotCode_AutoOnly.c
146 lines (136 loc) · 3.88 KB
/
RobotCode_AutoOnly.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
#pragma config(Motor, port2, leftMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, rightMotor, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port4, liftMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, swivelMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, clawMotor, tmotorVex393_MC29, openLoop)
#pragma config(Sensor, dgtl10, redLED, sensorLEDtoVCC)
#pragma config(Sensor, dgtl11, yellowLED, sensorLEDtoVCC)
#pragma config(Sensor, dgtl12, greenLED, sensorLEDtoVCC)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#pragma platform(VEX2)
/*-----------------------------------------------------------------------------------
Robot code for GHS VEX Team G
2018-19 Competiton Season
Team members are Lucas Ritzdorf, Riker Foster, and Lauryn Vornbrock.
This version of the robot code is intended to be used exclusively for testing
purposes. For that reason, it is not equipped to interact with the competition
control system, and will immediately start the AUTONOMOUS portion of the code.
-----------------------------------------------------------------------------------*/
// Variable Definitions
const float turnTime = 1000;
float clawTime = 500;
int clawDir = -1;
float liftTime = 3000;
int liftDir = 1;
// Task to open or close the claw concurrently
task claw()
{
setMotor(clawMotor, clawDir*127);
sleep(clawTime);
stopMotor(clawMotor);
}
// Task to raise or lower the lift concurrently
task lift()
{
setMotor(liftMotor, liftDir*127);
sleep(liftTime);
stopMotor(liftMotor);
}
task auto()
{
turnLEDOff(redLED);
turnLEDOn(yellowLED);
// Turn left
setMotor(leftMotor, -24);
setMotor(rightMotor, 64);
sleep(750);
setMotor(leftMotor, -96);
sleep(400); // To a right angle
sleep(100); // Angled slightly toward the wall
stopMultipleMotors(leftMotor, rightMotor);
// Drive forwards
setMultipleMotors(127, leftMotor, rightMotor);
sleep(1750);
// Turn slightly right and drive forwards
setMotor(leftMotor, 64);
stopMotor(rightMotor);
sleep(500);
setMotor(rightMotor, 64);
sleep(1000);
// Back up and turn (and open claw)
clawDir = -1; startTask(claw); clearTimer(T1);
setMotor(leftMotor, -127);
setMotor(rightMotor, -32);
sleep(1500);
// Back up
setMultipleMotors(leftMotor, rightMotor, -127);
sleep(1500);
// Turn right
motor[leftMotor] = 127;
motor[rightMotor] = -127;
sleep(turnTime+500);
// Drive forwards (after the claw has opened)
while(time1[T1] < clawTime) { sleep(0.1); }
setMultipleMotors(64, leftMotor, rightMotor);
sleep(1500);
// Flip the cap
setMultipleMotors(32, leftMotor, rightMotor);
setMotor(liftMotor, 127);
sleep(1500);
stopAllMotors();
sleep(250);
// Back up and lower lift
liftDir = -1; liftTime = 3; startTask(lift); clearTimer(T2);
setMultipleMotors(-127, leftMotor, rightMotor);
sleep(1750);
// Turn right
setMotor(leftMotor, 127);
setMotor(rightMotor, -127);
sleep(turnTime);
// Drive forward
setMultipleMotors(127, leftMotor, rightMotor);
sleep(1000);
// Turn left
setMotor(leftMotor, -127);
setMotor(rightMotor, 127);
sleep(turnTime);
// Drive forward
setMultipleMotors(127, leftMotor, rightMotor);
sleep(2500);
// Lift the cap
setMotor(liftMotor, 64);
setMultipleMotors(32, leftMotor, rightMotor);
sleep(1000);
// Turn and set the cap down
setMotor(leftMotor, -32);
setMotor(rightMotor, 16);
sleep(2000);
// Done
stopAllMotors();
turnLEDOff(greenLED);
turnLEDOn(yellowLED);
}
// Emergency-stop task
task e_stop()
{
while(true) {
if (vexRT[Btn8L] == 1) {
turnLEDOff(yellowLED);
turnLEDOn(redLED);
stopTask(auto);
stopAllMotors();
}
sleep(0.1);
}
}
task main()
{
turnLEDOff(redLED);
turnLEDOff(yellowLED);
turnLEDOff(greenLED);
startTask(e_stop);
while(true) {
if (vexRT[Btn8R] == 1) { startTask(auto); }
sleep(100);
}
}