Commit | Line | Data |
---|---|---|
6bb7f8ac | 1 | package org.usfirst.frc.team3501.robot.commands.driving; |
be737780 | 2 | |
5ac4d78e | 3 | import org.usfirst.frc.team3501.robot.Constants.Direction; |
53924f8d | 4 | import org.usfirst.frc.team3501.robot.Robot; |
5ac4d78e | 5 | |
de0fd5e3 | 6 | import edu.wpi.first.wpilibj.Timer; |
be737780 ME |
7 | import edu.wpi.first.wpilibj.command.Command; |
8 | ||
f1242e7b ME |
9 | /*** |
10 | * This command turns the robot in a specified direction for a specified | |
4ec3b5b3 | 11 | * duration in seconds. |
f1242e7b ME |
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 | ||
be737780 | 22 | public class TurnForTime extends Command { |
53924f8d ME |
23 | private final double SPEED = 0.5; |
24 | private Direction direction; | |
25 | private double seconds; | |
26 | private Timer timer; | |
be737780 | 27 | |
5ac4d78e | 28 | public TurnForTime(double seconds, Direction direction) { |
6389c060 ME |
29 | this.seconds = seconds; |
30 | this.direction = direction; | |
5ac4d78e ME |
31 | } |
32 | ||
33 | @Override | |
34 | protected void initialize() { | |
6389c060 ME |
35 | timer = new Timer(); |
36 | timer.start(); | |
5ac4d78e | 37 | |
53924f8d ME |
38 | if (direction == Direction.RIGHT) { |
39 | Robot.driveTrain.setMotorSpeeds(SPEED, -SPEED); | |
40 | } else if (direction == Direction.LEFT) { | |
41 | Robot.driveTrain.setMotorSpeeds(-SPEED, SPEED); | |
42 | } | |
5ac4d78e ME |
43 | } |
44 | ||
4ec3b5b3 ME |
45 | @Override |
46 | protected void execute() { | |
47 | ||
48 | } | |
49 | ||
5ac4d78e ME |
50 | @Override |
51 | protected boolean isFinished() { | |
53924f8d ME |
52 | if (timer.get() >= seconds) |
53 | return true; | |
5ac4d78e ME |
54 | return false; |
55 | } | |
56 | ||
57 | @Override | |
58 | protected void end() { | |
f7ab7af3 | 59 | Robot.driveTrain.setMotorSpeeds(0, 0); |
5ac4d78e ME |
60 | } |
61 | ||
62 | @Override | |
63 | protected void interrupted() { | |
64 | } | |
be737780 | 65 | } |