-
Notifications
You must be signed in to change notification settings - Fork 0
/
moreAdvancedOldCode.c
917 lines (836 loc) · 24.8 KB
/
moreAdvancedOldCode.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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, in1, FlipperGyro, sensorGyro)
#pragma config(Sensor, in2, ArmPot, sensorPotentiometer)
#pragma config(Sensor, in3, FlipperPot, sensorPotentiometer)
#pragma config(Sensor, in4, Auton_Pot, sensorPotentiometer)
#pragma config(Sensor, in5, Gyro, sensorNone)
#pragma config(Sensor, dgtl1, JawChanger, sensorTouch)
#pragma config(Sensor, dgtl11, LED, sensorLEDtoVCC)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_2, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_4, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_5, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_6, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Motor, port1, RightBaseBack, tmotorVex393HighSpeed, PIDControl, reversed, encoder, encoderPort, I2C_2, 1000)
#pragma config(Motor, port2, LeftArm, tmotorVex393HighSpeed, PIDControl, reversed, encoder, encoderPort, I2C_4, 1000)
#pragma config(Motor, port3, RightArm, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port4, LeftBaseFront, tmotorVex393, openLoop)
#pragma config(Motor, port5, TheJaw, tmotorVex269, openLoop, reversed)
#pragma config(Motor, port6, FlipperMotorLeft, tmotorVex269, openLoop, reversed, encoder, encoderPort, I2C_5, 1000)
#pragma config(Motor, port7, FlipperMotorRight, tmotorVex269, openLoop, encoder, encoderPort, I2C_6, 1000)
#pragma config(Motor, port8, LeftBaseBack, tmotorVex393, openLoop)
#pragma config(Motor, port9, Convayer, tmotorVex393, openLoop)
#pragma config(Motor, port10,+
RightBaseFront, tmotorVex393HighSpeed, PIDControl, reversed, encoder, encoderPort, I2C_1, 1000)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#pragma platform(VEX)
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
#include "Vex_Competition_Includes.c" //Main competition background code...do not modify!
// Pot Values - for the ARMS
#define Trough 2222
#define HighGoal 2770 //2780
#define HighLimit 3000
#define LowLimit 1080
#define ArmsFloor 1060
#define ArmsHigh 2780 //2720
// Arm Commands
bool goup = true;
bool godown = true;
// Range values for the autonomous dial
#define Range0 5000
#define Range1 2000
#define Range2 1000
#define Range3 0
// Flipper values
#define FlipperHold 3500
#define FlipperToFloor 3260 //2750 //2600//2500//2600//2560
#define FlipperScore 830
task BatmanHold()
{
while(1)
{
// 400 = Tempo
// 5 = Default octave
// Eighth = Default note length
// 10% = Break between notes
//
PlayTone( 587, 14); wait1Msec( 150); // Note(D)
PlayTone( 587, 14); wait1Msec( 150); // Note(D)
PlayTone( 554, 14); wait1Msec( 150); // Note(C#)
PlayTone( 554, 14); wait1Msec( 150); // Note(C#)
PlayTone( 523, 14); wait1Msec( 150); // Note(C)
PlayTone( 523, 14); wait1Msec( 150); // Note(C)
PlayTone( 554, 14); wait1Msec( 150); // Note(C#)
PlayTone( 554, 14); wait1Msec( 150); // Note(C#)
PlayTone( 587, 14); wait1Msec( 150); // Note(D)
PlayTone( 587, 14); wait1Msec( 150); // Note(D)
PlayTone( 554, 14); wait1Msec( 150); // Note(C#)
PlayTone( 554, 14); wait1Msec( 150); // Note(C#)
PlayTone( 523, 14); wait1Msec( 150); // Note(C)
PlayTone( 523, 14); wait1Msec( 150); // Note(C)
PlayTone( 554, 14); wait1Msec( 150); // Note(C#)
PlayTone( 554, 14); wait1Msec( 150); // Note(C#)
PlayTone( 587, 14); wait1Msec( 150); // Note(D)
PlayTone( 622, 14); wait1Msec( 150); // Note(D#)
PlayTone( 523, 14); wait1Msec( 150); // Note(C)
PlayTone( 554, 14); wait1Msec( 150); // Note(C#)
PlayTone( 523, 14); wait1Msec( 150); // Note(C)
PlayTone( 523, 14); wait1Msec( 150); // Note(C)
PlayTone( 554, 14); wait1Msec( 150); // Note(C#)
PlayTone( 554, 14); wait1Msec( 150); // Note(C#)
PlayTone( 698, 14); wait1Msec( 150); // Note(F)
PlayTone( 0, 14); wait1Msec( 150); // Note(Rest)
PlayTone( 698, 27); wait1Msec( 300); // Note(F, Duration(Quarter))
}
}
task MulBat()
{
while(1)
{
if(SensorValue(ArmPot) >= HighGoal)
{
// 180 = Tempo
// 5 = Default octave
// Quarter = Default note length
// 10% = Break between notes
//
PlayTone( 587, 15); wait1Msec( 167); // Note(D, Duration(Eighth))
PlayTone( 587, 15); wait1Msec( 167); // Note(D, Duration(Eighth))
PlayTone( 554, 15); wait1Msec( 167); // Note(C#, Duration(Eighth))
PlayTone( 554, 15); wait1Msec( 167); // Note(C#, Duration(Eighth))
PlayTone( 523, 15); wait1Msec( 167); // Note(C, Duration(Eighth))
PlayTone( 523, 15); wait1Msec( 167); // Note(C, Duration(Eighth))
PlayTone( 554, 15); wait1Msec( 167); // Note(C#, Duration(Eighth))
PlayTone( 554, 15); wait1Msec( 167); // Note(C#, Duration(Eighth))
PlayTone( 587, 15); wait1Msec( 167); // Note(D, Duration(Eighth))
PlayTone( 587, 15); wait1Msec( 167); // Note(D, Duration(Eighth))
PlayTone( 554, 15); wait1Msec( 167); // Note(C#, Duration(Eighth))
PlayTone( 554, 15); wait1Msec( 167); // Note(C#, Duration(Eighth))
PlayTone( 523, 15); wait1Msec( 167); // Note(C, Duration(Eighth))
PlayTone( 523, 15); wait1Msec( 167); // Note(C, Duration(Eighth))
PlayTone( 554, 15); wait1Msec( 167); // Note(C#, Duration(Eighth))
PlayTone( 554, 15); wait1Msec( 167); // Note(C#, Duration(Eighth))
PlayTone( 587, 30); wait1Msec( 333); // Note(D)
PlayTone( 0, 15); wait1Msec( 167); // Note(Rest, Duration(Eighth))
PlayTone( 622, 15); wait1Msec( 167); // Note(D#, Duration(Eighth))
PlayTone( 523, 15); wait1Msec( 167); // Note(C, Duration(Eighth))
PlayTone( 554, 15); wait1Msec( 167); // Note(C#, Duration(Eighth))
PlayTone( 523, 15); wait1Msec( 167); // Note(C, Duration(Eighth))
PlayTone( 523, 15); wait1Msec( 167); // Note(C, Duration(Eighth))
PlayTone( 554, 15); wait1Msec( 167); // Note(C#, Duration(Eighth))
PlayTone( 554, 15); wait1Msec( 167); // Note(C#, Duration(Eighth))
PlayTone( 698, 15); wait1Msec( 167); // Note(F, Duration(Eighth))
PlayTone( 0, 15); wait1Msec( 167); // Note(Rest, Duration(Eighth))
PlayTone( 698, 30); wait1Msec( 333); // Note(F)
return;
}
}
}
// LCD buttons
//const short leftButton = 1;
//const short centerButton = 2;
//const short rightButton = 4;
void WaitForLCD()
{
while(true)
{
// we will be in this loop until the user pushes a button
// check if button has been pressed if so break out of loop
if (nLCDButtons != 0)
{
// somebody pressed a button - break out of this loop and continue on...
break;
}
}
}
void FlipperGoDown()
{
if (SensorValue [FlipperPot] > FlipperToFloor)
{
while (SensorValue [FlipperPot] > FlipperToFloor)
{
motor(FlipperMotorLeft) = -63;
motor(FlipperMotorRight) = -63;
}
motor(FlipperMotorLeft) = 0;
motor(FlipperMotorRight) = 0;
}
}
void FlipperToTrough()
{
// first reead the pot on flipper into a local variable
// keep movimg the flliper down until it reaCHES the "trough" pot setting
// once it reaches the trough setting - quit moving the flipper
while (SensorValue[FlipperPot] > FlipperScore)
{
motor(FlipperMotorRight) = -83;
motor(FlipperMotorLeft) = -83;
}
motor(FlipperMotorLeft) = 0;
motor(FlipperMotorRight) = 0;
}
task TASKflipperup()
{
motor(FlipperMotorLeft) = 10;
motor(FlipperMotorRight) = 10;
while(true)
{
if (SensorValue [FlipperPot] < 3050) //2650
{
motor(FlipperMotorLeft) = 60;
motor(FlipperMotorRight) = 60;
wait1Msec(10);
motor(FlipperMotorLeft) = 10;
motor(FlipperMotorRight) = 10;
}
else if (SensorValue [FlipperPot] > 3000) // 2600
{
motor(FlipperMotorLeft) = -60;
motor(FlipperMotorRight) = -60;
wait1Msec(10);
motor(FlipperMotorLeft) = 10;
motor(FlipperMotorRight) = 10;
}
else
{
motor(FlipperMotorLeft) = 10;
motor(FlipperMotorRight) = 10;
}
}
}
task TASKflippertofloorandhold
{
// raising up from trough position scored
while (SensorValue [FlipperPot] < FlipperToFloor)
{
motor(FlipperMotorLeft) = 127;
motor(FlipperMotorRight) = 127;
}
motor(FlipperMotorLeft) = 10;
motor(FlipperMotorRight) = 10;
}
void ClearEncoders()
{
nMotorEncoder[RightBaseBack] = 0;
nMotorEncoder[RightBaseFront] = 0;
nMotorEncoder[LeftBaseBack] = 0;
nMotorEncoder[LeftBaseFront] = 0;
}
task TASKKeepFlipperInPlace()
{
// first if we are too high then the flipper must go down
while (SensorValue[FlipperPot] > 1000)
{
motor(FlipperMotorRight) = -50;
motor(FlipperMotorLeft) = -50;
}
while(true)
{
motor(FlipperMotorRight) = 20;
motor(FlipperMotorLeft) = 20;
while (SensorValue[FlipperPot] > 1200)
{
// too high
motor(FlipperMotorRight) = -10;
motor(FlipperMotorLeft) = -10;
}
while(SensorValue[FlipperPot] < 900)
{
// too low
motor(FlipperMotorRight) = 40;
motor(FlipperMotorLeft) = 40;
}
}
}
void MoveHalfSpeed(bool bForwards, int iPosition)
{
ClearEncoders();
while (abs(nMotorEncoder(RightBaseBack)) < iPosition)
{
if (bForwards)
{
motor[RightBaseFront] = 60;
motor[RightBaseBack] = 60;
motor[LeftBaseFront] = 60;
motor[LeftBaseBack] = 60;
}
else
{
motor[RightBaseFront] = -60;
motor[RightBaseBack] = -60;
motor[LeftBaseFront] = -60;
motor[LeftBaseBack] = -60;
}
}
motor[RightBaseFront] = 0;
motor[RightBaseBack] = 0;
motor[LeftBaseFront] = 0;
motor[LeftBaseBack] = 0;
}
void MoveFullSpeed(bool bForwards, int iPosition)
{
ClearEncoders();
while (abs(nMotorEncoder(RightBaseBack)) < iPosition)
{
if (bForwards)
{
motor[RightBaseFront] = 127;
motor[RightBaseBack] = 127;
motor[LeftBaseFront] = 127;
motor[LeftBaseBack] = 127;
}
else
{
motor[RightBaseFront] = -127;
motor[RightBaseBack] = -127;
motor[LeftBaseFront] = -127;
motor[LeftBaseBack] = -127;
}
}
motor[RightBaseFront] = 0;
motor[RightBaseBack] = 0;
motor[LeftBaseFront] = 0;
motor[LeftBaseBack] = 0;
}
#define ArmsMotorHold 10
bool ArmsHighNow = true;
void Arms(bool bUp, int iPosition, int iMotorPower)
{
//Move arms to trough, floor, or high
// are we moving up or down
if (bUp)
{
// we are moving up
while (SensorValue[ArmPot] < iPosition)
{
motor(RightArm) = iMotorPower;
motor(LeftArm) = iMotorPower;
motor(RightBaseBack) = vexRT(Ch2);
motor(LeftBaseBack) = vexRT(Ch3);
}
// no movement - HOLD
ArmsHighNow = true;
motor(RightArm) = ArmsMotorHold;
motor(LeftArm) = ArmsMotorHold;
}
else if (!bUp)
{
// we are moving down
while (SensorValue[ArmPot] > iPosition)
{
motor(RightArm) = -iMotorPower;
motor(LeftArm) = -iMotorPower;
}
// no movement - HOLD
motor(RightArm) = 0;
motor(LeftArm) = 0;
}
}
#define ArmsTrough 2222//2260
task TASKarmstofloor()
{
while (SensorValue[ArmPot] > ArmsFloor)
{
motor(RightArm) = -127;
motor(LeftArm) = -127;
}
motor(RightArm) = 0;
motor(LeftArm) = 0;
}
task YellowFlipperHold()
{
while(1)
{
if(SensorValue(FlipperPot) < 2700)//2883
{
motor(FlipperMotorLeft) = 50;
motor(FlipperMotorRight) = 50;
}
else if(SensorValue(FlipperPot) > 2800)//3000//3361
{
motor(FlipperMotorLeft) = -10;
motor(FlipperMotorRight) = -10;
}
else if(SensorValue(FlipperPot) > 2700 && SensorValue(FlipperPot) < 2800)//3361
{
motor(FlipperMotorLeft) = 10;
motor(FlipperMotorRight) = 10;
}
}
}
void flipperdown()
{
motor(FlipperMotorLeft) = -63;
motor(FlipperMotorRight) = -63;
wait1Msec(700);
motor(FlipperMotorLeft) = 0;
motor(FlipperMotorRight) = 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////Start Autonomous Voids///////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void AutonomousScoreFive()
{
flipperdown();
//drive forward to five stack
MoveFullSpeed(true, 900); //1100
StartTask(TASKflipperup);
while(SensorValue(ArmPot) < Trough)
{
motor(RightArm) = 127;
motor(LeftArm) = 127;
}
motor(RightArm) = 10;
motor(LeftArm) = 10;
// drive forward
MoveHalfSpeed(true, 400);//300//400//500
StopTask(TASKflipperup);
FlipperToTrough();
wait1Msec(500);
// drive back to starting tile
MoveFullSpeed(false, 1200);
StartTask(TASKflippertofloorandhold);
StartTask(TASKarmstofloor);
///////////////////////////
// now pickup the yellow //
///////////////////////////
WaitForLCD();
motor(FlipperMotorLeft) = -63;
motor(FlipperMotorRight) = -63;
wait1Msec(250);
motor(FlipperMotorLeft) = 0;
motor(FlipperMotorRight) = 0;
//drive forward to yellow bag
MoveFullSpeed(true, 1600);
// raise slightly and hold
motor[FlipperMotorLeft] = 127;
motor[FlipperMotorRight] = 127;
MoveFullSpeed(true, 600);
motor[FlipperMotorLeft] = 10;
motor[FlipperMotorRight] = 10;
// back up
MoveFullSpeed(false, 2000);
wait1Msec(10000);
}
void AutonomousScoreYellow()
{
FlipperGoDown();
//drive forward to yellow bag
MoveFullSpeed(true, /*1500*/1600);
// raise trough slightly and hold
motor[FlipperMotorLeft] = 127;
motor[FlipperMotorRight] = 127;
MoveFullSpeed(true, 600);
motor[FlipperMotorLeft] = 10;
motor[FlipperMotorRight] = 10;
MoveFullSpeed(false, 1400);//1250//900
// lowering flipper so bags dont fall out
motor[FlipperMotorLeft] = -80;
motor[FlipperMotorRight] = -80;
wait1Msec(250);
motor[FlipperMotorLeft] = 10;
motor[FlipperMotorRight] = 10;
// raise arms up to trough
StartTask(YellowFlipperHold);
Arms(true, ArmsTrough, 127);
MoveFullSpeed(true, 350);//230
StopTask(YellowFlipperHold);
FlipperToTrough();
motor(LeftArm) = 50;
motor(RightArm) = 50;
wait1Msec(500);
MoveFullSpeed(false, 10);
motor(RightArm) = 0;
motor(LeftArm) = 0;
// drive back to starting tile
MoveFullSpeed(false, 1200);
}
void Fuse()
{
bool go = true;
//part 1 drive forward
motor(FlipperMotorLeft) = -63;
motor(FlipperMotorRight) = -63;
wait1Msec(800);
motor(FlipperMotorLeft) = 0;
motor(FlipperMotorRight) = 0;
while(go == true)
{
motor[RightBaseFront] = 127;
motor[RightBaseBack] = 127;
motor[LeftBaseFront] = 127;
motor[LeftBaseBack] = 127;
wait1Msec(5000);
go = false;
}
motor[RightBaseFront] = 0;
motor[RightBaseBack] = 0;
motor[LeftBaseFront] = 0;
motor[LeftBaseBack] = 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// END Autonomous Voids///////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Wait for Press--------------------------------------------------
void waitForPress()
{
while(nLCDButtons == 0){}
wait1Msec(5);
}
//----------------------------------------------------------------
//Wait for Release------------------------------------------------
void waitForRelease()
{
while(nLCDButtons != 0){}
wait1Msec(5);
}
//----------------------------------------------------------------
bool ScoreHighHoldButton = false;
// global variable to hold the gyro value
void CheckScoreHigh()
{
if(vexRT(Btn7UXmtr2) == true)
{
if (ScoreHighHoldButton == true)
{
SensorValue(LED) = 0; // LED OFF
StopTask(BatmanHold);
StopTask(TASKKeepFlipperInPlace);
wait1Msec(500);
// turn off the hold
motor(FlipperMotorLeft) = 0;
motor(FlipperMotorRight) = 0;
motor(RightArm) = 0;
motor(LeftArm) = 0;
ScoreHighHoldButton = false;
}
else
{
SensorValue(LED) = 1; // LED ON
wait1Msec(500);
StartTask(BatmanHold);
ScoreHighHoldButton = true;
//hold the flipper with a value that will hold five bags
StartTask(TASKKeepFlipperInPlace);
Arms(true, ArmsHigh, 127);
// hold arms
motor(RightArm) = 20;
motor(LeftArm) = 20;
}
}
else
{
// if the button is not pressed, do nothing (until the button is pressed again)
}
}
///////////////////////////////////////Start User Control Voids/////////////////////////////////////////////////////////
// The controls for the user control base. It has PID in it (nMotorPIDSpeedCtrl[motorX] = mtrSpeedReg in #pragma config)
// as now doesn't have a ramp motor.
void base()
{
if(vexRT(Btn6U) == 1)
{
motor(LeftBaseBack) = vexRT(Ch3);
motor(LeftBaseFront) = vexRT(Ch3);
motor(RightBaseBack) = vexRT(Ch2);
motor(RightBaseFront) = vexRT(Ch2);
}
else
{
motor(LeftBaseBack) = vexRT(Ch3)/2;
motor(LeftBaseFront) = vexRT(Ch3)/2;
motor(RightBaseBack) = vexRT(Ch2)/2;
motor(RightBaseFront) = vexRT(Ch2)/2;
}
}
void UArms()
{
if(vexRT(Btn8UXmtr2) == 1)
{
goup = true;
while(goup == true)
{
motor(RightArm) = 127;
motor(LeftArm) = 127;
if(SensorValue(ArmPot) == HighGoal || SensorValue(ArmPot) >= HighLimit)
{
goup = false;
motor(RightArm) = 0;
motor(LeftArm) = 0;
}
}
}
motor[RightArm] = vexRT(Ch2Xmtr2)+5; // Lifter Motor 1
motor[LeftArm] = vexRT(Ch2Xmtr2)+5; // Lifter Motor 2
if(vexRT(Btn8DXmtr2) == 1)
{
godown = true;
while(godown == true)
{
motor(RightArm) = -127;
motor(LeftArm) = -127;
if(SensorValue(ArmPot) == HighGoal || SensorValue(ArmPot) <= LowLimit)
{
godown = false;
motor(RightArm) = 0;
motor(LeftArm) = 0;
}
}
}
}
task ConvayerTask()
{
while(1)
{
if(vexRT(Btn6UXmtr2) == 1)
{
motor(Convayer) = 127;
}
if(vexRT(Btn6DXmtr2) == 1)
{
motor(Convayer) = -127;
}
if(vexRT(Btn6DXmtr2) == 0 && vexRT(Btn6UXmtr2) == 0)
{
motor(Convayer) = 0;
}
}
}
void Flipper()
{
motor[FlipperMotorLeft] = vexRT(Ch3Xmtr2);
motor[FlipperMotorRight] = vexRT(Ch3Xmtr2);
}
void HighArmButton()
{
if(vexRT(Btn7U) == 0)
{
Arms(true, ArmsHigh, 127);
}
}
int FlipperGyroValue = 1;
int FlipperMotorHoldValue = 0;
task FlipperGyroHold()
{
// start holding the flipper in place - enter an infinite loop (until stop task is called, the code in here will continue to operate)
while(true)
{
bool bMoveDown = false;
bool bMoveUp = false;
// do whatever you need to do to keep the flipper near the value
if (SensorValue(FlipperGyro) > (FlipperGyroValue + 70))
{
// higher then the allowed threshold = start moving down
bMoveUp = false;
bMoveDown = true;
}
else if (SensorValue(FlipperGyro) < (FlipperGyroValue - 40))
{
// lower then the allowed threshold = start moving up
bMoveUp = true;
bMoveDown = false;
}
if(bMoveUp)
{
FlipperMotorHoldValue -= 1;
motor(FlipperMotorRight) = -40;// FlipperMotorHoldValue;
motor(FlipperMotorLeft) = -40; //FlipperMotorHoldValue;
//wait1Msec(10);
}
else if(bMoveDown)
{
FlipperMotorHoldValue += 1;
motor(FlipperMotorRight) = 40;// FlipperMotorHoldValue;
motor(FlipperMotorLeft) = 40;//FlipperMotorHoldValue;
//wait1Msec(10);
}
else
{
motor(FlipperMotorLeft) = 10;
motor(FlipperMotorRight) = 10;
}
//wait1Msec(10);
}
}
// global variable to check the status of the flipper hold button press
bool FlipperHoldButton = false;
// global variable to hold the gyro value
// add this as one of the functions that gets called in the infinite loop in the user control section of the code
void CheckFlipperHold()
{
if(vexRT(Btn5UXmtr2) == true)
{
if (FlipperHoldButton == true)
{
SensorValue(LED) = 0; // LED OFF
wait1Msec(500);
// turn off the hold
StopTask(BatmanHold);
StopTask(FlipperGyroHold);
FlipperHoldButton = false;
}
else
{
wait1Msec(500);
// turn on the hold
// get the current value of the gyro so we know where to hold the flipper
while(SensorValue(FlipperPot) < FlipperHold)
{
motor(FlipperMotorLeft) = 70;
motor(FlipperMotorRight) = 70;
}
FlipperGyroValue = SensorValue(FlipperGyro);
SensorValue(LED) = 1; // LED ON
StartTask(BatmanHold);
StartTask(FlipperGyroHold);
FlipperHoldButton = true;
}
}
else
{
// if the button is not pressed, do nothing (until the button is pressed again)
}
}
/////////////////////////////////////////////////////////////////////////////////////////
//
// Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
//////////////////////////////////////////////////////////////////////////////////////////
void pre_auton()
{
bLCDBacklight = true;
// 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;
SensorType[in1] = sensorNone;
wait1Msec(1000);
//Reconfigure Analog Port 8 as a Gyro sensor and allow time for ROBOTC to calibrate it
SensorType[in1] = sensorGyro;
wait1Msec(2000);
if(SensorValue(Auton_Pot) > Range1 && SensorValue(Auton_Pot) < Range0)
{
displayLCDCenteredString(0, "AutoScoreFive");
}
if(SensorValue(Auton_Pot) > Range2 && SensorValue(Auton_Pot) < Range1)
{
displayLCDCenteredString(0, "AutoScoreFive");
}
if(SensorValue(Auton_Pot) > Range3 && SensorValue(Auton_Pot) < Range2)
{
displayLCDCenteredString(0, "Fuse");
}
}
/////////////////////////////////////////////////////////////////////////////////////////
//
// 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()
{
bLCDBacklight = true; // have LCD backlight on
clearLCDLine(0); // Clear line 1 (0) of the LCD
clearLCDLine(1); // Clear line 2 (1) of the LCD
//Declare count variable to keep track of our choice
int count = 0;
//------------- Beginning of User Interface Code ---------------
//Clear LCD
clearLCDLine(0);
clearLCDLine(1);
while(1)
{
//Loop while center button is not pressed
//Switch case that allows the user to choose from 4 different options
switch(count){
case 0:
//Display first choice
ClearEncoders();
if(SensorValue(Auton_Pot) > Range1 && SensorValue(Auton_Pot) < Range0)
{
ClearEncoders();
displayLCDCenteredString(0, "ScoreFive");
AutonomousScoreFive();
wait10Msec(5000);
}
if(SensorValue(Auton_Pot) > Range2 && SensorValue(Auton_Pot) < Range1)
{
ClearEncoders();
displayLCDCenteredString(0, "ScoreYellow");
AutonomousScoreYellow();
wait10Msec(5000);
}
if(SensorValue(Auton_Pot) > Range3 && SensorValue(Auton_Pot) < Range2)
{
ClearEncoders();
displayLCDCenteredString(0, "Fuse");
Fuse();
wait10Msec(5000);
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////
//
// 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()
{
StartTask(MulBat);
StartTask(ConvayerTask);
bLCDBacklight = true; // have LCD backlight on
string mainBattery, backupBattery;
//Clear the encoders associated with the left and right motors
nMotorEncoder[RightBaseBack] = 0;
nMotorEncoder[LeftBaseBack] = 0;
nMotorEncoder[RightBaseFront] = 0;
nMotorEncoder[LeftBaseFront] = 0;
// Run Forever
while(1)
{
// Displays the battery level on the LCD
clearLCDLine(0); // Clear line 1 (0) of the LCD
clearLCDLine(1); // Clear line 2 (1) of the LCD
//Display the Primary Robot battery voltage
displayLCDString(0, 0, "Primary: ");
sprintf(mainBattery, "%1.2f%c", nImmediateBatteryLevel/1000.0,'V'); //Build the value to be displayed
displayNextLCDString(mainBattery);
//Display the Backup battery voltage
displayLCDString(1, 0, "Backup: ");
sprintf(backupBattery, "%1.2f%c", BackupBatteryLevel/1000.0, 'V'); //Build the value to be displayed
displayNextLCDString(backupBattery);
//Short delay for the LCD refresh rate
wait1Msec(100);
// Run the base program
base();
//DriverFlipper();
if (ScoreHighHoldButton == false)
{
// run the arms program
UArms();
}
// run the flipper program
CheckScoreHigh();
if (ScoreHighHoldButton == false || FlipperHoldButton == false )
{
// run Flipper program
Flipper();
}
CheckFlipperHold();
}
}
// end of code!!!!!!!!!!
//chupa chupa ;)
//lol what?
//UpUpDownDownLeftRightLeftRightBAStart