Initialize timer
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / commands / climber / MaintainWinchSpeed.java
1 package org.usfirst.frc.team3501.robot.commands.climber;
2
3 import org.usfirst.frc.team3501.robot.Constants;
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 runs the winch at a specified speed and time in seconds when the
11 * button triggering it is pressed. This command also makes the drive train
12 * motors run because the winch is controlled by the drive train.
13 *
14 * pre-condition: This command is run by a button in OI. The robot must be
15 * attached to the rope.
16 *
17 * post-condition: Winch motor set to a specified speed for a specified time.
18 *
19 * @param motorVal
20 * value range is from -1 to 1
21 * @param time
22 * in seconds
23 * @author shivanighanta
24 *
25 */
26 public class MaintainWinchSpeed extends Command {
27 Timer timer;
28 private double time;
29 private double motorVal;
30
31 /**
32 * See JavaDoc comment in class for details
33 *
34 * @param time
35 * time in seconds to run the winch
36 * @param motorVal
37 * value range is from -1 to 1
38 */
39 public MaintainWinchSpeed(double time, double motorVal) {
40 timer = new Timer();
41 requires(Robot.getDriveTrain());
42 this.time = time;
43 this.motorVal = motorVal;
44 }
45
46 @Override
47 protected void initialize() {
48 timer.start();
49 }
50
51 @Override
52 protected void execute() {
53 Robot.getDriveTrain().setMotorValues(Constants.Climber.MAINTAIN_MOTOR_VAL,
54 Constants.Climber.MAINTAIN_MOTOR_VAL);
55
56 }
57
58 @Override
59 protected boolean isFinished() {
60 return timer.get() >= time;
61 }
62
63 @Override
64 protected void end() {
65 Robot.getDriveTrain().stop();
66 }
67
68 @Override
69 protected void interrupted() {
70 end();
71 }
72 }