-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRobotCode.cpp
More file actions
1026 lines (877 loc) · 29.8 KB
/
RobotCode.cpp
File metadata and controls
1026 lines (877 loc) · 29.8 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
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 "DashboardDataSender.h"
#include "math.h"
#include "timer.h"
#define ABUTTON 1
#define BBUTTON 2
#define XBUTTON 3
#define YBUTTON 4
#define START 7
#define LBUMPER 5
#define RBUMPER 6
#define LSTICKP 9
#define RSTICKP 10
#define DPADVERT 7
#define DPADSIDE 6
#define BACK 8
#define ANSWER 0x2A
class BuiltinDefaultCode : public IterativeRobot
{
// Declare a variable to use to access the driver station object
DriverStation *m_ds; // driver station object
UINT32 m_priorPacketNumber; // keep track of the most recent packet number from the DS
UINT8 m_dsPacketsReceivedInCurrentSecond; // keep track of the ds packets received in the current second
// Variable for the Smart Dashboard
//SmartDashboard *dash;
//variable for encoder
double encoder_zero;
// Variable for front/back switch
int front; // 1 is shooter front -1 is gather front
//Declare robot drive
RobotDrive *m_robotdrive;
DriverStationLCD *d_st;
// Declare variables for the two joysticks being used
Joystick *m_controller; // joystick 1 (arcade stick or right tank stick)
Joystick *m_tech; // joystick 2 (tank left stick)
// Variable for the compressor
Compressor *m_compressor;
//variable for timer
Timer *m_timer;
// Variable for the solenoid
Solenoid *m_solenoid1;//bridge tipper
Solenoid *m_solenoid2;//bridge tipper
Solenoid *m_solenoid3;//omniwheels
Solenoid *m_solenoid4;//omniwheels
Solenoid *m_solenoid5;//solenoid pi
Solenoid *m_solenoid6;//solenoid pi
Solenoid *m_solenoid7;//super shifter
Solenoid *m_solenoid8;//super shifter
//variables for bridge toggle
int start_last;
int bridge_status;
//variables for solenoid pi toggle
int back_last;
int solenoid_pi_status;
//variable for x button switch
int xbutton_last;
//variable for manual shooter increase
bool tech5_last;
//variable for manual shooter decrease
bool tech10_last;
//variable for auton mode
int auton_mode;
int auton_speed;
int auton_waitTime; //wait time should be in milliseconds
double auton_distance; //how far to drive backwards
// robot motors
CANJaguar *jaguar1; ///1-4 wheels
CANJaguar *jaguar2;
CANJaguar *jaguar3;
CANJaguar *jaguar4;
CANJaguar *jaguar5; ///shooter
CANJaguar *jaguar6; ///shooter (spike for feed)
CANJaguar *jaguar7; /// ball gatherer
// limit switches
//DigitalInput *limit1; //stops ball from launching
// spike
Relay *spike1; //feed motor
//Relay *; //Ball Gatherer
Relay *spike3; //ball agitator
///values to set motors
double setValue1,setValue2;
///shooter speed (pwm)
int SSpeed;
// Variable for the encoders
Encoder *m_encoder;
// Variable for the Axis Camera
// AxisCamera *m_camera;
Image *image1;
// Dashboard Data Sender
// DashboardDataSender *m_dds;
static const int NUM_JOYSTICK_BUTTONS = 16;
bool m_controllerButtonState[(NUM_JOYSTICK_BUTTONS+1)];
bool m_techButtonState[(NUM_JOYSTICK_BUTTONS+1)];
enum { // drive mode selection
UNINITIALIZED_DRIVE = 0,
ARCADE_DRIVE = 1,
TANK_DRIVE = 2
} m_driveMode;
// Local variables to count the number of periodic loops performed
UINT32 m_autoPeriodicLoops;
UINT32 m_disabledPeriodicLoops;
UINT32 m_telePeriodicLoops;
public:
BuiltinDefaultCode(void) {
printf("BuiltinDefaultCode Constructor Started\n");
// Acquire the Driver Station object
m_ds = DriverStation::GetInstance();
m_priorPacketNumber = 0;
m_dsPacketsReceivedInCurrentSecond = 0;
// Initialize SmartDashboard
//dash = SmartDashboard::GetInstance();
// Initialize Driver Station
d_st = DriverStationLCD::GetInstance();
// Define joysticks being used at USB port #1 and USB port #2 on the Drivers Station
m_controller = new Joystick(1);
m_tech = new Joystick(2);
//define encoder_zero
encoder_zero = 0;
//define bridge_status
bridge_status = 1;
//define solenoid pi status
solenoid_pi_status = 1; // 1 = up -1 = down
// Define compressor
m_compressor = new Compressor(1, 3);
//Define variable front
front = 1;
// Define solenoid
m_solenoid1 = new Solenoid(1);//bridge tipper
m_solenoid2 = new Solenoid(2);//bridge tipper
m_solenoid3 = new Solenoid(3);//omniwheels
m_solenoid4 = new Solenoid(4);//omniwheels
m_solenoid5 = new Solenoid(5);//solenoid pi
m_solenoid6 = new Solenoid(6);//solenoid pi
m_solenoid7 = new Solenoid(7);//super shifter
m_solenoid8 = new Solenoid(8);//super shifter
//xbutton_last initial value
xbutton_last = 0;
//tech5_last initial value
tech5_last = 0;
//tech10_last initial value
tech10_last = 0;
//SSpeed initial value
SSpeed = 2300;
// Define motor
jaguar1 = new CANJaguar(5, CANJaguar::kPercentVbus); //1-4 wheels
jaguar2 = new CANJaguar(2, CANJaguar::kPercentVbus);
jaguar3 = new CANJaguar(6, CANJaguar::kPercentVbus);
jaguar4 = new CANJaguar(3, CANJaguar::kPercentVbus);
jaguar5 = new CANJaguar(7, CANJaguar::kVoltage); //shooter
jaguar6 = new CANJaguar(4, CANJaguar::kSpeed); //shooter ///has encoder
jaguar7 = new CANJaguar(9, CANJaguar::kPercentVbus);
//set jags to coast or brake
jaguar6->ConfigNeutralMode(CANJaguar::kNeutralMode_Coast);//shooter
jaguar5->ConfigNeutralMode(CANJaguar::kNeutralMode_Coast);//shooter
jaguar1->ConfigNeutralMode(CANJaguar::kNeutralMode_Brake);//wheel
jaguar2->ConfigNeutralMode(CANJaguar::kNeutralMode_Brake);//wheel
jaguar3->ConfigNeutralMode(CANJaguar::kNeutralMode_Brake);//wheel
jaguar4->ConfigNeutralMode(CANJaguar::kNeutralMode_Brake);//wheel
//define robotdrive
m_robotdrive = new RobotDrive(jaguar1,jaguar2,jaguar3,jaguar4);
//m_robotdrive->SetInvertedMotor(RobotDrive::kFrontLeftMotor,true);
//m_robotdrive->SetInvertedMotor(RobotDrive::kFrontRightMotor,true);
// Define spikes
spike1 = new Relay(1, 1, Relay::kBothDirections); ///feed motor
// = new Relay(1, 2, Relay::kBothDirections); ///Ball Gatherer
spike3 = new Relay(1, 4, Relay::kBothDirections); ///ball agitator
//define Timer
m_timer = new Timer();
// Define encoder
m_encoder = new Encoder(5,6,true);
m_encoder->Start();
//Defualt value for auton_speed
auton_speed = 2300;
auton_mode = 0;
auton_waitTime = 0;
auton_distance = 16.5;
// Define camera
/*m_camera = &AxisCamera::GetInstance("10.33.22.11");
m_camera->WriteResolution(AxisCamera::kResolution_320x240);
m_camera->WriteCompression(20);
m_camera->WriteBrightness(0);*/
// Define dashboard data sender
// m_dds = new DashboardDataSender;
// Iterate over all the buttons on each joystick, setting state to false for each
UINT8 buttonNum = 1; // start counting buttons at button 1
for (buttonNum = 1; buttonNum <= NUM_JOYSTICK_BUTTONS; buttonNum++) {
m_controllerButtonState[buttonNum] = false;
m_techButtonState[buttonNum] = false;
}
// Set drive mode to uninitialized
m_driveMode = UNINITIALIZED_DRIVE;
// Initialize counters to record the number of loops completed in autonomous and teleop modes
m_autoPeriodicLoops = 0;
m_disabledPeriodicLoops = 0;
m_telePeriodicLoops = 0;
}
/********************************** Init Routines *************************************/
void RobotInit(void) {
// Actions which would be performed once (and only once) upon initialization of the
// robot would be put here.
printf("RobotInit() completed.\n");
}
void DisabledInit(void) {
m_disabledPeriodicLoops = 0; // Reset the loop counter for disabled mode
ClearSolenoidLEDsKITT();
//dash->init();
// Move the cursor down a few, since we'll move it back up in periodic.
printf("\x1b[2B");
m_compressor->Start();
spike3->Set(Relay::kOff); //sets ball agitator to off
d_st->Clear(); //clears driver station
}
void AutonomousInit(void) {
m_autoPeriodicLoops = 0; // Reset the loop counter for autonomous mode
ClearSolenoidLEDsKITT();
jaguar1->EnableControl();
jaguar2->EnableControl();
jaguar3->EnableControl();
jaguar4->EnableControl();
jaguar5->EnableControl();
jaguar6->EnableControl();
///encoders for drive and shooter
//must find jaguar numbers for encoders for drive.
jaguar2->SetSpeedReference(CANJaguar::kSpeedRef_QuadEncoder);
jaguar2->SetPositionReference(CANJaguar::kPosRef_QuadEncoder);
jaguar2->ConfigEncoderCodesPerRev(360);
jaguar4->SetSpeedReference(CANJaguar::kSpeedRef_QuadEncoder);
jaguar4->SetPositionReference(CANJaguar::kPosRef_QuadEncoder);
jaguar4->ConfigEncoderCodesPerRev(360);
jaguar6->SetSpeedReference(CANJaguar::kSpeedRef_QuadEncoder);
jaguar6->SetPositionReference(CANJaguar::kPosRef_QuadEncoder);
jaguar6->ConfigEncoderCodesPerRev(360);
jaguar6->SetPID(0.1, 0.003, 0);
//encoders for drive
jaguar1->SetPositionReference(CANJaguar::kPosRef_QuadEncoder);
jaguar1->SetSpeedReference(CANJaguar::kSpeedRef_QuadEncoder);
jaguar1->ConfigEncoderCodesPerRev(82);
m_compressor->Start();
d_st->Clear();
encoder_zero = jaguar1->GetPosition();
}
void TeleopInit(void) {
m_telePeriodicLoops = 0; // Reset the loop counter for teleop mode
m_dsPacketsReceivedInCurrentSecond = 0; // Reset the number of dsPackets in current second
m_driveMode = UNINITIALIZED_DRIVE; // Set drive mode to uninitialized
ClearSolenoidLEDsKITT();
jaguar1->EnableControl(0.0);
jaguar1->EnableControl(0.0);
jaguar2->EnableControl();
jaguar3->EnableControl();
jaguar4->EnableControl();
jaguar5->EnableControl();
jaguar6->EnableControl();
///encoders for shooter
jaguar6->SetPositionReference(CANJaguar::kPosRef_QuadEncoder);
jaguar6->SetSpeedReference(CANJaguar::kSpeedRef_QuadEncoder);
jaguar6->ConfigEncoderCodesPerRev(360);
jaguar6->SetPID(0.1, 0.003, 0);
//encoders for drive
jaguar1->SetPositionReference(CANJaguar::kPosRef_QuadEncoder);
jaguar1->SetSpeedReference(CANJaguar::kSpeedRef_QuadEncoder);
jaguar1->ConfigEncoderCodesPerRev(82);
m_compressor->Start();
m_robotdrive->SetExpiration(0.1);
m_robotdrive->SetSafetyEnabled(true);
d_st->Clear();
}
/********************************** Periodic Routines *************************************/
void DisabledPeriodic(void) {
// increment the number of disabled periodic loops completed
m_disabledPeriodicLoops++;
static bool button1 = false; //decrement
static bool button2 = false; //move speed by 100
static bool button3 = false; //move speed by 10
static bool button4 = false; //mode
static bool button5 = false; //wait
static bool button6 = false;
static bool button7 = false;
int incrementOrDecrement; //1 if increment -1 if decrement
if(m_tech->GetRawButton(1))
incrementOrDecrement = -1;
else
incrementOrDecrement = 1;
if(m_tech->GetRawButton(2) && !button2)
auton_speed += 100*incrementOrDecrement;
else if(m_tech->GetRawButton(3) && !button3)
auton_speed += 10*incrementOrDecrement;
if(m_tech->GetRawButton(4) && !button4)
auton_mode += incrementOrDecrement;
if(m_tech->GetRawButton(5) && !button5)
auton_waitTime += incrementOrDecrement;
if(m_tech->GetRawButton(6) && !button6)
auton_distance += incrementOrDecrement;
if(m_tech->GetRawButton(7) && !button7)
auton_distance += 0.1*incrementOrDecrement;
button1 = m_tech->GetRawButton(1);
button2 = m_tech->GetRawButton(2);
button3 = m_tech->GetRawButton(3);
button4 = m_tech->GetRawButton(4);
button5 = m_tech->GetRawButton(5);
button6 = m_tech->GetRawButton(6);
button7 = m_tech->GetRawButton(7);
d_st->Printf(DriverStationLCD::kUser_Line1,1,"Shooter speed = %d ",auton_speed);
d_st->Printf(DriverStationLCD::kUser_Line2,1,"Auton wait time = %d ",auton_waitTime);
d_st->Printf(DriverStationLCD::kUser_Line3,1,"Autonomous mode = %d ",auton_mode);
//d_st->Printf(DriverStationLCD::kUser_Line4,1,"Autonomous distance = %d ",auton_distance);
d_st->UpdateLCD();
}
void AutonomousPeriodic(void) {
d_st->Printf(DriverStationLCD::kUser_Line4,1,"Encoder = %f ",jaguar1->GetPosition() - encoder_zero);
switch (auton_mode)
{
case 1:
AutonomousMode1();
break;
case 2:
AutonomousMode2();
break;
case 3:
AutonomousMode3();
break;
default:
AutonomousMode1();
}
m_autoPeriodicLoops++;
//printf("encoder value: %d\n", m_encoder->GetRaw());
/* the below code (if uncommented) would drive the robot forward at half speed
* for two seconds. This code is provided as an example of how to drive the
* robot in autonomous mode, but is not enabled in the default code in order
* to prevent an unsuspecting team from having their robot drive autonomously!
*/
/* below code commented out for safety*/
}
void TeleopPeriodic(void) {
printf("derpitworks herp\n");
// increment the number of teleop periodic loops completed
m_telePeriodicLoops++;
/*
* No longer needed since periodic loops are now synchronized with incoming packets.
if (m_ds->GetPacketNumber() != m_priorPacketNumber) {
*/
m_dsPacketsReceivedInCurrentSecond++; // increment DS packets received
setValue1 = m_controller->GetY()-m_controller->GetTwist();
setValue2 = -(m_controller->GetY()+m_controller->GetTwist());
//this button will manually run the compressor
//if (m_controller->GetRawButton(YBUTTON))
//m_compressor->Start(); ///should use instead
// if the X button is pressed the direction of the front of the robot will change.
/*if (m_controller->GetRawButton(XBUTTON)&& !xbutton_last)
{
front *= -1;
}*/
xbutton_last = m_controller->GetRawButton(XBUTTON);
//ball agitator
if(m_controller->GetRawButton(BBUTTON))
{
spike3->Set(Relay::kOn);
spike3->Set(Relay::kReverse);
}
else if(m_controller->GetRawButton(XBUTTON))
{
spike3->Set(Relay::kOn);
spike3->Set(Relay::kForward);
}
else
{
spike3->Set(Relay::kOff);
}
//start compressor
m_compressor->Start();
//DriveRobot(jaguar1, jaguar2, jaguar3, jaguar4, setValue1, setValue2);
m_robotdrive->ArcadeDrive(m_controller,2,m_controller,4);
//code for manual variable shooter speed
static bool button1 = false; //decrement
static bool button2 = false; //move speed by 100
static bool button3 = false; //move speed by 10
static bool button4 = false; //mode
static bool button5 = false; //wait
int incrementOrDecrement; //1 if increment -1 if decrement
if(m_tech->GetRawButton(1))
incrementOrDecrement = -1;
else
incrementOrDecrement = 1;
if(m_tech->GetRawButton(2) && !button2)
SSpeed += 100*incrementOrDecrement;
else if(m_tech->GetRawButton(3) && !button3)
SSpeed += 10*incrementOrDecrement;
if(m_tech->GetRawButton(4) && !button4)
auton_mode += incrementOrDecrement;
if(m_tech->GetRawButton(5) && !button5)
auton_waitTime += incrementOrDecrement;
if(m_tech->GetRawButton(6))
{
SSpeed = 2300;
}
if(m_tech->GetRawButton(7))
{
SSpeed = 4000;
}
if(m_tech->GetRawButton(8))
{
encoder_zero = jaguar1->GetPosition();
}
button1 = m_tech->GetRawButton(1);
button2 = m_tech->GetRawButton(2);
button3 = m_tech->GetRawButton(3);
button4 = m_tech->GetRawButton(4);
button5 = m_tech->GetRawButton(5);
///bridge tipper
if (m_controller->GetRawButton(START) && !start_last)
{
bridge_status *= -1;
}
if(bridge_status == -1)
{
m_solenoid1->Set(true);
m_solenoid2->Set(false);
}
else if(bridge_status == 1)
{
m_solenoid1->Set(false);
m_solenoid2->Set(true);
}
start_last = m_controller->GetRawButton(START);
///omniwheels
if (m_controller->GetRawButton(LSTICKP))
{
m_solenoid3->Set(true);
m_solenoid4->Set(false);
}
else
{
m_solenoid3->Set(false);
m_solenoid4->Set(true);
}
///solenoid pi
if(m_controller->GetRawButton(BACK)&& !back_last)
{
solenoid_pi_status *= -1;
}
if(solenoid_pi_status == -1)
{
m_solenoid5->Set(false);
m_solenoid6->Set(true);
}
else if(solenoid_pi_status == 1)
{
m_solenoid5->Set(true);
m_solenoid6->Set(false);
}
back_last = m_controller->GetRawButton(BACK);
///super shifters
if (m_controller->GetRawButton(LSTICKP))
{
m_solenoid7->Set(true);
m_solenoid8->Set(false);
}
else
{
m_solenoid7->Set(false);
m_solenoid8->Set(true);
}
///ball gatherer
if(m_controller->GetRawButton(ABUTTON))
{
jaguar7->Set(1);
}
else if(m_controller->GetRawButton(YBUTTON))
{
jaguar7->Set(-1);
}
else
{
jaguar7->Set(0);
}
///shooter motor
if(m_controller->GetRawAxis(3)<0) ///motor on
{
jaguar6->Set(SSpeed);//-m_controller->GetRawAxis(3)*12); ///get rid of the -1 on competition robot
jaguar5->Set(jaguar6->GetOutputVoltage());//-m_controller->GetRawAxis(3)*12);
if (jaguar6->GetSpeed() > 0.8*SSpeed) ///change to 0.9 on competition robot
{
spike1->Set(Relay::kOn);
spike1->Set(Relay::kForward);
}
else
{
spike1->Set(Relay::kOff);
}
}
else //// motor off
{
jaguar5->Set(0);
jaguar6->Set(0);
if(m_controller->GetRawButton(LBUMPER))
{
spike1->Set(Relay::kOn);
spike1->Set(Relay::kReverse);
}
else if(m_controller->GetRawButton(RBUMPER))
{
spike1->Set(Relay::kOn);
spike1->Set(Relay::kForward);
}
else
spike1->Set(Relay::kOff);
}
////////////feed motor
/*if(m_controller->GetRawButton(LBUMPER)) ///feed motor forward
{
spike1->Set(Relay::kOn);
spike1->Set(Relay::kForward);
}
else if(m_controller->GetRawAxis(3) < 0)///feed motor reverse
{
spike1->Set(Relay::kOn);
spike1->Set(Relay::kReverse);
}
else ///feed motor off
{
spike1->Set(Relay::kOff);
}*/
//dash->PutInt("Something", m_telePeriodicLoops);
//dash->PutInt("Camera working?", m_camera->GetImage(image1));
d_st->Printf(DriverStationLCD::kUser_Line1,1,"Juxtaposition = %3.2f ", (double) m_telePeriodicLoops);
d_st->Printf(DriverStationLCD::kUser_Line2,1,"Encoder = %f ",jaguar6->GetSpeed());
d_st->Printf(DriverStationLCD::kUser_Line3,1,"Shooter speed = %d ",SSpeed);
d_st->Printf(DriverStationLCD::kUser_Line4,1,"Auton wait time = %d ",auton_waitTime);
d_st->Printf(DriverStationLCD::kUser_Line5,1,"Autonomous mode = %d ",auton_mode);
d_st->Printf(DriverStationLCD::kUser_Line6,1,"Encoder = %f ",jaguar1->GetPosition() - encoder_zero);
//d_st->Printf(DriverStationLCD::kUser_Line3,1,"Shooter Speed = %i", SSpeed);
//d_st->Printf(DriverStationLCD::kUser_Line2,1,"BButton = %d ", m_controller->GetRawButton(2));
//d_st->Printf(DriverStationLCD::kUser_Line2,1,"button5 = %f ", m_controller->GetRawAxis(5));
d_st->UpdateLCD();
Wait(0.05);
//m_dds->sendIOPortData();
/*
} // if (m_ds->GetPacketNumber()...
*/
} // TeleopPeriodic(void)
/********************************** Continuous Routines *************************************/
/*
* These routines are not used in this demonstration robot
*
*
void DisabledContinuous(void) {
}
void AutonomousContinuous(void) {
}
void TeleopContinuous(void) {
}
*/
/********************************** Miscellaneous Routines *************************************/
/**
* Clear KITT-style LED display on the solenoids
*
* Clear the solenoid LEDs used for a KITT-style LED display.
*/
void ClearSolenoidLEDsKITT() {
}
/**
+ * Demonstrate handling of joystick buttons
*
* This method expects to be called during each periodic loop, providing the following
* capabilities:
* - Print out a message when a button is initially pressed
* - Solenoid LEDs light up according to joystick buttons:
* - When no buttons pressed, clear the solenoid LEDs
* - When only one button is pressed, show the button number (in binary) via the solenoid LEDs
* - When more than one button is pressed, show "15" (in binary) via the solenoid LEDs
*/
void DemonstrateJoystickButtons(Joystick *currStick,
bool *buttonPreviouslyPressed,
const char *stickString,
Solenoid *solenoids[]) {
UINT8 buttonNum = 1; // start counting buttons at button 1
bool outputGenerated = false; // flag for whether or not output is generated for a button
INT8 numOfButtonPressed = 0; // 0 if no buttons pressed, -1 if00 multiple buttons pressed
/* Iterate over all the buttons on the joystick, checking to see if each is pressed
* If a button is pressed, check to see if it is newly pressed; if so, print out a
* message on the console
*/
for (buttonNum = 1; buttonNum <= NUM_JOYSTICK_BUTTONS; buttonNum++) {
if (currStick->GetRawButton(buttonNum)) {
// the current button is pressed, now act accordingly...
if (!buttonPreviouslyPressed[buttonNum]) {
// button newly pressed; print out a message
if (!outputGenerated) {
// print out a heading if no other button pressed this cycle
outputGenerated = true;
printf("%s button pressed:", stickString);
}
printf(" %d", buttonNum);
}
// remember that this button is pressed for the next iteration
buttonPreviouslyPressed[buttonNum] = true;
// set numOfButtonPressed appropriately
if (numOfButtonPressed == 0) {
// no button pressed yet this time through, set the number correctly
numOfButtonPressed = buttonNum;
} else {
// another button (or buttons) must have already been pressed, set appropriately
numOfButtonPressed = -1;
}
} else {
buttonPreviouslyPressed[buttonNum] = false;
}
}
// after iterating through all the buttons, add a newline to output if needed
if (outputGenerated) {
printf("\n");
}
if (numOfButtonPressed == -1) {
// multiple buttons were pressed, display as if button 15 was pressed
DisplayBinaryNumberOnSolenoidLEDs(15, solenoids);
} else {
// display the number of the button pressed on the solenoids;
// note that if no button was pressed (0), the solenoid display will be cleared (set to 0)
DisplayBinaryNumberOnSolenoidLEDs(numOfButtonPressed, solenoids);
}
}
/**
* Display a given four-bit value in binary on the given solenoid LEDs
*/
void DisplayBinaryNumberOnSolenoidLEDs(UINT8 displayNumber, Solenoid *solenoids[]) {
if (displayNumber > 15) {
// if the number to display is larger than can be displayed in 4 LEDs, display 0 instead
displayNumber = 0;
}
solenoids[3]->Set( (displayNumber & 1) != 0);
solenoids[2]->Set( (displayNumber & 2) != 0);
solenoids[1]->Set( (displayNumber & 4) != 0);
solenoids[0]->Set( (displayNumber & 8) != 0);
}
////code to the robot (we added this)
/*void DriveRobot(CANJaguar *jaguar1, CANJaguar *jaguar2, CANJaguar *jaguar3, CANJaguar *jaguar4, double setValue1, double setValue2)
{
if(setValue1 > 1 )setValue1 = 1;
if(setValue1 < -1 )setValue1 = -1;
if(setValue2 > 1 )setValue2 = 1;
if(setValue2 < -1 )setValue2 = -1;
setValue1 *= fabs(setValue1);
setValue2 *= fabs(setValue2);
jaguar1->Set(setValue1*12);
jaguar2->Set(setValue1*12);
jaguar3->Set(setValue2*12);
jaguar4->Set(setValue2*12);
}
*/
//distance is in feet, jags 1 and 3 are masters
/*void DriveRobot(CANJaguar *jaguar1, CANJaguar *jaguar2, CANJaguar *jaguar3, CANJaguar *jaguar4, double distance)
{
double distanceDriven = 0.0;
while(distanceDriven < distance)
{
// Set motor,"PID"
jaguar1->Set(6);
jaguar2->Set(jaguar1->GetOutputVoltage());
jaguar3->Set(6);
jaguar4->Set(jaguar3->GetOutputVoltage());
}
}*/
/////bridge tipper acts as a toggle
/*void ToggleBridgeTipper()
{
static bool bridgeDown = false;
if(bridgeDown) //if bridge is down then bridge raised
{
m_solenoid1->Set(false);
m_solenoid2->Set(true);
bridgeDown = false;
}
else //if bridge is raised then bridge is lowered
{
m_solenoid1->Set(true);
m_solenoid2->Set(false);
bridgeDown = true;
}
}*/
////1 = forward,0 = off, -1 = reverse
void SetFeedMotor(int value)
{
switch(value)
{
case 1:
break;
case -1:
break;
}
}
void AutonomousMode1() //this should be very similar to the autonomous mode used at kettering
{
m_solenoid3->Set(true); // omniwheels
m_solenoid4->Set(false);//omniwheels
m_solenoid5->Set(true);//solenoidpi
m_solenoid6->Set(false);//solenoidpi
m_solenoid7->Set(true);//supershifters
m_solenoid8->Set(false);//supershifters
m_solenoid1->Set(false);//bridge tipper
m_solenoid2->Set(true);//bridge tipper
if(m_timer->Get()== 0 )
{
m_timer->Start();
}
if(m_timer->Get() > auton_waitTime)
{
jaguar6->Set(auton_speed);
jaguar5->Set(jaguar6->GetOutputVoltage()); //run shooter motor
spike1->Set(Relay::kOn); //run feed motor
spike1->Set(Relay::kForward);
jaguar7->Set(1); //run ball gatherer
}
else
{
jaguar5->Set(0); //turn off all the motors
jaguar6->Set(0);
spike1->Set(Relay::kOff);
jaguar7->Set(0);
}
}
void AutonomousMode2() //shoot, drive backwards, shoot
{
m_solenoid3->Set(true); // omniwheels
m_solenoid4->Set(false);//omniwheels
m_solenoid5->Set(false);//solenoid3
m_solenoid6->Set(true);//solenoid3
m_solenoid7->Set(true);//supershifters
m_solenoid8->Set(false);//supershifters
m_solenoid1->Set(false);//bridge tipper
m_solenoid2->Set(true);//bridge tipper
if(m_timer->Get()== 0 ) //starts timer
{
m_timer->Start();
}
else if(m_timer->Get() < auton_waitTime) //shoots from key
{
jaguar6->Set(auton_speed);
//jaguar6->Set(2300+75*(jaguar1->GetPosition() - encoder_zero)*(5.5/16.5));
jaguar5->Set(jaguar6->GetOutputVoltage()); //run shooter motor
spike1->Set(Relay::kOn); //run feed motor
spike1->Set(Relay::kForward);
jaguar7->Set(1); //run ball gatherer
}
else if(jaguar1->GetPosition() - encoder_zero > -16.3) //drive backward
{
jaguar5->Set(0); // sets shooter to off
jaguar6->Set(0);
spike1->Set(Relay::kOff); //sets feeder to off
jaguar7->Set(1); //starts ball gatherer
m_robotdrive->ArcadeDrive(1,0,false); //drives backwards
}
else //shoots from bridge
{
jaguar6->Set(3000); //starts shooter
jaguar5->Set(jaguar6->GetOutputVoltage());
spike1->Set(Relay::kOn); //starts feed
spike1->Set(Relay::kForward);
}
}
void AutonomousMode3() //shoot, drive backwards, shoot
{
m_solenoid3->Set(true); // omniwheels
m_solenoid4->Set(false);//omniwheels
m_solenoid5->Set(false);//solenoid3
m_solenoid6->Set(true);//solenoid3
m_solenoid7->Set(true);//supershifters
m_solenoid8->Set(false);//supershifters
m_solenoid1->Set(false);//bridge tipper
m_solenoid2->Set(true);//bridge tipper
if(m_timer->Get()== 0 ) //starts timer
{
m_timer->Start();
}
else if(m_timer->Get() < auton_waitTime) //shoots from key
{
jaguar6->Set(2600);
//jaguar6->Set(2300+75*(jaguar1->GetPosition() - encoder_zero)*(5.5/16.5));
jaguar5->Set(jaguar6->GetOutputVoltage()); //run shooter motor
spike1->Set(Relay::kOn); //run feed motor
spike1->Set(Relay::kForward);
jaguar7->Set(1); //run ball gatherer
}
else if(jaguar1->GetPosition() - encoder_zero > -16.3) //drive backward
{
jaguar5->Set(0); // sets shooter to off
jaguar6->Set(0);
spike1->Set(Relay::kOff); //sets feeder to off
jaguar7->Set(1); //starts ball gatherer
m_robotdrive->ArcadeDrive(1,0,false); //drives backwards
}
else //shoots from bridge
{
jaguar6->Set(auton_speed); //starts shooter
jaguar5->Set(jaguar6->GetOutputVoltage());
spike1->Set(Relay::kOn); //starts feed
spike1->Set(Relay::kForward);
}
}
};
//jaguar6->Set(2300+75*(jaguar1->GetPosition() - encoder_zero)*(5.5/16.5));
START_ROBOT_CLASS(BuiltinDefaultCode);
/*
if(m_timer->Get()== 0 )
{
m_timer->Start();
}
else if(m_timer->Get() < 4000)
{
jaguar5->Set(2300);
jaguar6->Set(2300);
if(m_timer->Get() > 500)
{
->Set(Relay::kOn);
->Set(Relay::kForward);
}
else
{
->Set(Relay::kOff);
}
}
jaguar5->Set(0);
jaguar6->Set(0);
->Set(Relay::kOff);
autonomousCase = 1;
m_timer->Stop();
m_timer->Reset();
break;
case 1:
//drop bridge tipper
m_solenoid1->Set(true);
m_solenoid2->Set(false);
autonomousCase = 2;
break;
case 2:
//drive backward
if (m_timer->Get() == 0 )
{
m_timer->Start();
}
else if(m_timer->Get() > 2000) ///number of milliseconds to drive backward exceeded
{
m_timer->Stop();
m_timer->Reset();
jaguar1->Set(0.0); //stop drive
jaguar2->Set(0.0);
jaguar3->Set(0.0);
jaguar4->Set(0.0);
autonomousCase = 3;
}
else
{
jaguar1->Set(-1.0);
jaguar2->Set(-1.0);
jaguar3->Set(-1.0);