be19f16163ac021691fe7124b934a3142db7da0c
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / Robot.java
1 package org.usfirst.frc.team3501.robot;
2
3 import org.usfirst.frc.team3501.robot.Constants.Defense;
4 import org.usfirst.frc.team3501.robot.commands.auton.ChooseStrategy;
5 import org.usfirst.frc.team3501.robot.commands.driving.SetHighGear;
6 import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
7 import org.usfirst.frc.team3501.robot.subsystems.IntakeArm;
8 import org.usfirst.frc.team3501.robot.subsystems.Shooter;
9
10 import edu.wpi.first.wpilibj.IterativeRobot;
11 import edu.wpi.first.wpilibj.command.Scheduler;
12 import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
13 import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
14
15 public class Robot extends IterativeRobot {
16 public static OI oi;
17 public static DriveTrain driveTrain;
18 public static Shooter shooter;
19 public static IntakeArm intakeArm;
20
21 // Sendable Choosers send a drop down menu to the Smart Dashboard.
22 SendableChooser positionChooser;
23 SendableChooser positionOneDefense, positionTwoDefense, positionThreeDefense,
24 positionFourDefense, positionFiveDefense;
25
26 @Override
27 public void robotInit() {
28 driveTrain = new DriveTrain();
29 shooter = new Shooter();
30 intakeArm = new IntakeArm();
31
32 oi = new OI();
33
34 initializeSendableChoosers();
35 addPositionChooserOptions();
36 addDefensesToAllDefenseSendableChoosers();
37 sendSendableChoosersToSmartDashboard();
38 }
39
40 private void initializeSendableChoosers() {
41 positionChooser = new SendableChooser();
42 positionOneDefense = new SendableChooser();
43 positionTwoDefense = new SendableChooser();
44 positionThreeDefense = new SendableChooser();
45 positionFourDefense = new SendableChooser();
46 positionFiveDefense = new SendableChooser();
47 }
48
49 private void addPositionChooserOptions() {
50 positionChooser.addDefault("Position 1", 1);
51 positionChooser.addObject("Position 2", 2);
52 positionChooser.addObject("Position 3", 3);
53 positionChooser.addObject("Position 4", 4);
54 positionChooser.addObject("Position 5", 5);
55 }
56
57 private void addDefensesToAllDefenseSendableChoosers() {
58 addDefenseOptions(positionOneDefense);
59 addDefenseOptions(positionTwoDefense);
60 addDefenseOptions(positionThreeDefense);
61 addDefenseOptions(positionFourDefense);
62 addDefenseOptions(positionFiveDefense);
63 }
64
65 private void addDefenseOptions(SendableChooser chooser) {
66 chooser.addDefault("Portcullis", Defense.PORTCULLIS);
67 chooser.addObject("Sally Port", Defense.SALLY_PORT);
68 chooser.addObject("Rough Terrain", Defense.ROUGH_TERRAIN);
69 chooser.addObject("Low Bar", Defense.LOW_BAR);
70 chooser.addObject("Chival De Frise", Defense.CHIVAL_DE_FRISE);
71 chooser.addObject("Drawbridge", Defense.DRAWBRIDGE);
72 chooser.addObject("Moat", Defense.MOAT);
73 chooser.addObject("Rock Wall", Defense.ROCK_WALL);
74 }
75
76 private void sendSendableChoosersToSmartDashboard() {
77 SmartDashboard.putData("PositionChooser", positionChooser);
78 SmartDashboard.putData("Position One Defense Chooser", positionOneDefense);
79 SmartDashboard.putData("Position Two Defense Chooser", positionTwoDefense);
80 SmartDashboard.putData("Position Three Defense Chooser",
81 positionThreeDefense);
82 SmartDashboard
83 .putData("Position Four Defense Chooser", positionFourDefense);
84 SmartDashboard
85 .putData("Position Five Defense Chooser", positionFiveDefense);
86
87 SmartDashboard
88 .putData("Position Four Defense Chooser", positionFourDefense);
89 SmartDashboard
90 .putData("Position Five Defense Chooser", positionFiveDefense);
91
92 }
93
94 @Override
95 public void autonomousInit() {
96 // get options chosen from drop down menu
97 Integer chosenPosition = (Integer) positionChooser.getSelected();
98 Defense chosenDefense = null;
99
100 if (chosenPosition == 1)
101 chosenDefense = (Defense) positionOneDefense.getSelected();
102 else if (chosenPosition == 2)
103 chosenDefense = (Defense) positionTwoDefense.getSelected();
104 else if (chosenPosition == 3)
105 chosenDefense = (Defense) positionThreeDefense.getSelected();
106 else if (chosenPosition == 4)
107 chosenDefense = (Defense) positionFourDefense.getSelected();
108 else if (chosenPosition == 5)
109 chosenDefense = (Defense) positionFiveDefense.getSelected();
110
111 Scheduler.getInstance().add(
112 new ChooseStrategy(chosenPosition, chosenDefense));
113 }
114
115 @Override
116 public void autonomousPeriodic() {
117 Scheduler.getInstance().run();
118 }
119
120 @Override
121 public void teleopInit() {
122 Scheduler.getInstance().add(new SetHighGear());
123 }
124
125 @Override
126 public void teleopPeriodic() {
127 Scheduler.getInstance().run();
128 }
129
130 }