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