| 1 | package org.usfirst.frc3501.RiceCatRobot.commands; |
| 2 | |
| 3 | import org.usfirst.frc3501.RiceCatRobot.robot.Robot; |
| 4 | import org.usfirst.frc3501.RiceCatRobot.subsystems.DriveTrain; |
| 5 | |
| 6 | import edu.wpi.first.wpilibj.command.Command; |
| 7 | |
| 8 | public class MoveDistance extends Command { |
| 9 | |
| 10 | double distance, minSpeed, maxSpeed; |
| 11 | |
| 12 | public MoveDistance(double distance, double minSpeed, double maxSpeed) { |
| 13 | requires(Robot.driveTrain); |
| 14 | this.distance = distance; |
| 15 | this.minSpeed = minSpeed; |
| 16 | this.maxSpeed = maxSpeed; |
| 17 | } |
| 18 | |
| 19 | protected void initialize() { |
| 20 | Robot.driveTrain.resetEncoders(); |
| 21 | } |
| 22 | |
| 23 | @Override |
| 24 | protected void execute() { |
| 25 | double speed = 4 * (minSpeed - maxSpeed) * |
| 26 | Math.pow((Robot.driveTrain.getAverageSpeed() / distance - 0.5), 2) |
| 27 | + maxSpeed; |
| 28 | Robot.driveTrain.setMotorSpeeds(speed, speed); |
| 29 | } |
| 30 | |
| 31 | @Override |
| 32 | protected boolean isFinished() { |
| 33 | if (Robot.driveTrain.getLeftDistance() > distance |
| 34 | && Robot.driveTrain.getRightDistance() > distance) |
| 35 | return true; |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | protected void end() { |
| 41 | Robot.driveTrain.stop(); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | protected void interrupted() { |
| 46 | end(); |
| 47 | } |
| 48 | } |