This repository has been archived by the owner on Aug 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattemptAtLCD.c
485 lines (431 loc) · 15.2 KB
/
attemptAtLCD.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
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#pragma config(UART_Usage, UART1, uartVEXLCD, baudRate19200, IOPins, None, None)
#pragma config(Sensor, dgtl1, rightEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, leftEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl5, LSbumper, sensorTouch)
#pragma config(Motor, port2, topRight, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port3, bottomLeft, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, rightLS, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port5, leftLS, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port6, rightCone, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, bottomRight, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, topLeft, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port9, leftCone, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port10, rubberbands, tmotorVex393_HBridge, 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)
//Main competition background code...do not modify!
#include "Vex_Competition_Includes.c"
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
//Variable that will carry between modes
int Program;
const int threshold = 10;
const int QUAD_TOLERANCE = 40;
/*---------------------------------------------------------------------------*/
/* 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 autonomous 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 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;
SensorValue(rightEncoder) = 0;
SensorValue(leftEncoder) = 0;
//Leave this value alone
int lcdScreenMin = 1;
//This keeps track of which program you want to run
int lcdScreen = 1;
//Change this value to be the maximum number of programs you want on the robot
int lcdScreenMax = 4;
//Turns on the Backlight
bLCDBacklight = true;
//Copied from someone's sample code because the documentation for RobotC won't tell me anything useful
//These should logically work, but I'm not 100% sure
const short leftButton = 1;
const short centerButton = 2;
const short rightButton = 4;
while (vrDisabled == 1) { //Ensures this code will run ONLY when the robot is disabled
if (nLCDButtons == leftButton) { //Scrolls to the left
if (lcdScreenMin == lcdScreen) {
lcdScreen = lcdScreenMax;
wait1Msec(250);
} else {
lcdScreen --;
wait1Msec(250);
}
}
if (nLCDButtons == rightButton) { //Scrolls to the right
if (lcdScreenMax == lcdScreen) {
lcdScreen = lcdScreenMin;
wait1Msec(250);
} else {
lcdScreen++;
wait1Msec(250);
}
}
if (lcdScreen == 1 && Program != 1) {
displayLCDCenteredString (0, "Program"); //Name the first program here
displayLCDCenteredString (1, "1"); //Name the first program here
if (nLCDButtons == centerButton) {
Program = lcdScreen; //Sets the Program to the one on-screen
displayLCDCenteredString (0, "Autonomous Has");
displayLCDCenteredString (1, "Been Selected!");
wait1Msec(1500);
}
} else if (lcdScreen == 1 && Program == 1) {
displayLCDCenteredString (0, "Program"); //We use brackets to mark which program we have chosen
displayLCDCenteredString (1, "[1]"); //So that while we're scrolling, we can have one marked
} else if (lcdScreen == 2 && Program != 2) {
displayLCDCenteredString (0, "Program"); //Name the second program here
displayLCDCenteredString (1, "2"); //Name the second program here
if (nLCDButtons == centerButton) {
Program = lcdScreen; //Sets the Program to the one on-screen
displayLCDCenteredString (0, "Autonomous Has");
displayLCDCenteredString (1, "Been Selected!");
wait1Msec(1500);
}
} else if (lcdScreen == 2 && Program == 2) {
displayLCDCenteredString (0, "Program"); //We use brackets to mark which program we have chosen
displayLCDCenteredString (1, "[2]"); //So that while we're scrolling, we can have one marked
} else if (lcdScreen == 3 && Program != 3) {
displayLCDCenteredString (0, "Program"); //Name the third program here
displayLCDCenteredString (1, "3"); //Name the third program here
if (nLCDButtons == centerButton) {
Program = lcdScreen; //Sets the Program to the one on-screen
displayLCDCenteredString (0, "Autonomous Has");
displayLCDCenteredString (1, "Been Selected!");
wait1Msec(1500);
}
} else if (lcdScreen == 3 && Program == 3) {
displayLCDCenteredString (0, "Program"); //We use brackets to mark which program we have chosen
displayLCDCenteredString (1, "[3]"); //So that while we're scrolling, we can have one marked
} else if (lcdScreen == 4 && Program != 4) {
displayLCDCenteredString (0, "Program"); //Name the fourth program here
displayLCDCenteredString (1, "4"); //Name the fourth program here
if (nLCDButtons == centerButton) {
Program = lcdScreen; //Sets the Program to the one on-screen
displayLCDCenteredString (0, "Autonomous Has");
displayLCDCenteredString (1, "Been Selected!");
wait1Msec(1500);
}
} else if (lcdScreen == 4 && Program == 4) {
displayLCDCenteredString (0, "Program"); //We use brackets to mark which program we have chosen
displayLCDCenteredString (1, "[4]"); //So that while we're scrolling, we can have one marked
}
}
}
/*---------------------------------------------------------------------------*/
/* */
/* 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 resetQuads() {
SensorValue[rightEncoder] = 0;
SensorValue[leftEncoder] = 0;
}
void waitTicks(int ticks, int timeout = -1) {
resetQuads();
ticks = abs(ticks);
timeout *= 1000;
while (abs(SensorValue[rightEncoder]) - QUAD_TOLERANCE < ticks &&
abs(SensorValue[leftEncoder]) - QUAD_TOLERANCE < ticks && (timeout > 0 || timeout == -1000)) {
wait1Msec(100);
if (timeout != -1000) timeout -= 100;
}
}
void autoLSStop() {
motor[rightLS] = 0;
motor[leftLS] = 0;
}
void stopLift() {
motor[rightCone] = 0;
motor[leftCone] = 0;
}
void autoLift(int speed, int time) {
//lift clockwise = positive
//lift counterClockwise = negative
motor[rightCone] = speed;
motor[leftCone] = speed;
wait1Msec(time);
stopLift();
}
void stopRubberbands() {
motor[rubberbands] = 0;
}
void rubberbandMechanism(int speed, int time) {
//rotateIn = negative
//rotateOut = positive
motor[rubberbands] = speed;
wait1Msec(time);
stopRubberbands();
}
void autoLS(const string motion, int time) {
if(motion == "up") {
motor[rightLS] = 90;
motor[leftLS] = 80;
wait1Msec(time);
}
if(motion == "down") {
motor[rightLS] = -90;
motor[leftLS] = -80;
wait1Msec(time);
}
autoLSStop();
}
void stopDrive() {
motor[bottomRight] = 0;
motor[bottomLeft] = 0;
motor[topRight] = 0;
motor[topLeft] = 0;
}
void autoDrive(const string direction, int speed, int ticks) {
if(direction == "forward") {
motor[bottomRight] = speed;
motor[topRight] = speed;
motor[bottomLeft] = speed;
motor[topLeft] = speed;
waitTicks(ticks);
}
if(direction == "backward") {
motor[bottomRight] = -speed;
motor[topRight] = -speed;
motor[bottomLeft] = -speed;
motor[topLeft] = -speed;
waitTicks(ticks);
}
if(direction == "right") {
motor[bottomRight] = -speed;
motor[topRight] = -speed;
motor[bottomLeft] = speed;
motor[topLeft] = speed;
waitTicks(ticks);
}
if(direction == "left") {
motor[bottomRight] = speed;
motor[topRight] = speed;
motor[bottomLeft] = -speed;
motor[topLeft] = -speed;
waitTicks(ticks);
}
stopDrive();
}
void bumper() {
while(SensorValue(LSbumper) == 0) {
autoDrive("forward", 100, 1);
wait1Msec(10);
}
}
void left5points() {
// for 5 points incase other team has a better 20 point autonomous
//autoDrive("forward", 90, 100);
autoLift(-90, 1000);
bumper();
stopDrive();
autoLS("up", 1200);
autoDrive("backward", 100, 700);
autoDrive("right", 75, 400);
autoDrive("forward", 80, 100);
autoDrive("right", 75, 50);
autoDrive("forward", 100, 1200);
autoLS("down", 800);
autoDrive("backward", 75, 1500);
}
void right5points() {
// for 5 points incase other team has a better 20 point autonomous
autoDrive("forward", 90, 1000);
while(SensorValue(LSbumper) == 0) {
autoDrive("forward", 75, 100);
wait1Msec(10);
}
stopDrive();
autoLS("up", 800);
autoDrive("left", 75, 700);
autoDrive("forward", 100, 2000);
autoLS("down", 800);
autoDrive("backward", 75, 1000);
}
void shortAutoRightSide() {
//drive forward, pick up a mobile goal, 180 left, drive forward and place it in the 10 point zone
autoDrive("forward", 90, 1000);
bumper();
stopDrive();
autoLS("up", 1000);
autoDrive("backward", 100, 700);
autoDrive("left", 75, 400);
autoDrive("forward", 80, 100);
autoDrive("left", 75, 50);
autoDrive("forward", 100, 1500);
autoLS("up", 600);
autoDrive("left", 75, 100);
autoDrive("forward", 127, 500);
autoLS("down", 400);
autoDrive("backward", 75, 200);
}
void shortAutoLeftSide() {
//drive forward, pick up a mobile goal, 180 right, drive forward and place it in the 10 point zone
autoDrive("forward", 90, 1000);
bumper();
stopDrive();
autoLS("up", 800);
autoDrive("backward", 100, 700);
autoDrive("right", 75, 400);
autoDrive("forward", 80, 100);
autoDrive("right", 75, 50);
autoDrive("forward", 100, 1500);
autoLS("up", 600);
autoDrive("right", 75, 100);
autoDrive("forward", 127, 500);
autoLS("down", 400);
autoDrive("backward", 75, 200);
}
void line() {
//first mobile goal
bumper();
autoLS("up", 800);
autoDrive("right", 75, 400);
autoDrive("forward", 100, 300);
autoLS("up", 600);
autoDrive("forward", 100, 100);
autoLS("down", 400);
autoDrive("backward", 100, 50);
autoDrive("right", 75, 400);
//far mobile goal
//bumper();
autoDrive("forward", 100, 700);
autoLS("up", 800);
autoDrive("forward", 100, 100);
autoDrive("left", 100, 50);
autoDrive("forward", 100, 20);
autoDrive("right", 100, 20);
autoLS("up", 600);
autoDrive("forward", 127, 200);
autoDrive("backward", 127, 50);
}
void oneMinute() {
line();
autoDrive("backward", 100, 100);
autoDrive("left", 100, 100);
autoDrive("forward", 100, 100);
autoDrive("left", 100, 100);
line();
}
task autonomous(){
//left5points();
//right5points();
line();
//shortAutoLeftSide();
//shortAutoRightSide();
//oneMinute();
if(Program == 1){
right5points();
}
else if(Program == 2){
left5points();
}
else if(Program == 3){
//Put your third program in here
}
}
/*---------------------------------------------------------------------------*/
/* */
/* 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. */
/*---------------------------------------------------------------------------*/
void drive(int y, int x) {
if(abs(x) > threshold) {
//right, bottom right goes backwards, top right goes forward
motor[bottomRight] = -x;
motor[topRight] = -x;
motor[bottomLeft] = x;
motor[topLeft] = x;
}
//forward and backward
else if(abs(y) > threshold) {
motor[bottomRight] = y;
motor[topRight] = y;
motor[bottomLeft] = y;
motor[topLeft] = y;
} else {
stopDrive();
}
}
void LS(int extend, int retract) {
//positive LS moves backward
if(extend == 1) {
//if(abs(SensorValue(rightEncoder)) < LSMAX && abs(SensorValue(leftEncoder)) < LSMAX) {
motor[rightLS] = 90;
motor[leftLS] = 80;
//}
}
else if(retract == 1) {
motor[rightLS] = -90;
motor[leftLS] = -80;
}
else {
motor[rightLS] = 0;
motor[leftLS] = 0;
}
}
void lift(int clockwise, int counterClockwise, int speed) {
if(clockwise == 1) {
motor[rightCone] = speed;
motor[leftCone] = speed;
}
else if(counterClockwise == 1) {
motor[rightCone] = -speed;
motor[leftCone] = -speed;
}
else {
motor[rightCone] = 0;
motor[leftCone] = 0;
}
}
void cone(int rotateIn, int rotateOut) {
if(rotateIn == 1) {
motor[rubberbands] = -80;
}
else if(rotateOut == 1) {
motor[rubberbands] = 80;
}
else {
motor[rubberbands] = 0;
}
}
void Riley() {
drive(vexRT[Ch3], vexRT[Ch1]);
//for LS
//right trigger, button 6D extends
//right trigger, button 6U retracts
LS(vexRT[Btn6D], vexRT[Btn6U]);
lift(vexRT[Btn5D], vexRT[Btn5U], 80);
cone(vexRT[Btn7U], vexRT[Btn7D]);
}
task usercontrol() {
while(true) {
Riley();
}
}