6bf02a4cd1017acc57873e7070deced1c454e017
[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" + " Will probably work...", Defense.LOW_BAR);
73 chooser.addObject("Chival De Frise", Defense.CHIVAL_DE_FRISE);
74 chooser.addObject("Drawbridge", Defense.DRAWBRIDGE);
75 chooser.addObject("Moat" + Auton.MOAT_SPEED + " " + Auton.MOAT_TIME,
76 Defense.MOAT);
77 chooser.addObject("Rock Wall" + Auton.ROCK_WALL_SPEED + " "
78 + Auton.ROCK_WALL_TIME, Defense.ROCK_WALL);
79 }
80
81 private void sendSendableChoosersToSmartDashboard() {
82 SmartDashboard.putData("PositionChooser", positionChooser);
83 SmartDashboard.putData("Position 1 Defense Chooser", positionOneDefense);
84 SmartDashboard.putData("Position 2 Defense Chooser", positionTwoDefense);
85 SmartDashboard.putData("Position 3 Defense Chooser", positionThreeDefense);
86 SmartDashboard.putData("Position 4 Defense Chooser", positionFourDefense);
87 SmartDashboard.putData("Position 5 Defense Chooser", positionFiveDefense);
88
89 }
90
91 @Override
92 public void autonomousInit() {
93 // get options chosen from drop down menu
94 Integer chosenPosition = (Integer) positionChooser.getSelected();
95 Defense chosenDefense = null;
96
97 if (chosenPosition == 1)
98 chosenDefense = (Defense) positionOneDefense.getSelected();
99 else if (chosenPosition == 2)
100 chosenDefense = (Defense) positionTwoDefense.getSelected();
101 else if (chosenPosition == 3)
102 chosenDefense = (Defense) positionThreeDefense.getSelected();
103 else if (chosenPosition == 4)
104 chosenDefense = (Defense) positionFourDefense.getSelected();
105 else if (chosenPosition == 5)
106 chosenDefense = (Defense) positionFiveDefense.getSelected();
107
108 if (chosenPosition != 0)
109 Scheduler.getInstance().add(
110 new ChooseStrategy(chosenPosition, chosenDefense));
111
112 // Scheduler.getInstance().add(new TimeDrive(.6, 4));
113 }
114
115 @Override
116 public void autonomousPeriodic() {
117 Scheduler.getInstance().run();
118 }
119
120 @Override
121 public void teleopInit() {
122 Scheduler.getInstance().add(new SetLowGear());
123 }
124
125 @Override
126 public void teleopPeriodic() {
127 Scheduler.getInstance().run();
128 }
129
130 }