make a method for initializing all the Sendable Choosers
[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 initializeSendableChoosers();
29
30 // add options for positions to the positionChooser
31 positionChooser.addDefault("Position 1", 1);
32 positionChooser.addObject("Position 2", 2);
33 positionChooser.addObject("Position 3", 3);
34 positionChooser.addObject("Position 4", 4);
35 positionChooser.addObject("Position 5", 5);
36
37 // add options for defenses into each defense chooser (5)
38 addDefense(positionOneDefense);
39 addDefense(positionTwoDefense);
40 addDefense(positionThreeDefense);
41 addDefense(positionFourDefense);
42 addDefense(positionFiveDefense);
43
44 // send the Sendable Choosers to the Smart Dashboard
45 // Sendable Choosers allows the driver to select the position of the robot
46 // and the positions of the defenses from a drop-down menu on the Smart
47 // Dashboard
48 SmartDashboard.putData("PositionChooser", positionChooser);
49 SmartDashboard.putData("Position One Defense Chooser", positionOneDefense);
50 SmartDashboard.putData("Position Two Defense Chooser", positionTwoDefense);
51 SmartDashboard.putData("Position Three Defense Chooser",
52 positionThreeDefense);
53 SmartDashboard.putData("Position Four Defense Chooser",
54 positionFourDefense);
55 SmartDashboard.putData("Position Five Defense Chooser",
56 positionFiveDefense);
57 }
58
59 // initialize all the Sendable Choosers
60 private void initializeSendableChoosers() {
61 positionChooser = new SendableChooser();
62 positionOneDefense = new SendableChooser();
63 positionTwoDefense = new SendableChooser();
64 positionThreeDefense = new SendableChooser();
65 positionFourDefense = new SendableChooser();
66 positionFiveDefense = new SendableChooser();
67 }
68
69 private void addDefense(SendableChooser chooser) {
70 chooser.addDefault("Portcullis", Defense.PORTCULLIS);
71 chooser.addObject("Sally Port", Defense.SALLY_PORT);
72 chooser.addObject("Rough Terrain", Defense.ROUGH_TERRAIN);
73 chooser.addObject("Low Bar", Defense.LOW_BAR);
74 chooser.addObject("Cheval De Frise", Defense.CHEVAL_DE_FRISE);
75 chooser.addObject("Drawbridge", Defense.DRAWBRIDGE);
76 chooser.addObject("Moat", Defense.MOAT);
77 chooser.addObject("Rock Wall", Defense.ROCK_WALL);
78 }
79
80 @Override
81 public void autonomousInit() {
82 Scheduler.getInstance().run();
83
84 // get options chosen from drop down menu
85 Integer chosenPosition = (Integer) positionChooser.getSelected();
86 Integer chosenDefense = 0;
87
88 switch (chosenPosition) {
89 case 1:
90 chosenDefense = (Integer) positionOneDefense.getSelected();
91 case 2:
92 chosenDefense = (Integer) positionTwoDefense.getSelected();
93 case 3:
94 chosenDefense = (Integer) positionThreeDefense.getSelected();
95 case 4:
96 chosenDefense = (Integer) positionFourDefense.getSelected();
97 case 5:
98 chosenDefense = (Integer) positionFiveDefense.getSelected();
99 }
100
101 System.out.println("Chosen Position: " + chosenPosition);
102 System.out.println("Chosen Defense: " + chosenDefense);
103 }
104
105 @Override
106 public void autonomousPeriodic() {
107 Scheduler.getInstance().run();
108 }
109
110 @Override
111 public void teleopInit() {
112 }
113
114 @Override
115 public void teleopPeriodic() {
116 Scheduler.getInstance().run();
117
118 }
119 }