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