82dff37237ebbecd43458157343dbf16748c43bf
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / commands / driving / TurnForTime.java
1 package org.usfirst.frc.team3501.robot.commands.driving;
2
3 import org.usfirst.frc.team3501.robot.Constants.Direction;
4 import org.usfirst.frc.team3501.robot.Robot;
5
6 import edu.wpi.first.wpilibj.Timer;
7 import edu.wpi.first.wpilibj.command.Command;
8
9 /***
10 * This command turns the robot in a specified direction for a specified
11 * duration.
12 *
13 * pre-condition: robot is on a flat surface
14 *
15 * post-condition: robot has turned in the specified direction for the specified
16 * time
17 *
18 * @author Meryem, Avi, and Sarvesh
19 *
20 */
21
22 public class TurnForTime extends Command {
23 private final double SPEED = 0.5;
24 private Direction direction;
25 private double seconds;
26 private Timer timer;
27
28 public TurnForTime(double seconds, Direction direction) {
29 this.seconds = seconds;
30 this.direction = direction;
31 }
32
33 @Override
34 protected void initialize() {
35 timer = new Timer();
36 timer.start();
37 }
38
39 @Override
40 protected void execute() {
41 if (direction == Direction.RIGHT) {
42 Robot.driveTrain.setMotorSpeeds(SPEED, -SPEED);
43 } else if (direction == Direction.LEFT) {
44 Robot.driveTrain.setMotorSpeeds(-SPEED, SPEED);
45 }
46 }
47
48 @Override
49 protected boolean isFinished() {
50 if (timer.get() >= seconds)
51 return true;
52 return false;
53 }
54
55 @Override
56 protected void end() {
57 }
58
59 @Override
60 protected void interrupted() {
61 }
62 }