Use GyroClass and currently using method getDegrees in teleopPeriodic
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / Robot.java
CommitLineData
38a404b3
KZ
1package org.usfirst.frc.team3501.robot;
2
bd5a85e3 3import org.usfirst.frc.team3501.robot.AnotherGyroClass.Rotation;
53d61b3e 4import org.usfirst.frc.team3501.robot.Constants.Defense;
8a0a9571 5import org.usfirst.frc.team3501.robot.subsystems.DefenseArm;
047383c3 6import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
f81370d3 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
2680d6fc 11import edu.wpi.first.wpilibj.I2C;
38a404b3
KZ
12import edu.wpi.first.wpilibj.IterativeRobot;
13import edu.wpi.first.wpilibj.command.Scheduler;
3366a59a
ME
14import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
15import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
38a404b3
KZ
16
17public class Robot extends IterativeRobot {
18 public static OI oi;
19 public static DriveTrain driveTrain;
40348cab 20 public static Shooter shooter;
fbab1d06 21
02cb494e 22 public static Scaler scaler;
bd5a85e3 23 double then;
f81370d3 24 public static IntakeArm intakeArm;
bd5a85e3 25 public static DefenseArm defenseArm;
38a404b3 26
88e66b4e 27 // Sendable Choosers send a drop down menu to the Smart Dashboard.
3366a59a 28 SendableChooser positionChooser;
6947c8a4 29 SendableChooser positionOneDefense, positionTwoDefense, positionThreeDefense,
bd5a85e3 30 positionFourDefense, positionFiveDefense;
2680d6fc
E
31
32 // Gyro stuff
33 private final static double NANOSECONDS_PER_SECOND = 1000000000;
34 short rawValue;
9c83d56e 35 public GyroClass gyro;
2680d6fc 36
bd5a85e3 37 double now;
213e82b1 38 double degreesIncreased;
2680d6fc 39 double degrees;
3366a59a 40
bd5a85e3
E
41 Rotation rotation;
42
38a404b3
KZ
43 @Override
44 public void robotInit() {
2680d6fc 45 // driveTrain = new DriveTrain();
bd5a85e3 46 gyro = new GyroClass(I2C.Port.kOnboard, gyro.ITG3200_ADDRESS_AD0_LOW);
2680d6fc 47 // oi = new OI();
5d5bc4ed 48
40348cab 49 shooter = new Shooter();
02cb494e 50 scaler = new Scaler();
8a0a9571 51 defenseArm = new DefenseArm();
2680d6fc 52 intakeArm = new IntakeArm();
3366a59a 53
bd5a85e3
E
54 // Sendable Choosers allows the driver to select the position of the
55 // robot
88e66b4e
ME
56 // and the positions of the defenses from a drop-down menu on the Smart
57 // Dashboard
29d59f48 58 // make the Sendable Choosers
213e82b1
E
59 // initializeSendableChoosers();
60 // addPositionChooserOptions();
61 // addDefensesToAllDefenseSendableChooosers();
62 // sendSendableChoosersToSmartDashboard();
29d59f48 63
3366a59a
ME
64 }
65
6947c8a4
ME
66 private void initializeSendableChoosers() {
67 positionChooser = new SendableChooser();
68 positionOneDefense = new SendableChooser();
69 positionTwoDefense = new SendableChooser();
70 positionThreeDefense = new SendableChooser();
71 positionFourDefense = new SendableChooser();
72 positionFiveDefense = new SendableChooser();
73 }
74
29d59f48
ME
75 private void addPositionChooserOptions() {
76 positionChooser.addDefault("Position 1", 1);
77 positionChooser.addObject("Position 2", 2);
78 positionChooser.addObject("Position 3", 3);
79 positionChooser.addObject("Position 4", 4);
80 positionChooser.addObject("Position 5", 5);
81 }
82
83 private void addDefensesToAllDefenseSendableChooosers() {
84 addDefenseOptions(positionOneDefense);
85 addDefenseOptions(positionTwoDefense);
86 addDefenseOptions(positionThreeDefense);
87 addDefenseOptions(positionFourDefense);
88 addDefenseOptions(positionFiveDefense);
89 }
90
91 private void addDefenseOptions(SendableChooser chooser) {
3366a59a
ME
92 chooser.addDefault("Portcullis", Defense.PORTCULLIS);
93 chooser.addObject("Sally Port", Defense.SALLY_PORT);
94 chooser.addObject("Rough Terrain", Defense.ROUGH_TERRAIN);
95 chooser.addObject("Low Bar", Defense.LOW_BAR);
96 chooser.addObject("Cheval De Frise", Defense.CHEVAL_DE_FRISE);
97 chooser.addObject("Drawbridge", Defense.DRAWBRIDGE);
98 chooser.addObject("Moat", Defense.MOAT);
99 chooser.addObject("Rock Wall", Defense.ROCK_WALL);
38a404b3
KZ
100 }
101
29d59f48
ME
102 private void sendSendableChoosersToSmartDashboard() {
103 SmartDashboard.putData("PositionChooser", positionChooser);
104 SmartDashboard.putData("Position One Defense Chooser", positionOneDefense);
105 SmartDashboard.putData("Position Two Defense Chooser", positionTwoDefense);
106 SmartDashboard.putData("Position Three Defense Chooser",
107 positionThreeDefense);
108 SmartDashboard.putData("Position Four Defense Chooser",
109 positionFourDefense);
110 SmartDashboard.putData("Position Five Defense Chooser",
111 positionFiveDefense);
213e82b1 112
6740fa40
E
113 SmartDashboard.putData("Position Four Defense Chooser",
114 positionFourDefense);
115 SmartDashboard.putData("Position Five Defense Chooser",
116 positionFiveDefense);
117
118 shooter = new Shooter();
213e82b1 119
29d59f48
ME
120 }
121
38a404b3
KZ
122 @Override
123 public void autonomousInit() {
3366a59a
ME
124 Scheduler.getInstance().run();
125
126 // get options chosen from drop down menu
127 Integer chosenPosition = (Integer) positionChooser.getSelected();
e13d2293 128 Integer chosenDefense = 0;
3366a59a 129
33981335
ME
130 switch (chosenPosition) {
131 case 1:
3366a59a 132 chosenDefense = (Integer) positionOneDefense.getSelected();
33981335 133 case 2:
3366a59a 134 chosenDefense = (Integer) positionTwoDefense.getSelected();
33981335 135 case 3:
3366a59a 136 chosenDefense = (Integer) positionThreeDefense.getSelected();
33981335 137 case 4:
3366a59a 138 chosenDefense = (Integer) positionFourDefense.getSelected();
33981335 139 case 5:
3366a59a 140 chosenDefense = (Integer) positionFiveDefense.getSelected();
33981335 141 }
3366a59a
ME
142
143 System.out.println("Chosen Position: " + chosenPosition);
144 System.out.println("Chosen Defense: " + chosenDefense);
38a404b3
KZ
145 }
146
147 @Override
148 public void autonomousPeriodic() {
149 Scheduler.getInstance().run();
38a404b3
KZ
150 }
151
152 @Override
153 public void teleopInit() {
154 }
155
156 @Override
157 public void teleopPeriodic() {
158 Scheduler.getInstance().run();
bd5a85e3
E
159
160 }
161
162 public double getZAxisDegreesPerSeconds() {
163 double rawValue = gyro.getRotationZ() / 14.375;
164 return rawValue;
165 }
166
167 public void initializeGyro() {
168 degrees = 0;
169 then = System.nanoTime() / 1000000000.0;
170 gyro.reset();
171 gyro.initialize();
172 System.out.println("Testing Gyro Init");
173 }
174
175 public void addZAxisDegrees() {
176 double degreesRead = getZAxisDegreesPerSeconds();
177 now = System.nanoTime();
178 now = now / (1000000000.0);
179 double differenceInTime = now - then;
180 then = now;
181 degreesIncreased = differenceInTime * degreesRead;
182
183 // 0.0 = register
184 // + 1.0 is the formula constant
185 //
186 degrees += degreesIncreased;
187
188 }
189
190 public double getDegrees() {
191 return degrees;
38a404b3 192 }
213e82b1 193
38a404b3 194}