-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRobot2012.cpp
1241 lines (1033 loc) · 28.3 KB
/
Robot2012.cpp
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
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "WPILib.h"
#include "math.h"
#include "SubSystems/ElevatorSystem.h"
#include "SubSystems/Drivetrain.h"
#include "SubSystems/RampArm.h"
#include "Util/Switch.h"
#include "Util/XboxController.h"
#include "Util/DeadReckoner.h"
#include "Settings.h"
#include "RobotSupport.cpp"
#include "Vision/VisionProcessorBridge.h"
const static float TURRET_ROTATION_TICKS = 1488;
const static float TILT_ANGLE_JIG_MEASUREMENT = 2.051; //TODO: ENTER THE TILT ANGLE JIG MEASUREMENT
const static UINT32 SENSOR_ELEVATOR_WAIT = 1000000;
const static UINT32 SENSOR_KICKER_WAIT = 500000;
//#include "SubSystems/Shooter.h"
vspMessage myVSPMessage;
uint32_t lastMessageSeen = 0;
vspMessage * getVSPMessage() {
return &myVSPMessage;
}
//Robot Server///////////
STATUS tcpServer (void);
class Smoother
{
public:
float TUNING_CONSTANT;
Smoother (float StartReading)
{
lastReading = StartReading;
TUNING_CONSTANT = .5;
}
float NewValue(float CurrentReading)
{
//new_filtered_value = K*previous_filtered_value + (1-K)* new_sample
CurrentReading = (TUNING_CONSTANT * lastReading) + ((1-TUNING_CONSTANT) * CurrentReading);
lastReading = CurrentReading;
return CurrentReading;
}
private:
float lastReading;
};
class EncoderSmoother
{
public:
double PIDSCALE;
EncoderSmoother(Encoder* enc)
{
/*"K" is a tuning constant, which you use to adjust the "strength" of the filter.
* K must be in the range zero to +1. When K=0, there is no filtering. When K=1, the
* filtering is so "strong" that the filtered value never changes.
*/
TUNING_CONSTANT = .8;
SCALE = 100000.0;
PIDSCALE = 1;
_enc = enc;
encoderCurrent = 0;
encoderLast = 0;
timeLast = GetFPGATime();
timeCurrent = 0;
rate = 0;
newRate = 0;
}
double Get()
{
return rate / PIDSCALE;
}
void Update()
{
encoderCurrent = _enc->Get();
timeCurrent = GetFPGATime();
newRate = (encoderCurrent-encoderLast)*SCALE / (timeCurrent - timeLast);
//new_filtered_value = K*previous_filtered_value + (1-K)* new_sample
rate = (TUNING_CONSTANT * rate) + ((1-TUNING_CONSTANT) * newRate);
encoderLast = encoderCurrent;
timeLast = timeCurrent;
}
double TUNING_CONSTANT;
double SCALE;
private:
Encoder* _enc;
int encoderCurrent ;
int encoderLast;
UINT timeLast;
UINT timeCurrent;
double rate;
double newRate;
};
//Robot Class///////////
class Robot2012 : public SimpleRobot
{
// Drive System //////////////////////
Drivetrain *myRobot;
// Outputs ///////////////////////////
// Vision
PWM* greenLightControl;
// Motors
Victor* bBallRotator;
Victor* bBallPitchMotor;
Victor* bBallShooterTop;
Victor* bBallShooterBottom;
Victor* bBallCollector;
Relay* bBallElevatorBottom;
Relay* bBallElevatorTop;
Servo* rampServo;
// Relay* mockRelay;
// Air
Compressor* airCompressor;
Solenoid* shooterArm;
Solenoid* rampArm;
// Inputs //////////////////////////
// On robot //
// Encoders
Encoder* encoderWheelsLeft;
Encoder* encoderWheelsRight;
Encoder* encoderTurretRotation;
Encoder* encoderShooterTop;
Encoder* encoderShooterBottom;
// Switches
DigitalInput *bBallElevatorTopLimit;
DigitalInput *bBallElevatorBottomLimit;
Switch* shooterSwitch;
Switch* switchAimTrigger;
DigitalInput* sensorCollector;
DigitalInput* sensorElevator;
DigitalInput* sensorKicker;
AnalogChannel* tilt;
// Other
// ADXL345_I2C *accel;
// Gyro *gyro;
// Driver Station //
DriverStation *driverStationControl;
DriverStationLCD* dsLCD;
XboxController *xboxDrive;
XboxController *xboxShoot;
// Systems and Support ///////////////////
ElevatorSystem* robotElevator;
RampArm *robotRampArm;
EncoderSmoother* TopShooterSmoothed;
EncoderSmoother* BottomShooterSmoothed;
Smoother* TiltReadingSmoothed;
// messages from the computer
float msgAngleUp,
msgDistance,
msgRightBasketAngle,
msgCenterBasketAngle,
msgLeftBasketAngle;
bool shooterWheelState;
bool shooting;
bool overrideVSPProcessing;
float speedAdjust;
// global current wheel speed
float bBallTopWheelSpeed,
bBallBottomWheelSpeed,
bBallAngle,
bBallRotationLocation,
bBallAngleOffset;
// double PIDReading;
UINT8 lightValue;
UINT32 opShooterTimer;
UINT32 sensorElevatorTimer;
UINT32 sensorKickerTimer;
PIDScale* PIDTopWheel;
PIDScale* PIDBottomWheel;
PIDScale* PIDTiltReading;
PIDScale* PIDTurretRotation;
DigitalInput *testCompressor;
// float WheelSpeedAtKickTop;
// float WheelSpeedAtKickBottom;
// float TiltAtKick;
public:
void SetupTurret()
{
bBallPitchMotor = new Victor(2, 3);
bBallRotator = new Victor(2, 4);
bBallShooterTop = new Victor(2, 2);
bBallShooterBottom = new Victor(2, 1);
shooterArm = new Solenoid(1);
encoderTurretRotation = new Encoder(2, 3, 2, 4);
encoderShooterTop = new Encoder(2, 5, 2, 6, true, Encoder::k1X);
// encoderShooterBottom = new Encoder(2, 7, 2, 8, false, Encoder::k1X);
encoderShooterBottom = new Encoder(1, 6, 1, 5, true, Encoder::k1X);
tilt = new AnalogChannel(1);
encoderTurretRotation->Start();
encoderShooterTop->Start();
encoderShooterBottom->Start();
TopShooterSmoothed = new EncoderSmoother(encoderShooterTop);
BottomShooterSmoothed = new EncoderSmoother(encoderShooterBottom);
TiltReadingSmoothed = new Smoother(tilt->GetVoltage());
bBallTopWheelSpeed = 0.0;
bBallBottomWheelSpeed = 0.0;
bBallAngle = 2.0 + bBallAngleOffset;
bBallRotationLocation = 0.0;
PIDTopWheel = new PIDScale(11.45, 0.0, 231.85, 1200.0);
PIDBottomWheel = new PIDScale(64.2, 0.0, 2500.0, 1200.0);
PIDTiltReading = new PIDScale(.25, 0.0, 0.0, 0.287);
PIDTurretRotation = new PIDScale(1.0, 0.0, 1.0, 1440.0);
shooterWheelState = false;
shooting = false;
overrideVSPProcessing = false;
opShooterTimer = 0;
}
void SetupCameras()
{
//setup cameras
AxisCamera::GetInstance();
// Outputs //////////////////////////
// Vision
lightValue = 0;
greenLightControl = new PWM(1, 6);
greenLightControl->SetPeriodMultiplier(PWM::kPeriodMultiplier_1X);
greenLightControl->EnableDeadbandElimination(false);
msgAngleUp = 0.0;
msgDistance = 0.0;
msgRightBasketAngle = 0.0;
msgCenterBasketAngle = 0.0;
msgLeftBasketAngle = 0.0;
myVSPMessage.semVSPMessage = semMCreate(SEM_Q_FIFO);
//Robot Server///////////
if (taskSpawn("tcpServer", 100, 0, 10000,
(FUNCPTR) tcpServer, 0,0,0,0,0,0,0,0,0,0) == ERROR)
{
/* if taskSpawn fails, close fd and return to top of loop */
perror ("taskSpawn");
}
}
void SetupCollectorElevator()
{
// collector/elevator
bBallElevatorBottom = new Relay(2, 1, Relay::kBothDirections);
bBallElevatorTop = new Relay(2, 2, Relay::kBothDirections);
bBallCollector = new Victor(2, 5);
bBallElevatorTopLimit = new DigitalInput(2, 2);
bBallElevatorBottomLimit = new DigitalInput(2, 1);
sensorCollector = new DigitalInput(2,12);
sensorElevator = new DigitalInput(2,13);
sensorKicker = new DigitalInput(2,14);
sensorElevatorTimer = 0;
sensorKickerTimer = 0;
// robotElevator = new ElevatorSystem(bBallElevatorTop, mockRelay, bBallElevatorBottomLimit, bBallElevatorTopLimit);
robotElevator = new ElevatorSystem(bBallElevatorBottom,
bBallElevatorTop,
bBallElevatorBottomLimit,
bBallElevatorTopLimit
);
}
void SetupArm()
{
// ramp
rampServo = new Servo(2, 6);
rampArm = new Solenoid(2);
robotRampArm = new RampArm(rampServo, rampArm);
}
void SetupRobot()
{
// On robot //
encoderWheelsLeft = new Encoder(1, 3, 1, 4, true);
encoderWheelsRight = new Encoder(1, 1, 1, 2, false);
encoderWheelsLeft->Start();
encoderWheelsRight->Start();
// Drive System /////////////////////
// Adjust speed of drive
speedAdjust = 1.0;
myRobot = new Drivetrain(3, 4, 1, 2, encoderWheelsLeft, encoderWheelsRight); // create robot drive base
// other
// Air
airCompressor = new Compressor(1, 10, 2, 3);
airCompressor->Start();
testCompressor = new DigitalInput(1,10);
// Other
// accel = new ADXL345_I2C(1);
// gyro = new Gyro(1);
}
void SetupDriverStation()
{
// Driver Station //
driverStationControl = DriverStation::GetInstance();
dsLCD = DriverStationLCD::GetInstance();
xboxDrive = new XboxController(1);
xboxShoot = new XboxController(2);
}
/**
* Create an instance of a RobotDrive with left and right motors plugged into PWM
*/
Robot2012(void)
{
SetupTurret();
SetupCameras();
SetupCollectorElevator();
SetupArm();
SetupRobot();
SetupDriverStation();
}
void processVisionBridge(char * msg)
{
char * workingMessage = strtok(msg,",");
do
{
double value = atof(&workingMessage[1]);
switch(workingMessage[0])
{
case 'a': msgAngleUp = value; break;
case 'd': msgDistance = value; break;
case 'r': msgRightBasketAngle = value; break;
case 'm': msgCenterBasketAngle = value; break;
case 'l': msgLeftBasketAngle = value; break;
}
} while (workingMessage = strtok(0, ","));
}
void processVSPMessage()
{
semTake(myVSPMessage.semVSPMessage, WAIT_FOREVER);
if (myVSPMessage.count > lastMessageSeen) {
lastMessageSeen = myVSPMessage.count;
processVisionBridge(myVSPMessage.buf);
}
semGive(myVSPMessage.semVSPMessage);
}
void SetAngle(float degrees)
{
}
/**
* Drive left & right motors for 2 seconds, enabled by a jumper (jumper
* must be in for autonomous to operate).
*/
void Autonomous(void)
{
CalculateTiltOffset();
greenLightControl->SetRaw(255);
myRobot->ResetPosition();
shooterArm->Set(false);
// UINT32 waitForArmFirstShot = 0;
// UINT32 waitForArmSecondShot = 0;
// UINT32 loadSecondBallWait = 0;
UINT32 wheelSpinupStart = 0;
UINT32 timer = 0;
UINT32 elapsedTime = 0;
int state = 0;
//Auto one steps
// bool shotFirstBall = false;
// bool drivenToBridge = false;
// bool autoDone = false;
bool shotSecondBall = false;
bool shooting = false;
bBallAngle = 2.0 + bBallAngleOffset;
bBallBottomWheelSpeed = 0.0;
bBallTopWheelSpeed = 0.0;
bBallRotationLocation = 0.0;
while(IsAutonomous() && IsEnabled())
{
/*
* ========================= Select 1 ==============================
*
* Shoot Twice
*/
if(!driverStationControl->GetDigitalIn(1))
{
overrideVSPProcessing = true;
myRobot->Periodic(0.0, 0.0, true);
bBallAngle = 2.12 + bBallAngleOffset;
bBallTopWheelSpeed = 170.0;
bBallBottomWheelSpeed = 1080.0;
shooterWheelState = true;
processVSPMessage();
if(wheelSpinupStart == 0)
{
wheelSpinupStart = GetFPGATime();
}
elapsedTime = GetFPGATime() - wheelSpinupStart;
//wait for time
if(elapsedTime < 6000000)
{
// wait for go time
}
//shoot first
else if(elapsedTime < 6500000)
{
shooting = true;
shooterArm->Set(true);
}
//run elevator
else if(elapsedTime < 6700000)
{
//set elevator up
robotElevator->PeriodicSystem(true);
}
//pull arm back
else if(elapsedTime < 13000000)
{
shooting = false;
shooterArm->Set(false);
}
//shoot again
else if(elapsedTime < 13500000)
{
shooting = true;
shooterArm->Set(true);
}
//stop shooting
else if(elapsedTime < 14000000)
{
shooting = false;
shooterArm->Set(false);
overrideVSPProcessing = false;
}
robotElevator->PeriodicSystem(false);
}
/*
* ========================= Select 2 ==============================
*
* Drive to bridge
* Lower Bridge
* Drive back
* Shoot twice
*/
else if(!driverStationControl->GetDigitalIn(2))
{
//set angle to make it from top of key
bBallAngle = 2.1 + bBallAngleOffset;
//Set Wheel Speeds to make it from the bridge
bBallTopWheelSpeed = 400.0;
bBallBottomWheelSpeed = 1100.0;
shooterWheelState = true;
processVSPMessage();
if(state == 0)
{
robotRampArm->PeriodicSystem(true);
state++;
}
//drive to bridge
if(state == 1)
{
// if(myRobot->PositionY() < 30.0)
if(myRobot->PositionY() < 60.0)
{
myRobot->Periodic(-1.0, -1.0, true);
}
else if(myRobot->PositionY() < 67.0)
{
myRobot->Periodic(-0.97, -0.97, true);
}
else
{
state++;
}
}
if(state == 2)
{
// if(myRobot->PositionY() < 58.0)
if(myRobot->PositionY() < 84.0)
{
myRobot->Periodic(-0.77, -0.77, true);
}
else
{
state++;
}
}
//wait
if(state == 3)
{
if(timer == 0)
{
timer = GetFPGATime();
}
if(GetFPGATime() - timer < 2000000)
{
myRobot->Periodic(0.0, 0.0, true);
}
else
{
state++;
timer = 0;
}
}
//drive back
if(state == 4)
{
if(myRobot->PositionY() >= 5.0)
{
myRobot->Periodic(0.83, 0.83, true);
}
else
{
state++;
}
}
//shoot
if(state == 5)
{
myRobot->Periodic(0.0, 0.0, true);
if(timer == 0)
{
timer = GetFPGATime();
}
elapsedTime = GetFPGATime() - timer;
if(elapsedTime < 500000)
{
}
else if(elapsedTime < 600000)
{
OpShooter(true);
robotElevator->PeriodicSystem(true);
robotRampArm->PeriodicSystem(true);
}
else if(elapsedTime < 6500000)
{
//wait
}
else if(elapsedTime < 6600000)
{
OpShooter(true);
}
}
robotRampArm->PeriodicSystem(false);
robotElevator->PeriodicSystem(false);
OpShooter(false);
}
/*
* ========================= Select 3 ==============================
*
* Drive to bridge
* Lower bridge
* Shoot twice
* Back up
* Raise Arm
*/
/*else if(!driverStationControl->GetDigitalIn(3))
{
//set angle to make it from the bridge
bBallAngle = 2.01 + bBallAngleOffset;
//Set Wheel Speeds to make it from the bridge
bBallTopWheelSpeed = 400.0;
bBallBottomWheelSpeed = 1320.0;
// bBallBottomWheelSpeed = 1800.0;
// bBallTopWheelSpeed = driverStationControl->GetAnalogIn(1)*1300/5;
// bBallBottomWheelSpeed = driverStationControl->GetAnalogIn(2)*1300/5;
//Turn on shooter wheels
shooterWheelState = true;
//Follow Turret
processVSPMessage();
//Ramp arm down
if(robotRampArm->IsRampUp && !autoDone)
{
robotRampArm->PeriodicSystem(true);
}
//drive to bridge
if(myRobot->PositionY() < 60.0)
{
myRobot->Periodic(-(driverStationControl->GetAnalogIn(4)/5.), -(driverStationControl->GetAnalogIn(4)/5.), true);
}
//reached bridge
else
{
if(!shotSecondBall)
{
myRobot->Periodic(0.0, 0.0, true);
}
}
if(myRobot->PositionY() >= 60.0)
{
if(wheelSpinupStart == 0)
{
wheelSpinupStart = GetFPGATime();
}
if(GetFPGATime() - wheelSpinupStart > 5000000)
{
drivenToBridge = true;
}
}
if(drivenToBridge && !shotFirstBall)
{
//take first shot
shooting = true;
shooterArm->Set(true);
if(waitForArmFirstShot == 0){
waitForArmFirstShot = GetFPGATime();
}
if(GetFPGATime() - waitForArmFirstShot > 400000)
{
shooting = false;
shooterArm->Set(false);
shotFirstBall = true;
}
}
if(shotFirstBall)
{
//set elevator up
bBallElevatorTop->Set(Relay::kOn);
bBallElevatorTop->Set(Relay::kReverse);
if(loadSecondBallWait == 0)
{
loadSecondBallWait = GetFPGATime();
}
if(GetFPGATime() - loadSecondBallWait > 4000000)
{
shooting = true;
shooterArm->Set(true);
shotSecondBall = true;
}
}
if(shotSecondBall)
{
if(myRobot->PositionY() >= 30.0)
{
myRobot->Periodic((driverStationControl->GetAnalogIn(4)/5.), (driverStationControl->GetAnalogIn(4)/5.), true);
}
else
{
autoDone = true;
if(!robotRampArm->IsRampUp && autoDone)
{
robotRampArm->PeriodicSystem(true);
}
}
}
}*/
driverStationControl->SetDigitalOut(3, shotSecondBall);
OpTurret(false);
Debug();
Wait(.005);
}
}
void OpShooter(bool wantToShoot)
{
bool shoot = false;
if(wantToShoot && !shooting)
{
shoot = true;
}
if(IsOperatorControl() && driverStationControl->GetDigitalIn(7))
{
if (robotElevator->IsRunning)
{
shoot = false;
}
if (sensorKicker->Get())
{
// Start timer
if(sensorKickerTimer == 0)
{
sensorKickerTimer = GetFPGATime();
}
// Wait for ball to settle
if (GetFPGATime() - sensorKickerTimer < SENSOR_KICKER_WAIT)
{
shoot = false;
}
}
else
{
sensorKickerTimer = 0;
}
}
if(shooting || shoot)
{
if(opShooterTimer == 0)
{
opShooterTimer = GetFPGATime();
shooting = true;
}
if(GetFPGATime() - opShooterTimer < 500000)
{
shooterArm->Set(true);
}
else if(GetFPGATime() - opShooterTimer < 1000000)
{
shooterArm->Set(false);
}
else
{
shooting = false;
opShooterTimer = 0;
}
}
}
void OpTurret(bool gotMessage)
{
// Aim ////////////////////////////////
//----------
// float rotationChange = PIDTurretRotation->CalculateChange((float)(encoderTurretRotation->Get()), driverStationControl->In(4)*1488.0/2.5 - 1488);
float rotationChange = PIDTurretRotation->CalculateChange((float)(encoderTurretRotation->Get()), bBallRotationLocation);
//rotator here.....--------------------------------------------------------------------------
///Track Cener Basket
// -10000 == don't know
if(msgCenterBasketAngle > -6000 && driverStationControl->GetDigitalIn(8) && !overrideVSPProcessing)
{
rotationChange = msgCenterBasketAngle / 10.0;
// Offset Slider
rotationChange += (driverStationControl->GetAnalogIn(3) - 2.5) * .04;
if( rotationChange < 100.0 && rotationChange > .015)
{
rotationChange = 0.1365;
}
else if( rotationChange > -100.0 && rotationChange < -.015)
{
rotationChange = -0.125;
}
bBallRotationLocation = encoderTurretRotation->Get();
}
if(fabs(xboxShoot->GetRightX()) > .2)
{
rotationChange = xboxShoot->GetRightX();
bBallRotationLocation = encoderTurretRotation->Get();
}
if(encoderTurretRotation->Get() > TURRET_ROTATION_TICKS && bBallRotationLocation > 0.0){
rotationChange = 0.0;
}
// If rotation too low, will stop the motor
if(encoderTurretRotation->Get() < -TURRET_ROTATION_TICKS && bBallRotationLocation < 0.0){
rotationChange = 0.0;
}
bBallRotator->Set(rotationChange);
//---------------------------------------------Tilt--------------------------------
float tiltChange = PIDTiltReading->CalculateChange(TiltReadingSmoothed->NewValue(tilt->GetVoltage()),bBallAngle);
if(tiltChange > -.22 && tiltChange < -.01)
{
tiltChange = -.22;
}
else if(tiltChange < .33 && tiltChange > .01)
{
tiltChange = .33;
}
if(fabs(xboxShoot->GetLeftY()) > 0.2)
{
tiltChange = xboxShoot->GetLeftY();
bBallAngle = TiltReadingSmoothed->NewValue(tilt->GetVoltage());
//down
if(tiltChange < 0 )
{
tiltChange /= 4.0;
}
//up
else
{
tiltChange /= 2.1;
}
}
// this code is for vpc
// else
// {
// if(tiltChange < 0 )
// {
// tiltChange = tiltChange * 8.0;
// }
// else
// {
// tiltChange = tiltChange * 10.0;
// }
// }
// If tilt is too high, will SAY NO!
if(tilt->GetVoltage() > (2.28 + bBallAngleOffset) && tiltChange > 0.0){
tiltChange = 0.0;
}
// If tilt too low, will stop the motor
if(tilt->GetVoltage() < (2.0 + bBallAngleOffset) && tiltChange < 0.0){
tiltChange = 0.0;
}
bBallPitchMotor->Set(tiltChange);
//------------------------------- spin wheels -----------------------
TopShooterSmoothed->Update();
BottomShooterSmoothed->Update();
//Spin up wheels
float topChange = PIDTopWheel->CalculateChange(TopShooterSmoothed->Get(),bBallTopWheelSpeed);
float botChange = PIDBottomWheel->CalculateChange(BottomShooterSmoothed->Get(),bBallBottomWheelSpeed);
// Collect and Shoot bBalls///////////
// right button or right trigger (ignoring accidents)
if(xboxShoot->GetRB() || xboxShoot->GetRightTrigger() < -.1){
shooterWheelState = true;
}
// left button or left trigger (ignoring accidents)
if(xboxShoot->GetLB() || xboxShoot->GetLeftTrigger() > .1){
shooterWheelState = false;
}
driverStationControl->SetDigitalOut(1, shooterWheelState);
driverStationControl->SetDigitalOut(2, shooterArm->Get());
if(shooterWheelState)
{
if (!shooterArm->Get() || PIDTopWheel->CurrentMotorValue < 0.1)
{
PIDTopWheel->CurrentMotorValue += topChange;
if (PIDTopWheel->CurrentMotorValue > 1) { PIDTopWheel->CurrentMotorValue = 1; }
if (PIDTopWheel->CurrentMotorValue < 0) { PIDTopWheel->CurrentMotorValue = 0; }
PIDBottomWheel->CurrentMotorValue += botChange;
if (PIDBottomWheel->CurrentMotorValue > 1) { PIDBottomWheel->CurrentMotorValue = 1; }
if (PIDBottomWheel->CurrentMotorValue < 0) { PIDBottomWheel->CurrentMotorValue = 0; }
}
bBallShooterTop->Set(PIDTopWheel->CurrentMotorValue);
bBallShooterBottom->Set(PIDBottomWheel->CurrentMotorValue);
}
else
{
PIDTopWheel->zeroOut();
PIDBottomWheel->zeroOut();
bBallShooterTop->Set(0.0);
bBallShooterBottom->Set(0.0);
}
}
void OpElevator()
{
// ELEVATORS //////////////////////////////
// REVERSE IS UP ///////////
// bottom down
if(xboxShoot->GetSelect()){
robotElevator->ManualFreezeAll();
bBallElevatorBottom->Set(Relay::kOn);
bBallElevatorBottom->Set(Relay::kForward);
}else
// bottom up
if(xboxShoot->GetStart()){
robotElevator->ManualFreezeAll();
bBallElevatorBottom->Set(Relay::kOn);
bBallElevatorBottom->Set(Relay::kReverse);
}else{
bBallElevatorBottom->Set(Relay::kOff);
}
// top down
if(xboxShoot->GetX()){
bBallElevatorTop->Set(Relay::kOn);
bBallElevatorTop->Set(Relay::kForward);
}else
// top up
if(xboxShoot->GetB()){
bBallElevatorTop->Set(Relay::kOn);
bBallElevatorTop->Set(Relay::kReverse);
}else{
bBallElevatorTop->Set(Relay::kOff);
}
bool runElevator = xboxShoot->GetY();
if(IsOperatorControl() && driverStationControl->GetDigitalIn(7))
{