bb06782c47770182203ece05cf56f676cf9e3e9d
[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 1 Defense Chooser", positionOneDefense);
79 SmartDashboard.putData("Position 2 Defense Chooser", positionTwoDefense);
80 SmartDashboard.putData("Position 3 Defense Chooser", positionThreeDefense);
81 SmartDashboard.putData("Position 4 Defense Chooser", positionFourDefense);
82 SmartDashboard.putData("Position 5 Defense Chooser", positionFiveDefense);
83
84 }
85
86 @Override
87 public void autonomousInit() {
88 // get options chosen from drop down menu
89 Integer chosenPosition = (Integer) positionChooser.getSelected();
90 Defense chosenDefense = null;
91
92 if (chosenPosition == 1)
93 chosenDefense = (Defense) positionOneDefense.getSelected();
94 else if (chosenPosition == 2)
95 chosenDefense = (Defense) positionTwoDefense.getSelected();
96 else if (chosenPosition == 3)
97 chosenDefense = (Defense) positionThreeDefense.getSelected();
98 else if (chosenPosition == 4)
99 chosenDefense = (Defense) positionFourDefense.getSelected();
100 else if (chosenPosition == 5)
101 chosenDefense = (Defense) positionFiveDefense.getSelected();
102
103 Scheduler.getInstance().add(
104 new ChooseStrategy(chosenPosition, chosenDefense));
105 }
106
107 @Override
108 public void autonomousPeriodic() {
109 Scheduler.getInstance().run();
110 }
111
112 @Override
113 public void teleopInit() {
114 Scheduler.getInstance().add(new SetHighGear());
115 }
116
117 @Override
118 public void teleopPeriodic() {
119 Scheduler.getInstance().run();
120 }
121
122 }