From: David Date: Fri, 20 Nov 2015 18:55:36 +0000 (-0800) Subject: enable DriveDistance to drive backwards X-Git-Url: http://challenge-bot.com/repos/?a=commitdiff_plain;h=79e4711dd8b4e31ae0ca886b5b94ff0fc302ca4e;p=3501%2F2015-FRC-Spark enable DriveDistance to drive backwards --- diff --git a/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveDistance.java b/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveDistance.java index 75ae227..461050e 100644 --- a/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveDistance.java +++ b/src/org/usfirst/frc3501/RiceCatRobot/commands/DriveDistance.java @@ -19,7 +19,9 @@ public class DriveDistance extends Command { // Since negative values in setMotorSpeeds(...) are forwards, we reverse // speed here so positive input values will move the robot forwards. this.speed = -speed; - this.distance = distance; + + // ensure distance is positive + this.distance = Math.max(distance, -distance); } @Override @@ -35,8 +37,8 @@ public class DriveDistance extends Command { @Override protected boolean isFinished() { - return Robot.driveTrain.getLeftDistance() >= distance - && Robot.driveTrain.getRightDistance() >= distance; + return Math.abs(Robot.driveTrain.getLeftDistance()) >= distance + && Math.abs(Robot.driveTrain.getRightDistance()) >= distance; } @Override