| 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 | public static IntakeArm intakeArm; |
| 25 | public static DefenseArm defenseArm; |
| 26 | |
| 27 | // Sendable Choosers send a drop down menu to the Smart Dashboard. |
| 28 | SendableChooser positionChooser; |
| 29 | SendableChooser positionOneDefense, positionTwoDefense, positionThreeDefense, |
| 30 | positionFourDefense, positionFiveDefense; |
| 31 | |
| 32 | // Gyro stuff |
| 33 | private final static double NANOSECONDS_PER_SECOND = 1000000000; |
| 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 | defenseArm = new DefenseArm(); |
| 52 | intakeArm = new IntakeArm(); |
| 53 | |
| 54 | // Sendable Choosers allows the driver to select the position of the |
| 55 | // robot |
| 56 | // and the positions of the defenses from a drop-down menu on the Smart |
| 57 | // Dashboard |
| 58 | // make the Sendable Choosers |
| 59 | // initializeSendableChoosers(); |
| 60 | // addPositionChooserOptions(); |
| 61 | // addDefensesToAllDefenseSendableChooosers(); |
| 62 | // sendSendableChoosersToSmartDashboard(); |
| 63 | |
| 64 | } |
| 65 | |
| 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 | |
| 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) { |
| 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); |
| 100 | } |
| 101 | |
| 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); |
| 112 | |
| 113 | SmartDashboard.putData("Position Four Defense Chooser", |
| 114 | positionFourDefense); |
| 115 | SmartDashboard.putData("Position Five Defense Chooser", |
| 116 | positionFiveDefense); |
| 117 | |
| 118 | shooter = new Shooter(); |
| 119 | |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public void autonomousInit() { |
| 124 | Scheduler.getInstance().run(); |
| 125 | |
| 126 | // get options chosen from drop down menu |
| 127 | Integer chosenPosition = (Integer) positionChooser.getSelected(); |
| 128 | Integer chosenDefense = 0; |
| 129 | |
| 130 | switch (chosenPosition) { |
| 131 | case 1: |
| 132 | chosenDefense = (Integer) positionOneDefense.getSelected(); |
| 133 | case 2: |
| 134 | chosenDefense = (Integer) positionTwoDefense.getSelected(); |
| 135 | case 3: |
| 136 | chosenDefense = (Integer) positionThreeDefense.getSelected(); |
| 137 | case 4: |
| 138 | chosenDefense = (Integer) positionFourDefense.getSelected(); |
| 139 | case 5: |
| 140 | chosenDefense = (Integer) positionFiveDefense.getSelected(); |
| 141 | } |
| 142 | |
| 143 | System.out.println("Chosen Position: " + chosenPosition); |
| 144 | System.out.println("Chosen Defense: " + chosenDefense); |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public void autonomousPeriodic() { |
| 149 | Scheduler.getInstance().run(); |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public void teleopInit() { |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public void teleopPeriodic() { |
| 158 | Scheduler.getInstance().run(); |
| 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; |
| 192 | } |
| 193 | |
| 194 | } |