delete comments to make code readable and change message to 'go' to match Arduino
[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;
e4fbab02 4import org.usfirst.frc.team3501.robot.commands.shooter.ResetCatapult;
2947642e 5import org.usfirst.frc.team3501.robot.subsystems.DefenseArm;
047383c3 6import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
e47f0862 7import org.usfirst.frc.team3501.robot.subsystems.IntakeArm;
02cb494e 8import org.usfirst.frc.team3501.robot.subsystems.Scaler;
40348cab
E
9import org.usfirst.frc.team3501.robot.subsystems.Shooter;
10
bb571221
LM
11import edu.wpi.first.wpilibj.I2C;
12import edu.wpi.first.wpilibj.I2C.Port;
38a404b3
KZ
13import edu.wpi.first.wpilibj.IterativeRobot;
14import edu.wpi.first.wpilibj.command.Scheduler;
3366a59a
ME
15import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
16import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
38a404b3
KZ
17
18public class Robot extends IterativeRobot {
19 public static OI oi;
20 public static DriveTrain driveTrain;
40348cab 21 public static Shooter shooter;
2c9f5abb 22
02cb494e 23 public static Scaler scaler;
c97fbce2 24
a96fa926 25 public static IntakeArm intakeArm;
200caf63 26 public static DefenseArm defenseArm;
38a404b3 27
bb571221 28 static I2C Wire = new I2C(Port.kOnboard, 42);
bb571221 29
88e66b4e 30 // Sendable Choosers send a drop down menu to the Smart Dashboard.
3366a59a 31 SendableChooser positionChooser;
6947c8a4 32 SendableChooser positionOneDefense, positionTwoDefense, positionThreeDefense,
53f43a72 33 positionFourDefense, positionFiveDefense;
3366a59a 34
38a404b3
KZ
35 @Override
36 public void robotInit() {
9742fe2e
KZ
37 driveTrain = new DriveTrain();
38 oi = new OI();
2ac0cc17 39
40348cab 40 shooter = new Shooter();
02cb494e 41 scaler = new Scaler();
a96fa926 42 intakeArm = new IntakeArm();
3366a59a 43
9742fe2e
KZ
44 initializeSendableChoosers();
45 addPositionChooserOptions();
46 addDefensesToAllDefenseSendableChoosers();
47 sendSendableChoosersToSmartDashboard();
48
3366a59a
ME
49 }
50
6947c8a4
ME
51 private void initializeSendableChoosers() {
52 positionChooser = new SendableChooser();
53 positionOneDefense = new SendableChooser();
54 positionTwoDefense = new SendableChooser();
55 positionThreeDefense = new SendableChooser();
56 positionFourDefense = new SendableChooser();
57 positionFiveDefense = new SendableChooser();
58 }
59
29d59f48
ME
60 private void addPositionChooserOptions() {
61 positionChooser.addDefault("Position 1", 1);
62 positionChooser.addObject("Position 2", 2);
63 positionChooser.addObject("Position 3", 3);
64 positionChooser.addObject("Position 4", 4);
65 positionChooser.addObject("Position 5", 5);
66 }
67
9742fe2e 68 private void addDefensesToAllDefenseSendableChoosers() {
29d59f48
ME
69 addDefenseOptions(positionOneDefense);
70 addDefenseOptions(positionTwoDefense);
71 addDefenseOptions(positionThreeDefense);
72 addDefenseOptions(positionFourDefense);
73 addDefenseOptions(positionFiveDefense);
74 }
75
76 private void addDefenseOptions(SendableChooser chooser) {
3366a59a
ME
77 chooser.addDefault("Portcullis", Defense.PORTCULLIS);
78 chooser.addObject("Sally Port", Defense.SALLY_PORT);
79 chooser.addObject("Rough Terrain", Defense.ROUGH_TERRAIN);
80 chooser.addObject("Low Bar", Defense.LOW_BAR);
81 chooser.addObject("Cheval De Frise", Defense.CHEVAL_DE_FRISE);
82 chooser.addObject("Drawbridge", Defense.DRAWBRIDGE);
83 chooser.addObject("Moat", Defense.MOAT);
84 chooser.addObject("Rock Wall", Defense.ROCK_WALL);
38a404b3
KZ
85 }
86
29d59f48
ME
87 private void sendSendableChoosersToSmartDashboard() {
88 SmartDashboard.putData("PositionChooser", positionChooser);
89 SmartDashboard.putData("Position One Defense Chooser", positionOneDefense);
90 SmartDashboard.putData("Position Two Defense Chooser", positionTwoDefense);
91 SmartDashboard.putData("Position Three Defense Chooser",
92 positionThreeDefense);
bb571221
LM
93 SmartDashboard.putData("Position Four Defense Chooser",
94 positionFourDefense);
95 SmartDashboard.putData("Position Five Defense Chooser",
96 positionFiveDefense);
d06ee698 97
bb571221
LM
98 SmartDashboard.putData("Position Four Defense Chooser",
99 positionFourDefense);
100 SmartDashboard.putData("Position Five Defense Chooser",
101 positionFiveDefense);
e23bfd98
E
102
103 shooter = new Shooter();
d06ee698 104
29d59f48
ME
105 }
106
38a404b3
KZ
107 @Override
108 public void autonomousInit() {
3366a59a
ME
109 Scheduler.getInstance().run();
110
111 // get options chosen from drop down menu
112 Integer chosenPosition = (Integer) positionChooser.getSelected();
e13d2293 113 Integer chosenDefense = 0;
3366a59a 114
ee177a4a 115 if (chosenPosition == 1)
3366a59a 116 chosenDefense = (Integer) positionOneDefense.getSelected();
ee177a4a 117 else if (chosenPosition == 2)
3366a59a 118 chosenDefense = (Integer) positionTwoDefense.getSelected();
ee177a4a 119 else if (chosenPosition == 3)
3366a59a 120 chosenDefense = (Integer) positionThreeDefense.getSelected();
ee177a4a 121 else if (chosenPosition == 4)
3366a59a 122 chosenDefense = (Integer) positionFourDefense.getSelected();
ee177a4a 123 else if (chosenPosition == 5)
3366a59a
ME
124 chosenDefense = (Integer) positionFiveDefense.getSelected();
125
126 System.out.println("Chosen Position: " + chosenPosition);
127 System.out.println("Chosen Defense: " + chosenDefense);
38a404b3
KZ
128 }
129
130 @Override
131 public void autonomousPeriodic() {
132 Scheduler.getInstance().run();
38a404b3
KZ
133 }
134
135 @Override
136 public void teleopInit() {
e4fbab02
HD
137 Scheduler.getInstance().add(new ResetCatapult()); // Reset catapult at start
138 // of each match.
38a404b3
KZ
139 }
140
141 @Override
142 public void teleopPeriodic() {
143 Scheduler.getInstance().run();
e458b515
LM
144 String WriteString = "go";
145 char[] CharArray = WriteString.toCharArray();
146 byte[] WriteData = new byte[CharArray.length];
147 for (int i = 0; i < CharArray.length; i++) {
148 WriteData[i] = (byte) CharArray[i];
bb571221 149 }
e458b515 150 Wire.transaction(WriteData, WriteData.length, null, 0);
1e039ebd
E
151 }
152
38a404b3 153}