| 1 | package org.usfirst.frc3501.RiceCatRobot.commands; |
| 2 | |
| 3 | import org.usfirst.frc3501.RiceCatRobot.Robot; |
| 4 | import org.usfirst.frc3501.RiceCatRobot.RobotMap.Direction; |
| 5 | |
| 6 | import edu.wpi.first.wpilibj.Timer; |
| 7 | import edu.wpi.first.wpilibj.command.Command; |
| 8 | |
| 9 | public class TurnFor extends Command { |
| 10 | private double seconds; |
| 11 | private Timer timer; |
| 12 | private Direction direction; |
| 13 | |
| 14 | public TurnFor(double seconds, Direction direction) { |
| 15 | this.seconds = seconds; |
| 16 | this.direction = direction; |
| 17 | } |
| 18 | |
| 19 | @Override |
| 20 | protected void initialize() { |
| 21 | timer = new Timer(); |
| 22 | timer.start(); |
| 23 | } |
| 24 | |
| 25 | @Override |
| 26 | protected void execute() { |
| 27 | if (direction == Direction.LEFT) { |
| 28 | Robot.driveTrain.arcadeDrive(0, -0.5); |
| 29 | } else if (direction == Direction.RIGHT) { |
| 30 | Robot.driveTrain.arcadeDrive(0, 0.5); |
| 31 | } else { |
| 32 | Robot.driveTrain.arcadeDrive(0, 0); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | protected boolean isFinished() { |
| 38 | System.out.println(timer.get()); |
| 39 | System.out.println(seconds); |
| 40 | if (timer.get() > seconds) { |
| 41 | Robot.driveTrain.arcadeDrive(0, 0); |
| 42 | } |
| 43 | return timer.get() > seconds; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | protected void end() { |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | protected void interrupted() { |
| 52 | end(); |
| 53 | } |
| 54 | } |