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