-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBOONIES
More file actions
342 lines (312 loc) · 12.2 KB
/
BOONIES
File metadata and controls
342 lines (312 loc) · 12.2 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
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#pragma config(Motor, port2, LWheel, tmotorServoContinuousRotation, openLoop) //Left Wheel Motor
#pragma config(Motor, port3, RWheel, tmotorServoContinuousRotation, openLoop, reversed) //Right Wheel Motor
#pragma config(Motor, port4, LLift1, tmotorServoContinuousRotation, openLoop) //Left Bottom Lift
#pragma config(Motor, port5, LLift2, tmotorServoContinuousRotation, openLoop) //Left Second Lift
#pragma config(Motor, port6, RLift1, tmotorServoContinuousRotation, openLoop, reversed) //Right Bottom Lift
#pragma config(Motor, port7, RLift2, tmotorServoContinuousRotation, openLoop, reversed) //Right Second Lift
#pragma config(Motor, port8, Claw1, tmotorServoStandard, openLoop) //Claw Motor1
#pragma config(Motor, port9, Claw2, tmotorServoStandard, openLoop, reversed) //Claw Motor2
//Three-wire motors: tmotorVex393
//Two-wire motors: tmotorServoContinuousRotation
#pragma platform(VEX)
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(15)
#pragma userControlDuration(105)
#include "Vex_Competition_Includes.c" //Main competition background code...do not modify!
/////////////////////////////////////////////////////////////////////////////////////////
//
// Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////
void pre_auton()
{
// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
// Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.
bStopTasksBetweenModes = true;
// 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.
//
/////////////////////////////////////////////////////////////////////////////////////////
void stopWheels()
{
motor[LWheel] = 0;
motor[RWheel] = 0;
}
void moveForward()
{
ClearTimer(T1);
while(time1[T1] < 1000) // 1 second: move forward
{
motor[RWheel] = 127;
motor[LWheel] = 127;
}
stopWheels();
}
void moveBackward()
{
ClearTimer(T1);
while(time1[T1] < 1000) // 1 second: move backward
{
motor[RWheel] = -127;
motor[LWheel] = -127;
}
}
task autonomous()
{
// Insert user code here.
// AutonomousCodePlaceholderForTesting(); // Remove this function call once you have "real" code.
// wait1Msec("insert milliseconds"); // Waits for X Milliseconds
// random("insert maxvalue"); // Gets random number from 0 to X max
// wait1Msec(random(5000)); // Wait up to 5 seconds
// motor[RWheel] = random(127); // Chooses Random motor value between -127 and 127
// time1["timer name"] = milliseconds, time10["timer name"] = centiseconds, time100["timer name"] = centiseconds
////////////////////////////////
//START OF AUTONOMOUS
////////////////////////////////
wait1Msec(1000); // Wait 1 second before starting autonomous
moveForward(); // 1 second forward
moveForward();
}
/////////////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////////////
int threshold = 8; // Threshold y-axis must pass to activate wheel motors. Default = 12.7
int clawlim = 120; // Threshold x-axis must pass to activate fubar motors.
task usercontrol() // User control code here, inside the loop
{
while (true)
{
// This is the main execution loop for the user control program. Each time through the loop
// your program should update motor + servo values based on feedback from the joysticks.
// Insert user code here. This is where you use the joystick values to update your motors, etc.
//UserControlCodePlaceholderForTesting(); // Remove this function call once you have "real" code.
////////////////////////////////
////////// Right wheel
////////////////////////////////
if (abs(vexRT[Ch2]) > threshold) // If the left joystick is greater than or less than the threshold:
{
motor[RWheel] = (vexRT[Ch2]); // Left Joystick Y value / 2.
}
if (abs(vexRT[Ch2]) < threshold) // If the left joystick is within the threshold:
{
motor[RWheel] = 0; // Stop the left motor (cancel noise)
}
////////////////////////////////
////////////////////////////////
////////// Left wheel
////////////////////////////////
if (abs(vexRT[Ch3]) > threshold) // If the left joystick is greater than or less than the threshold:
{
motor[LWheel] = (vexRT[Ch3]); // Left Joystick Y value / 2.
}
if (abs(vexRT[Ch3]) < threshold) // If the left joystick is within the threshold:
{
motor[LWheel] = 0; // Stop the left motor (cancel noise)
}
////////////////////////////////
////////////////////////////////
////////// Right Lifts
////////////////////////////////
if(vexRT[Btn8U] == 1 || vexRT[Btn8D] == 1 || vexRT[Btn8L] == 1 || vexRT[Btn8R] == 1 || vexRT[Btn6U] == 1 || vexRT[Btn6D] == 1) // Test for right lift button press
{
if(vexRT[Btn6U] == 1 || vexRT[Btn6D] == 1) // Test for right dual lift buttons
{
if(vexRT[Btn6U] == 1 && vexRT[Btn6D] == 1) // If both pressed: stops motors
{
motor[RLift1] = 0;
motor[RLift2] = 0;
}
else
{
if(vexRT[Btn6U] == 1) // right dual lifts up
{
motor[RLift1] = 127;
motor[RLift2] = 127;
}
if(vexRT[Btn6D] == 1) // right dual lifts down
{
motor[RLift1] = -127;
motor[RLift2] = -127;
}
}
}
else
{
if(vexRT[Btn8L] == 1 || vexRT[Btn8R] == 1) // Test for right bottom lift buttons
{
if(vexRT[Btn8L] == 1 && vexRT[Btn8R] == 1) // If both pressed: stops motors
{
motor[RLift1] = 0;
}
else
{
if(vexRT[Btn8L] == 1) // right bottom lift up
{
motor[RLift1] = 127;
}
if(vexRT[Btn8R] == 1) // right bottom lift down
{
motor[RLift1] = -127;
}
}
}
else
{
motor[RLift1] = 0; // if right bottom lift buttons are not in use: sets to 0
}
if(vexRT[Btn8U] == 1 || vexRT[Btn8D] == 1) // Test for right top lift buttons
{
if(vexRT[Btn8U] == 1 && vexRT[Btn8D] == 1) // If both pressed: stops motors
{
motor[RLift2] = 0;
}
else
{
if(vexRT[Btn8U] == 1) // right top lift up
{
motor[RLift2] = 127;
}
if(vexRT[Btn8D] == 1) // right top lift down
{
motor[RLift2] = -127;
}
}
}
else
{
motor[RLift2] = 0; // if right top lift buttons are not in use: sets to 0
}
}
}
else // no right lift button press
{
motor[RLift1] = 0;
motor[RLift2] = 0;
}
////////////////////////////////
////////////////////////////////
////////// Left Lifts
////////////////////////////////
if(vexRT[Btn7U] == 1 || vexRT[Btn7D] == 1 || vexRT[Btn7L] == 1 || vexRT[Btn7R] == 1 || vexRT[Btn5U] == 1 || vexRT[Btn5D] == 1) // Test for left lift button press
{
if(vexRT[Btn5U] == 1 || vexRT[Btn5D] == 1) // Test for left dual lift buttons
{
if(vexRT[Btn5U] == 1 && vexRT[Btn5D] == 1) // If both pressed: stops motors
{
motor[LLift1] = 0;
motor[LLift2] = 0;
}
else
{
if(vexRT[Btn5U] == 1) // left dual lifts up
{
motor[LLift1] = 127;
motor[LLift2] = 127;
}
if(vexRT[Btn5D] == 1) // left dual lifts down
{
motor[LLift1] = -127;
motor[LLift2] = -127;
}
}
}
else
{
if(vexRT[Btn7L] == 1 || vexRT[Btn7R] == 1) // Test for left bottom lift buttons
{
if(vexRT[Btn7L] == 1 && vexRT[Btn7R] == 1) // If both pressed: stops motors
{
motor[LLift1] = 127;
}
else
{
if(vexRT[Btn7L] == 1) // left bottom lift up
{
motor[LLift1] = 127;
}
if(vexRT[Btn7R] == 1) // left bottom lift down
{
motor[LLift1] = -127;
}
}
}
else
{
motor[LLift1] = 0; // if left bottom lift buttons are not in use: sets to 0
}
if(vexRT[Btn7U] == 1 || vexRT[Btn7D] == 1) // Test for left top lift buttons
{
if(vexRT[Btn7U] == 1 && vexRT[Btn7D] == 1) // If both pressed: stops motors
{
motor[LLift2] = 0;
}
else
{
if(vexRT[Btn7U] == 1) // left top lift up
{
motor[LLift2] = 127;
}
if(vexRT[Btn7D] == 1) // left top lift down
{
motor[LLift2] = -127;
}
}
}
else
{
motor[LLift2] = 0; // if left top lift buttons are not in use: sets to 0
}
}
}
else // no left lift button press
{
motor[LLift1] = 0;
motor[LLift2] = 0;
}
////////////////////////////////
////////////////////////////////
////////// Claw Motor 1 + 2
////////////////////////////////
if (abs(vexRT[Ch1]) > clawlim) // If the left joystick is greater than or less than the threshold:
{
motor[Claw1] = (vexRT[Ch2]);
motor[Claw2] = (vexRT[Ch2]);
}
if (abs(vexRT[Ch1]) < clawlim) // If the left joystick is within the threshold:
{
motor[Claw1] = 0; // Stop the left motor (cancel noise)
motor[Claw2] = 0; // Stop the left motor (cancel noise)
}
////////////////////////////////
////////////////////////////////
////////// Claw Motor 1 + 2
////////////////////////////////
/*if (abs(vexRT[Ch4]) > clawlim) // If the left joystick is greater than or less than the threshold:
{
motor[Claw1] = (vexRT[Ch2]);
motor[Claw2] = (vexRT[Ch2]);
}
if (abs(vexRT[Ch4]) < clawlim) // If the left joystick is within the threshold:
{
motor[Claw1] = 0; // Stop the left motor (cancel noise)
motor[Claw2] = 0; // Stop the left motor (cancel noise)
}*/
////////////////////////////////
} // while (true)
} // usercontrol()