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