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