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