From: David Date: Fri, 20 Nov 2015 18:42:23 +0000 (-0800) Subject: add DriveForTime command X-Git-Url: http://challenge-bot.com/repos/?a=commitdiff_plain;h=95adbe68c052382caa3e8a6b78b4610efbe22626;p=3501%2F2015-FRC-Spark add DriveForTime command --- diff --git a/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveFor.java b/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveFor.java deleted file mode 100644 index b614a07..0000000 --- a/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveFor.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.usfirst.frc3501.RiceCatRobot.commands; - -import org.usfirst.frc3501.RiceCatRobot.Robot; -import org.usfirst.frc3501.RiceCatRobot.RobotMap.Direction; -import org.usfirst.frc3501.RiceCatRobot.subsystems.DriveTrain; - -import edu.wpi.first.wpilibj.Timer; -import edu.wpi.first.wpilibj.command.Command; - -/** - * This command takes a time in seconds which is how long it should run - * - */ -public class DriveFor extends Command { - private double seconds; - private double speed; - private Timer timer; - private Direction direction; - - public DriveFor(double seconds, double speed, Direction direction) { - // limit speed to the range [0, MOTOR_MAX_VAL] - this.speed = Math.max(speed, -speed); - this.speed = Math.min(speed, DriveTrain.MOTOR_MAX_VAL); - - this.seconds = seconds; - this.direction = direction; - } - - @Override - protected void initialize() { - timer = new Timer(); - timer.reset(); - timer.start(); - } - - @Override - protected void execute() { - if (direction == Direction.FORWARD) { - Robot.driveTrain.setMotorSpeeds(-speed, -speed); - } else if (direction == Direction.BACKWARD) { - Robot.driveTrain.setMotorSpeeds(speed, speed); - } - } - - @Override - protected boolean isFinished() { - return timer.get() > seconds; - } - - @Override - protected void end() { - Robot.driveTrain.setMotorSpeeds(0, 0); - } - - @Override - protected void interrupted() { - end(); - } -} \ No newline at end of file diff --git a/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveForTime.java b/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveForTime.java new file mode 100644 index 0000000..9f7d91b --- /dev/null +++ b/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveForTime.java @@ -0,0 +1,59 @@ +package org.usfirst.frc3501.RiceCatRobot.commands; + +import org.usfirst.frc3501.RiceCatRobot.Robot; +import org.usfirst.frc3501.RiceCatRobot.RobotMap.Direction; +import org.usfirst.frc3501.RiceCatRobot.subsystems.DriveTrain; + +import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.wpilibj.command.Command; + +/** + * This command takes a time in seconds which is how long it should run + * + */ +public class DriveForTime extends Command { + private double seconds; + private double speed; + private Timer timer; + private Direction direction; + + public DriveForTime(double seconds, double speed, Direction direction) { + // limit speed to the range [0, MOTOR_MAX_VAL] + this.speed = Math.max(speed, -speed); + this.speed = Math.min(speed, DriveTrain.MOTOR_MAX_VAL); + + this.seconds = seconds; + this.direction = direction; + } + + @Override + protected void initialize() { + timer = new Timer(); + timer.reset(); + timer.start(); + } + + @Override + protected void execute() { + if (direction == Direction.FORWARD) { + Robot.driveTrain.setMotorSpeeds(-speed, -speed); + } else if (direction == Direction.BACKWARD) { + Robot.driveTrain.setMotorSpeeds(speed, speed); + } + } + + @Override + protected boolean isFinished() { + return timer.get() > seconds; + } + + @Override + protected void end() { + Robot.driveTrain.setMotorSpeeds(0, 0); + } + + @Override + protected void interrupted() { + end(); + } +} \ No newline at end of file diff --git a/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveForTimesSequence.java b/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveForTimesSequence.java index d5d4b44..8b1321d 100644 --- a/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveForTimesSequence.java +++ b/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveForTimesSequence.java @@ -31,7 +31,7 @@ public class DriveForTimesSequence extends CommandGroup { double time = timings[i][0]; double speed = timings[i][1]; - addSequential(new DriveFor(time, speed, direction)); + addSequential(new DriveForTime(time, speed, direction)); } } } \ No newline at end of file