88195a4b2d89227fffaa90ea3bf2ede0cbda4572
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / commands / climber / RunWinch.java
1 package org.usfirst.frc.team3501.robot.commands.climber;
2
3 import org.usfirst.frc.team3501.robot.Robot;
4
5 import edu.wpi.first.wpilibj.Timer;
6 import edu.wpi.first.wpilibj.command.Command;
7
8 /**
9 * This command runs the winch at a specified speed and time in seconds when the
10 * button triggering it is pressed. This command also makes the drive train
11 * motors run because the winch is controlled by the drive train.
12 *
13 * pre-condition: This command is run by a button in OI. The robot must be
14 * attached to the rope.
15 *
16 * post-condition: Winch motor set to a specified speed for a specified time.
17 *
18 * @param motorVal
19 * value range is from -1 to 1
20 * @param time
21 * in seconds
22 * @author shivanighanta
23 *
24 */
25
26 public class RunWinch 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 RunWinch(double time, double motorVal) {
40 requires(Robot.getDriveTrain());
41 this.time = time;
42 this.motorVal = motorVal;
43 }
44
45 @Override
46 protected void initialize() {
47 timer.start();
48 }
49
50 @Override
51 protected void execute() {
52 Robot.getDriveTrain().setMotorValues(motorVal, motorVal);
53
54 }
55
56 @Override
57 protected boolean isFinished() {
58 return timer.get() >= time;
59 }
60
61 @Override
62 protected void end() {
63 Robot.getDriveTrain().stop();
64 }
65
66 @Override
67 protected void interrupted() {
68 end();
69 }
70 }