From 79e4711dd8b4e31ae0ca886b5b94ff0fc302ca4e Mon Sep 17 00:00:00 2001 From: David Date: Fri, 20 Nov 2015 10:55:36 -0800 Subject: [PATCH] enable DriveDistance to drive backwards --- .../frc3501/RiceCatRobot/commands/DriveDistance.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 -- 2.30.2