-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwo Skinky Bot III #1.c
447 lines (406 loc) · 9.88 KB
/
Two Skinky Bot III #1.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
#pragma config(Sensor, in1, DR4Bpot, sensorPotentiometer)
#pragma config(Sensor, in2, Barpot, sensorPotentiometer)
#pragma config(Sensor, in3, Sidepot, sensorPotentiometer)
#pragma config(Sensor, in4, Zonepot, sensorPotentiometer)
#pragma config(Sensor, in5, Conepot, sensorPotentiometer)
#pragma config(Sensor, dgtl1, RDenc, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, LDenc, sensorQuadEncoder)
#pragma config(Motor, port2, RD1, tmotorVex393TurboSpeed_MC29, openLoop, encoderPort, dgtl1)
#pragma config(Motor, port3, RD2, tmotorVex393TurboSpeed_MC29, openLoop, encoderPort, dgtl1)
#pragma config(Motor, port4, MG, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, Roller, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, Bar, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, DR4B, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, LD2, tmotorVex393TurboSpeed_MC29, openLoop, encoderPort, dgtl3)
#pragma config(Motor, port9, LD1, tmotorVex393TurboSpeed_MC29, openLoop, encoderPort, dgtl3)
//*!!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"
void resetsensors()
{
SensorValue[RDenc] = 0;
SensorValue[LDenc] = 0;
}
void driveForward(int power, int sensoramount)
{
while (SensorValue[RDenc] < sensoramount || SensorValue[LDenc] < sensoramount)
{
if (SensorValue[RDenc] < sensoramount)
{
motor[RD1] = power;
motor[RD2] = power;
}
else
{
motor[RD1] = 0;
motor[RD2] = 0;
}
if (SensorValue[LDenc] < sensoramount)
{
motor[LD1] = power;
motor[LD2] = power;
}
else
{
motor[LD1] = 0;
motor[LD2] = 0;
}
}
motor[RD1] = 0;
motor[RD2] = 0;
motor[LD1] = 0;
motor[LD2] = 0;
}
void driveBackwards(int power, int sensoramount)
{
while (SensorValue[RDenc] > -sensoramount || SensorValue[LDenc] > -sensoramount)
{
if (SensorValue[RDenc] > -sensoramount)
{
motor[RD1] = -power;
motor[RD2] = -power;
}
else
{
motor[RD1] = 0;
motor[RD2] = 0;
}
if (SensorValue[LDenc] > -sensoramount)
{
motor[LD1] = -power;
motor[LD2] = -power;
}
else
{
motor[LD1] = 0;
motor[LD2] = 0;
}
}
motor[RD1] = 0;
motor[RD2] = 0;
motor[LD1] = 0;
motor[LD2] = 0;
}
void turnLeft(int power, int sensoramount)
{
while (SensorValue[RDenc] < sensoramount || SensorValue[LDenc] > -sensoramount)
{
if (SensorValue[RDenc] < sensoramount)
{
motor[RD1] = power;
motor[RD2] = power;
}
else
{
motor[RD1] = 0;
motor[RD2] = 0;
}
if (SensorValue[LDenc] > -sensoramount)
{
motor[LD1] = -power;
motor[LD2] = -power;
}
else
{
motor[LD1] = 0;
motor[LD2] = 0;
}
}
motor[RD1] = 0;
motor[RD2] = 0;
motor[LD1] = 0;
motor[LD2] = 0;
}
void turnRight(int power, int sensoramount)
{
while (SensorValue[RDenc] > -sensoramount || SensorValue[LDenc] < sensoramount)
{
if (SensorValue[RDenc] > -sensoramount)
{
motor[RD1] = -power;
motor[RD2] = -power;
}
else
{
motor[RD1] = 0;
motor[RD2] = 0;
}
if (SensorValue[LDenc] < sensoramount)
{
motor[LD1] = power;
motor[LD2] = power;
}
else
{
motor[LD1] = 0;
motor[LD2] = 0;
}
}
motor[RD1] = 0;
motor[RD2] = 0;
motor[LD1] = 0;
motor[LD2] = 0;
}
void specialBack(int power1, int power2, int sensoramount1, int sensoramount2)
{
while (SensorValue[RDenc] > -sensoramount1 || SensorValue[LDenc] > -sensoramount2)
{
if (SensorValue[RDenc] > -sensoramount1)
{
motor[RD1] = -power1;
motor[RD2] = -power1;
}
else
{
motor[RD1] = 0;
motor[RD2] = 0;
}
if (SensorValue[LDenc] < -sensoramount2)
{
motor[LD1] = -power2;
motor[LD2] = -power2;
}
else
{
motor[LD1] = 0;
motor[LD2] = 0;
}
}
motor[RD1] = 0;
motor[RD2] = 0;
motor[LD1] = 0;
motor[LD2] = 0;
}
void timeForward(int power, int time)
{
motor[RD1] = power;
motor[RD2] = power;
motor[LD1] = power;
motor[LD2] = power;
wait1Msec(time);
motor[RD1] = 0;
motor[RD2] = 0;
motor[LD1] = 0;
motor[LD2] = 0;
}
void timeBackwards(int power, int time)
{
motor[RD1] = -power;
motor[RD2] = -power;
motor[LD1] = -power;
motor[LD2] = -power;
wait1Msec(time);
motor[RD1] = 0;
motor[RD2] = 0;
motor[LD1] = 0;
motor[LD2] = 0;
}
void timeLeft(int power, int time)
{
motor[LD1] = power;
motor[LD2] = power;
wait1Msec(time);
motor[LD1] = 0;
motor[LD2] = 0;
}
void timeRight(int power, int time)
{
motor[LD1] = power;
motor[LD2] = power;
wait1Msec(time);
motor[LD1] = 0;
motor[LD2] = 0;
}
void liftMobileGoal(int power, int time)
{
motor[MG] = power;
wait1Msec(time);
motor[MG] = 0;
}
void lowerMobileGoal(int power, int time)
{
motor[MG] = -power;
wait1Msec(time);
motor[MG] = 0;
}
void liftDR4B(int power, int sensoramount)
{
while(SensorValue[DR4Bpot] < sensoramount)
{
motor[DR4B] = power;
}
motor[DR4B] = 0;
}
void lowerDR4B(int power, int sensoramount)
{
while(SensorValue[DR4Bpot] > sensoramount)
{
motor[DR4B] = -power;
}
motor[DR4B] = 0;
}
void timeLiftDR4B(int power, int time)
{
motor[DR4B] = power;
wait1Msec(time);
motor[DR4B] = 0;
}
void timeLowerDR4B(int power, int time)
{
motor[DR4B] = -power;
wait1Msec(time);
motor[DR4B] = 0;
}
void lift4Bar(int power, int sensoramount)
{
while(SensorValue[Barpot] < sensoramount)
{
motor[Bar] = power;
}
motor[Bar] = 0;
}
void lower4Bar(int power, int sensoramount)
{
while(SensorValue[Barpot] > sensoramount)
{
motor[Bar] = -power;
}
motor[Bar] = 0;
}
void timeLift4Bar(int power, int time)
{
motor[Bar] = power;
wait1Msec(time);
motor[Bar] = 0;
}
void timeLower4Bar(int power, int time)
{
motor[Bar] = -power;
wait1Msec(time);
motor[Bar] = 0;
}
void timeLift4Bar(int power, int time)
{
motor[Bar] = power;
wait1Msec(time);
motor[Bar] = 0;
}
void timeLower4Bar(int power, int time)
{
motor[Bar] = -power;
wait1Msec(time);
motor[Bar] = 0;
}
void grabCone(int power, int time)
{
motor[Roller] = power;
wait1Msec(time);
motor[Roller] = 0;
}
void releaseCone(int power, int time)
{
motor[Roller] = -power;
wait1Msec(time);
motor[Roller] = 0;
}
/*---------------------------------------------------------------------------*/
/* 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()
{
}
/*---------------------------------------------------------------------------*/
/* */
/* 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()
//if (0 <= SensorValue[Sidepot] && 1000 >= SensorValue[Sidepot] && 0 <= SensorValue[Zonepot] && 1000 >= SensorValue[Zonepot] && 0 <= SensorValue[Conepot] && 1000 >= SensorValue[Conepot])
{
}
/*---------------------------------------------------------------------------*/
/* */
/* 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()
{
while (true)
{
motor[RD1] = vexRT[Ch2];
motor[RD2] = vexRT[Ch2];
motor[LD1] = vexRT[Ch3];
motor[LD2] = vexRT[Ch3];
if (vexRT[Btn5U] == 1) //4 Bar
{
motor[Bar] = 127;
}
else if (vexRT[Btn5D] == 1)
{
motor[Bar] = -127;
}
else
{
motor[Bar] = 0;
}
if (vexRT[Btn6U] == 1) //Cone Intake
{
motor[Roller] = 127;
}
else if (vexRT[Btn6D] == 1)
{
motor[Roller] = -127;
}
else
{
motor[Roller] = 0;
}
if (vexRT[Btn7U] == 1) //DR4B
{
motor[DR4B] = 127;
}
else if (vexRT[Btn7D] == 1)
{
motor[DR4B] = -127;
}
else
{
motor[DR4B] = 0;
}
if (vexRT[Btn8U] == 1) //Mobile Goal
{
motor[MG] = 127;
}
else if (vexRT[Btn8U] == 1)
{
motor[MG] = -127;
}
else
{
motor[MG] = 0;
}
}
}