|
| 1 | + |
| 2 | +package org.usfirst.frc.team199.robot; |
| 3 | + |
| 4 | +import edu.wpi.first.wpilibj.IterativeRobot; |
| 5 | +import edu.wpi.first.wpilibj.command.Command; |
| 6 | +import edu.wpi.first.wpilibj.command.Scheduler; |
| 7 | +import edu.wpi.first.wpilibj.livewindow.LiveWindow; |
| 8 | +import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; |
| 9 | +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; |
| 10 | + |
| 11 | +import org.usfirst.frc.team199.robot.commands.ExampleCommand; |
| 12 | +import org.usfirst.frc.team199.robot.subsystems.ExampleSubsystem; |
| 13 | + |
| 14 | +/** |
| 15 | + * The VM is configured to automatically run this class, and to call the |
| 16 | + * functions corresponding to each mode, as described in the IterativeRobot |
| 17 | + * documentation. If you change the name of this class or the package after |
| 18 | + * creating this project, you must also update the manifest file in the resource |
| 19 | + * directory. |
| 20 | + */ |
| 21 | +public class Robot extends IterativeRobot { |
| 22 | + |
| 23 | + public static final ExampleSubsystem exampleSubsystem = new ExampleSubsystem(); |
| 24 | + public static OI oi; |
| 25 | + |
| 26 | + Command autonomousCommand; |
| 27 | + SendableChooser<Command> chooser = new SendableChooser<>(); |
| 28 | + |
| 29 | + /** |
| 30 | + * This function is run when the robot is first started up and should be |
| 31 | + * used for any initialization code. |
| 32 | + */ |
| 33 | + @Override |
| 34 | + public void robotInit() { |
| 35 | + oi = new OI(); |
| 36 | + chooser.addDefault("Default Auto", new ExampleCommand()); |
| 37 | + // chooser.addObject("My Auto", new MyAutoCommand()); |
| 38 | + SmartDashboard.putData("Auto mode", chooser); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * This function is called once each time the robot enters Disabled mode. |
| 43 | + * You can use it to reset any subsystem information you want to clear when |
| 44 | + * the robot is disabled. |
| 45 | + */ |
| 46 | + @Override |
| 47 | + public void disabledInit() { |
| 48 | + |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void disabledPeriodic() { |
| 53 | + Scheduler.getInstance().run(); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * This autonomous (along with the chooser code above) shows how to select |
| 58 | + * between different autonomous modes using the dashboard. The sendable |
| 59 | + * chooser code works with the Java SmartDashboard. If you prefer the |
| 60 | + * LabVIEW Dashboard, remove all of the chooser code and uncomment the |
| 61 | + * getString code to get the auto name from the text box below the Gyro |
| 62 | + * |
| 63 | + * You can add additional auto modes by adding additional commands to the |
| 64 | + * chooser code above (like the commented example) or additional comparisons |
| 65 | + * to the switch structure below with additional strings & commands. |
| 66 | + */ |
| 67 | + @Override |
| 68 | + public void autonomousInit() { |
| 69 | + autonomousCommand = chooser.getSelected(); |
| 70 | + |
| 71 | + /* |
| 72 | + * String autoSelected = SmartDashboard.getString("Auto Selector", |
| 73 | + * "Default"); switch(autoSelected) { case "My Auto": autonomousCommand |
| 74 | + * = new MyAutoCommand(); break; case "Default Auto": default: |
| 75 | + * autonomousCommand = new ExampleCommand(); break; } |
| 76 | + */ |
| 77 | + |
| 78 | + // schedule the autonomous command (example) |
| 79 | + if (autonomousCommand != null) |
| 80 | + autonomousCommand.start(); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * This function is called periodically during autonomous |
| 85 | + */ |
| 86 | + @Override |
| 87 | + public void autonomousPeriodic() { |
| 88 | + Scheduler.getInstance().run(); |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public void teleopInit() { |
| 93 | + // This makes sure that the autonomous stops running when |
| 94 | + // teleop starts running. If you want the autonomous to |
| 95 | + // continue until interrupted by another command, remove |
| 96 | + // this line or comment it out. |
| 97 | + if (autonomousCommand != null) |
| 98 | + autonomousCommand.cancel(); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * This function is called periodically during operator control |
| 103 | + */ |
| 104 | + @Override |
| 105 | + public void teleopPeriodic() { |
| 106 | + Scheduler.getInstance().run(); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * This function is called periodically during test mode |
| 111 | + */ |
| 112 | + @Override |
| 113 | + public void testPeriodic() { |
| 114 | + LiveWindow.run(); |
| 115 | + } |
| 116 | +} |
0 commit comments