make methods for various SendableChooser tasks to make robotInit() cleaner
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / Robot.java
CommitLineData
38a404b3
KZ
1package org.usfirst.frc.team3501.robot;
2
53d61b3e 3import org.usfirst.frc.team3501.robot.Constants.Defense;
91aac7a6 4import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
40348cab
E
5import org.usfirst.frc.team3501.robot.subsystems.Shooter;
6
38a404b3
KZ
7import edu.wpi.first.wpilibj.IterativeRobot;
8import edu.wpi.first.wpilibj.command.Scheduler;
3366a59a
ME
9import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
10import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
38a404b3
KZ
11
12public class Robot extends IterativeRobot {
13 public static OI oi;
14 public static DriveTrain driveTrain;
40348cab 15 public static Shooter shooter;
38a404b3 16
88e66b4e 17 // Sendable Choosers send a drop down menu to the Smart Dashboard.
3366a59a 18 SendableChooser positionChooser;
6947c8a4
ME
19 SendableChooser positionOneDefense, positionTwoDefense, positionThreeDefense,
20 positionFourDefense, positionFiveDefense;
3366a59a 21
38a404b3
KZ
22 @Override
23 public void robotInit() {
24 driveTrain = new DriveTrain();
25 oi = new OI();
40348cab 26 shooter = new Shooter();
3366a59a 27
88e66b4e
ME
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
29d59f48
ME
31 // make the Sendable Choosers
32 initializeSendableChoosers();
33 addPositionChooserOptions();
34 addDefensesToAllDefenseSendableChooosers();
35 sendSendableChoosersToSmartDashboard();
36
3366a59a
ME
37 }
38
6947c8a4
ME
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
29d59f48
ME
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) {
3366a59a
ME
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);
38a404b3
KZ
73 }
74
29d59f48
ME
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
38a404b3
KZ
87 @Override
88 public void autonomousInit() {
3366a59a
ME
89 Scheduler.getInstance().run();
90
91 // get options chosen from drop down menu
92 Integer chosenPosition = (Integer) positionChooser.getSelected();
e13d2293 93 Integer chosenDefense = 0;
3366a59a 94
33981335
ME
95 switch (chosenPosition) {
96 case 1:
3366a59a 97 chosenDefense = (Integer) positionOneDefense.getSelected();
33981335 98 case 2:
3366a59a 99 chosenDefense = (Integer) positionTwoDefense.getSelected();
33981335 100 case 3:
3366a59a 101 chosenDefense = (Integer) positionThreeDefense.getSelected();
33981335 102 case 4:
3366a59a 103 chosenDefense = (Integer) positionFourDefense.getSelected();
33981335 104 case 5:
3366a59a 105 chosenDefense = (Integer) positionFiveDefense.getSelected();
33981335 106 }
3366a59a
ME
107
108 System.out.println("Chosen Position: " + chosenPosition);
109 System.out.println("Chosen Defense: " + chosenDefense);
38a404b3
KZ
110 }
111
112 @Override
113 public void autonomousPeriodic() {
114 Scheduler.getInstance().run();
38a404b3
KZ
115 }
116
117 @Override
118 public void teleopInit() {
119 }
120
121 @Override
122 public void teleopPeriodic() {
123 Scheduler.getInstance().run();
124
125 }
126}