| 1 | package org.usfirst.frc.team3501.robot; |
| 2 | |
| 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; |
| 9 | |
| 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; |
| 15 | |
| 16 | public class Robot extends IterativeRobot { |
| 17 | public static OI oi; |
| 18 | public static DriveTrain driveTrain; |
| 19 | public static Shooter shooter; |
| 20 | |
| 21 | public static Scaler scaler; |
| 22 | |
| 23 | public static IntakeArm intakeArm; |
| 24 | public static DefenseArm defenseArm; |
| 25 | |
| 26 | // Sendable Choosers send a drop down menu to the Smart Dashboard. |
| 27 | SendableChooser positionChooser; |
| 28 | SendableChooser positionOneDefense, positionTwoDefense, positionThreeDefense, |
| 29 | positionFourDefense, positionFiveDefense; |
| 30 | |
| 31 | // Gyro stuff |
| 32 | private final static double NANOSECONDS_PER_SECOND = 1000000000; |
| 33 | short rawValue; |
| 34 | public FirebotGyro gyro; |
| 35 | |
| 36 | double initialSpeedNanoseconds; |
| 37 | double finalSpeedNanoseconds; |
| 38 | double initialSpeedSeconds; |
| 39 | double finalSpeedSeconds; |
| 40 | double deltaSpeed; |
| 41 | double degrees; |
| 42 | |
| 43 | @Override |
| 44 | public void robotInit() { |
| 45 | // driveTrain = new DriveTrain(); |
| 46 | gyro = new FirebotGyro(I2C.Port.kOnboard, (byte) 0x68); |
| 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 | SmartDashboard.putData("Position Four Defense Chooser", |
| 112 | positionFourDefense); |
| 113 | SmartDashboard.putData("Position Five Defense Chooser", |
| 114 | positionFiveDefense); |
| 115 | |
| 116 | shooter = new Shooter(); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public void autonomousInit() { |
| 121 | Scheduler.getInstance().run(); |
| 122 | |
| 123 | // get options chosen from drop down menu |
| 124 | Integer chosenPosition = (Integer) positionChooser.getSelected(); |
| 125 | Integer chosenDefense = 0; |
| 126 | |
| 127 | switch (chosenPosition) { |
| 128 | case 1: |
| 129 | chosenDefense = (Integer) positionOneDefense.getSelected(); |
| 130 | case 2: |
| 131 | chosenDefense = (Integer) positionTwoDefense.getSelected(); |
| 132 | case 3: |
| 133 | chosenDefense = (Integer) positionThreeDefense.getSelected(); |
| 134 | case 4: |
| 135 | chosenDefense = (Integer) positionFourDefense.getSelected(); |
| 136 | case 5: |
| 137 | chosenDefense = (Integer) positionFiveDefense.getSelected(); |
| 138 | } |
| 139 | |
| 140 | System.out.println("Chosen Position: " + chosenPosition); |
| 141 | System.out.println("Chosen Defense: " + chosenDefense); |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public void autonomousPeriodic() { |
| 146 | Scheduler.getInstance().run(); |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public void teleopInit() { |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public void teleopPeriodic() { |
| 155 | Scheduler.getInstance().run(); |
| 156 | } |
| 157 | } |