1 package org
.usfirst
.frc
.team3501
.robot
;
3 import org
.usfirst
.frc
.team3501
.robot
.Constants
.Defense
;
4 import org
.usfirst
.frc
.team3501
.robot
.subsystems
.DefenseArm
;
5 import org
.usfirst
.frc
.team3501
.robot
.subsystems
.DriveTrain
;
6 import org
.usfirst
.frc
.team3501
.robot
.subsystems
.IntakeArm
;
7 import org
.usfirst
.frc
.team3501
.robot
.subsystems
.Scaler
;
8 import org
.usfirst
.frc
.team3501
.robot
.subsystems
.Shooter
;
10 import edu
.wpi
.first
.wpilibj
.I2C
;
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
;
16 public class Robot
extends IterativeRobot
{
18 public static DriveTrain driveTrain
;
19 public static Shooter shooter
;
21 public static Scaler scaler
;
23 public static IntakeArm intakeArm
;
24 public static DefenseArm defenseArm
;
26 // Sendable Choosers send a drop down menu to the Smart Dashboard.
27 SendableChooser positionChooser
;
28 SendableChooser positionOneDefense
, positionTwoDefense
, positionThreeDefense
,
29 positionFourDefense
, positionFiveDefense
;
32 private final static double NANOSECONDS_PER_SECOND
= 1000000000;
34 public GyroClass gyro
;
37 double degreesIncreased
;
43 public void robotInit() {
44 // driveTrain = new DriveTrain();
45 gyro
= new GyroClass(I2C
.Port
.kOnboard
, gyro
.ITG3200_ADDRESS_AD0_LOW
);
48 shooter
= new Shooter();
49 scaler
= new Scaler();
50 defenseArm
= new DefenseArm();
51 intakeArm
= new IntakeArm();
53 // Sendable Choosers allows the driver to select the position of the robot
54 // and the positions of the defenses from a drop-down menu on the Smart
56 // make the Sendable Choosers
57 initializeSendableChoosers();
58 addPositionChooserOptions();
59 addDefensesToAllDefenseSendableChooosers();
60 sendSendableChoosersToSmartDashboard();
64 private void initializeSendableChoosers() {
65 positionChooser
= new SendableChooser();
66 positionOneDefense
= new SendableChooser();
67 positionTwoDefense
= new SendableChooser();
68 positionThreeDefense
= new SendableChooser();
69 positionFourDefense
= new SendableChooser();
70 positionFiveDefense
= new SendableChooser();
73 private void addPositionChooserOptions() {
74 positionChooser
.addDefault("Position 1", 1);
75 positionChooser
.addObject("Position 2", 2);
76 positionChooser
.addObject("Position 3", 3);
77 positionChooser
.addObject("Position 4", 4);
78 positionChooser
.addObject("Position 5", 5);
81 private void addDefensesToAllDefenseSendableChooosers() {
82 addDefenseOptions(positionOneDefense
);
83 addDefenseOptions(positionTwoDefense
);
84 addDefenseOptions(positionThreeDefense
);
85 addDefenseOptions(positionFourDefense
);
86 addDefenseOptions(positionFiveDefense
);
89 private void addDefenseOptions(SendableChooser chooser
) {
90 chooser
.addDefault("Portcullis", Defense
.PORTCULLIS
);
91 chooser
.addObject("Sally Port", Defense
.SALLY_PORT
);
92 chooser
.addObject("Rough Terrain", Defense
.ROUGH_TERRAIN
);
93 chooser
.addObject("Low Bar", Defense
.LOW_BAR
);
94 chooser
.addObject("Cheval De Frise", Defense
.CHEVAL_DE_FRISE
);
95 chooser
.addObject("Drawbridge", Defense
.DRAWBRIDGE
);
96 chooser
.addObject("Moat", Defense
.MOAT
);
97 chooser
.addObject("Rock Wall", Defense
.ROCK_WALL
);
100 private void sendSendableChoosersToSmartDashboard() {
101 SmartDashboard
.putData("PositionChooser", positionChooser
);
102 SmartDashboard
.putData("Position One Defense Chooser", positionOneDefense
);
103 SmartDashboard
.putData("Position Two Defense Chooser", positionTwoDefense
);
104 SmartDashboard
.putData("Position Three Defense Chooser",
105 positionThreeDefense
);
106 SmartDashboard
.putData("Position Four Defense Chooser",
107 positionFourDefense
);
108 SmartDashboard
.putData("Position Five Defense Chooser",
109 positionFiveDefense
);
110 SmartDashboard
.putData("Position Four Defense Chooser",
111 positionFourDefense
);
112 SmartDashboard
.putData("Position Five Defense Chooser",
113 positionFiveDefense
);
115 shooter
= new Shooter();
119 public void autonomousInit() {
120 Scheduler
.getInstance().run();
122 // get options chosen from drop down menu
123 Integer chosenPosition
= (Integer
) positionChooser
.getSelected();
124 Integer chosenDefense
= 0;
126 switch (chosenPosition
) {
128 chosenDefense
= (Integer
) positionOneDefense
.getSelected();
130 chosenDefense
= (Integer
) positionTwoDefense
.getSelected();
132 chosenDefense
= (Integer
) positionThreeDefense
.getSelected();
134 chosenDefense
= (Integer
) positionFourDefense
.getSelected();
136 chosenDefense
= (Integer
) positionFiveDefense
.getSelected();
139 System
.out
.println("Chosen Position: " + chosenPosition
);
140 System
.out
.println("Chosen Defense: " + chosenDefense
);
144 public void autonomousPeriodic() {
145 Scheduler
.getInstance().run();
149 public void teleopInit() {
153 public void teleopPeriodic() {
154 Scheduler
.getInstance().run();
157 public double getZAxisDegreesPerSeconds() {
158 double rawValue
= gyro
.getRotationZ() / 14.375;
162 public void initializeGyro() {
164 then
= System
.nanoTime() / 1000000000.0;
167 System
.out
.println("Testing Gyro Init");
170 public void addZAxisDegrees() {
171 double degreesRead
= getZAxisDegreesPerSeconds();
172 now
= System
.nanoTime();
173 now
= now
/ (1000000000.0);
174 double differenceInTime
= now
- then
;
176 degreesIncreased
= differenceInTime
* degreesRead
;
179 // + 1.0 is the formula constant
181 degrees
+= degreesIncreased
;
185 public double getDegrees() {