-
Notifications
You must be signed in to change notification settings - Fork 0
/
competitionV3.0
246 lines (218 loc) · 7.54 KB
/
competitionV3.0
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#pragma config(Motor, port2, frontRightMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor, port3, backRightMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor, port4, frontLeftMotor, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port5, backLeftMotor, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port6, claw, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port7, tilter, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor, port8, elevatorR, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor, port9, elevatorL, tmotorServoContinuousRotation, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*---------------------------------------------------------------------------*/
/* */
/* Description: Competition template for VEX EDR */
/* */
/*---------------------------------------------------------------------------*/
// This code is for the VEX cortex platform
#pragma platform(VEX2)
// Select Download method as "competition"
#pragma competitionControl(Competition)
#pragma autonomousDuration(15)
#pragma userControlDuration(120)
//Main competition background code...do not modify!
#include "Vex_Competition_Includes.c"
/*---------------------------------------------------------------------------*/
/* Pre-Autonomous Functions */
/* */
/* You may want to perform some actions before the competition starts. */
/* Do them in the following function. You must return from this function */
/* or the and usercontrol tasks will not be started. This */
/* function is only called once after the cortex has been powered on and */
/* not every time that the robot is disabled. */
/*---------------------------------------------------------------------------*/
void forward(){//moves robot forward
motor[frontRightMotor] = -120;
motor[backRightMotor] = -120;
motor[frontLeftMotor] = -120;
motor[backLeftMotor] = -120;
}
void backward(){//moves robot backwards
motor[frontRightMotor] = 120;
motor[backRightMotor] = 120;
motor[frontLeftMotor] = 120;
motor[backLeftMotor] = 120;
}
/* void left(){
motor[frontRightMotor] = 70;
motor[backRightMotor] = 70;
motor[frontLeftMotor] = -70;
motor[backLeftMotor] = -70;
}
void right(){
motor[frontRightMotor] = -70;
motor[backRightMotor] = -70;
motor[frontLeftMotor] = 70;
motor[backLeftMotor] = 70;
}*/
void turnRight(){//rotates the robot right
motor[frontRightMotor] = 120;
motor[backRightMotor] = 120;
motor[frontLeftMotor] = -120;
motor[backLeftMotor] = -120;
}
void turnLeft(){//rotates the robot left
motor[frontRightMotor] = -120;
motor[backRightMotor] = -120;
motor[frontLeftMotor] = 120;
motor[backLeftMotor] = 120;
}
void elevate(){//raises the forklift up to is maximum point (takes max 1.5s)
clearTimer(T1);
while(time1[T1] < 1200){
motor[elevatorR] = 120;
motor[elevatorL] = 120;
}
motor[elevatorR] = 0;
motor[elevatorL] = 0;
}
void elevateDown(){//lowers the forklift to its neutral position (takes max 1.4s)
clearTimer(T2);
while(time1[T2] < 1100){
motor[elevatorR] = -120;
motor[elevatorL] = -120;
}
motor[elevatorR] = 0;
motor[elevatorL] = 0;
}
void tilt(){//tilts the forklift up
clearTimer(T3);
while(time1[T3] < 500){
motor[tilter] = 70;
}
motor[tilter] = 0;
}
void tiltDown(){//tilts the forklift down to pick up stuff
clearTimer(T3);
while(time1[T3] < 500){
motor[tilter] = -70;
}
motor[tilter] = 0;
}
void grab(){//snaps the clamps together to 'grab' the thing
motor[claw] = 70;
}
void release(){//release the clamp
clearTimer(T4);
while(time1[T4] < 500){
motor[claw] = -70;
}
motor[claw] = 0;
}
void stopMotors() {//stops all motors
motor[frontRightMotor] = 0;
motor[backRightMotor] = 0;
motor[frontLeftMotor] = 0;
motor[backLeftMotor] = 0;
motor[claw] = 0;
motor[tilter] = 0;
motor[elevatorR] = 0;
motor[elevatorL] = 0;
}
void pre_auton()
{
// Set bStopTasksBetweenModes to false if you want to keep user created tasks
// running between Autonomous and Driver controlled modes. You will need to
// manage all user created tasks if set to false.
bStopTasksBetweenModes = true;
stopMotors();
// Set bDisplayCompetitionStatusOnLcd to false if you don't want the LCD
// used by the competition include file, for example, you might want
// to display your team name on the LCD in this function.
// bDisplayCompetitionStatusOnLcd = false;
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...
}
/*---------------------------------------------------------------------------*/
/* */
/* Autonomous Task */
/* */
/* This task is used to control your robot during the autonomous phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
task autonomous()
{
clearTimer(T4);
while(time1[T4] < 2000){
forward();
}
clearTimer(T1);
while(time1[T1] < 500){
turnLeft();
}
elevate();
for(int i=0; i < 4; i++){
clearTimer(T3);
while(time1[T3] < 200){
backward();
}
clearTimer(T3);
while(time1[T3] < 200){
forward();
}
}//causes jerking motion which flips the tilter
tilt();
clearTimer(T2);
while(time1[T2] < 2500){
forward();
}
}
/*---------------------------------------------------------------------------*/
/* */
/* User Control Task */
/* */
/* This task is used to control your robot during the user control phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
task usercontrol()
{
// User control code here, inside the loop
while (true)
{
if(vexRT[Btn7U] == 1){
forward();
}
/*if(vexRT[Btn7L] == 1){
left();
}
if(vexRT[Btn7R] == 1){
right();
}*/
if(vexRT[Btn7D] == 1){
backward();
}
if(vexRT[Btn8L] == 1){
turnLeft();
}
if(vexRT[Btn8R] == 1){
turnRight();
}
if(vexRT[Btn5U] == 1){
elevate();
tilt();
}
if(vexRT[Btn5D] == 1){
elevateDown();
tiltDown();
}
if(vexRT[Btn7D] == 1){
grab();
}
if(vexRT[Btn7U] == 1){
release();
}
stopMotors();
}
}