X-Git-Url: http://challenge-bot.com/repos/?a=blobdiff_plain;f=src%2Forg%2Fusfirst%2Ffrc%2Fteam3501%2Frobot%2Fcommands%2Fdriving%2FTurnForAngle.java;h=44434c694531aa65751e95f307fe740ffbf1378a;hb=refs%2Fheads%2Fchris%2FautonGearStrategy;hp=86176f15fe9e3b03ebaf0ac447af00f597f1cb17;hpb=f0a71840f17c1039ce4be1f66cf324cc979a9966;p=3501%2F2017steamworks diff --git a/src/org/usfirst/frc/team3501/robot/commands/driving/TurnForAngle.java b/src/org/usfirst/frc/team3501/robot/commands/driving/TurnForAngle.java index 86176f1..44434c6 100755 --- a/src/org/usfirst/frc/team3501/robot/commands/driving/TurnForAngle.java +++ b/src/org/usfirst/frc/team3501/robot/commands/driving/TurnForAngle.java @@ -28,15 +28,17 @@ public class TurnForAngle extends Command { private double gyroI; private double gyroD; + private double zeroAngle; + public TurnForAngle(double angle, Direction direction, double maxTimeOut) { requires(Robot.getDriveTrain()); this.direction = direction; this.maxTimeOut = maxTimeOut; - this.target = angle; + this.target = Math.abs(angle); - this.gyroP = driveTrain.defaultGyroP; - this.gyroI = driveTrain.defaultGyroI; - this.gyroD = driveTrain.defaultGyroD; + this.gyroP = driveTrain.turnP; + this.gyroI = driveTrain.turnI; + this.gyroD = driveTrain.turnD; this.gyroController = new PIDController(this.gyroP, this.gyroI, this.gyroD); this.gyroController.setDoneRange(1); @@ -46,8 +48,8 @@ public class TurnForAngle extends Command { @Override protected void initialize() { this.driveTrain.resetEncoders(); - this.driveTrain.resetGyro(); this.gyroController.setSetPoint(this.target); + this.zeroAngle = driveTrain.getAngle(); } @Override @@ -55,19 +57,20 @@ public class TurnForAngle extends Command { double xVal = 0; xVal = this.gyroController - .calcPID(this.driveTrain.getAngle() - this.driveTrain.getZeroAngle()); + .calcPID(Math.abs(this.driveTrain.getAngle() - this.zeroAngle)); - double leftDrive; - double rightDrive; + double leftDrive = 0; + double rightDrive = 0; if (direction == Constants.Direction.RIGHT) { leftDrive = xVal; rightDrive = -xVal; - } else { + } else if (direction == Constants.Direction.LEFT) { leftDrive = -xVal; rightDrive = xVal; } this.driveTrain.setMotorValues(leftDrive, rightDrive); + System.out.println(this.driveTrain.getAngle() - this.zeroAngle); } @Override