make so does not crash
[3501/3501-spark-go] / src / org / usfirst / frc / team3501 / robot / Robot.java
index 633cde60b724bafc01ef82cf73ce10b8d3fb2c58..84fd2f9faa8afa3fc1726a564d18c5abcae4433e 100644 (file)
@@ -9,7 +9,9 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
 import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
 
 import org.usfirst.frc.team3501.robot.autons.*;
+import org.usfirst.frc.team3501.robot.commands.*;
 import org.usfirst.frc.team3501.robot.subsystems.*;
+import org.usfirst.frc.team3501.util.AutonData;
 
 public class Robot extends IterativeRobot {
 
@@ -21,19 +23,22 @@ public class Robot extends IterativeRobot {
 
        public static OI oi;
 
-       private SendableChooser autoChooser;
+       public static AutonData autonData;
 
+       private SendableChooser autonChooser;
     private Command autonomousCommand;
 
     public void robotInit() {
-               oi = new OI();
-
                drivetrain = new Drivetrain();
                arm        = new Arm();
                claw       = new Claw();
 
                pneumatics = new Pneumatics();
 
+               autonData = new AutonData();
+
+               oi = new OI();
+
                chooseAuto();
     }
 
@@ -42,9 +47,11 @@ public class Robot extends IterativeRobot {
        }
 
     public void autonomousInit() {
-        pneumatics.start();
+        schedule(new TurnOnCompressor());
 
-        autonomousCommand = (Command) autoChooser.getSelected();
+        autonData.update();
+
+        autonomousCommand = (Command) autonChooser.getSelected();
         autonomousCommand.start();
     }
 
@@ -53,9 +60,10 @@ public class Robot extends IterativeRobot {
     }
 
     public void teleopInit() {
-        pneumatics.start();
+        schedule(new TurnOnCompressor());
 
-        autonomousCommand.cancel();
+        if (autonomousCommand != null)
+            autonomousCommand.cancel();
     }
 
     public void teleopPeriodic() {
@@ -66,17 +74,17 @@ public class Robot extends IterativeRobot {
         LiveWindow.run();
     }
 
-    public void disabledInit() {
-        pneumatics.stop();
-    }
-
     private void chooseAuto() {
-        autoChooser = new SendableChooser();
+        autonChooser = new SendableChooser();
 
-        autoChooser.addDefault("Pick up container", new ContainerOverStep());
-        autoChooser.addObject("Drive over step",    new DriveOverStep());
-        autoChooser.addObject("Drive past step",    new DrivePastStep());
+        autonChooser.addDefault("Pick up container", new ContainerOverStep());
+        autonChooser.addObject("Drive over step",    new DriveOverStep());
+        autonChooser.addObject("Drive past step",    new DrivePastStep());
+
+        SmartDashboard.putData("Auto Mode", autonChooser);
+    }
 
-        SmartDashboard.putData("Auto Mode", autoChooser);
+    private void schedule(Command c) {
+        Scheduler.getInstance().add(c);
     }
 }