X-Git-Url: http://challenge-bot.com/repos/?a=blobdiff_plain;f=src%2Forg%2Fusfirst%2Ffrc%2Fteam3501%2Frobot%2Fcommands%2Fdriving%2FDriveDistance.java;h=d297e66a1dcb1ecb55445b8291ce089d7d4f24ea;hb=refs%2Fheads%2Fchris%2FautonGearStrategy;hp=47fc46ea0303ed6689b3c2a03b6c918b30407c8f;hpb=e12d6901671044dfcf7eb0380c8193ec69bbc63d;p=3501%2F2017steamworks diff --git a/src/org/usfirst/frc/team3501/robot/commands/driving/DriveDistance.java b/src/org/usfirst/frc/team3501/robot/commands/driving/DriveDistance.java index 47fc46e..d297e66 100755 --- a/src/org/usfirst/frc/team3501/robot/commands/driving/DriveDistance.java +++ b/src/org/usfirst/frc/team3501/robot/commands/driving/DriveDistance.java @@ -1,6 +1,5 @@ package org.usfirst.frc.team3501.robot.commands.driving; -import org.usfirst.frc.team3501.robot.MathLib; import org.usfirst.frc.team3501.robot.Robot; import org.usfirst.frc.team3501.robot.subsystems.DriveTrain; import org.usfirst.frc.team3501.robot.utils.PIDController; @@ -18,77 +17,57 @@ import edu.wpi.first.wpilibj.command.Command; public class DriveDistance extends Command { private DriveTrain driveTrain = Robot.getDriveTrain(); private double maxTimeOut; - private PIDController driveController; - private PIDController gyroController; - private Preferences prefs; - private double target; - private double gyroP; - private double gyroI; - private double gyroD; + private double zeroAngle; + private Preferences prefs; + private PIDController driveController; private double driveP; private double driveI; private double driveD; + private double gyroP; - public DriveDistance(double distance, double motorVal) { + public DriveDistance(double distance, double maxTimeOut) { requires(driveTrain); + this.maxTimeOut = maxTimeOut; + this.target = distance; + this.driveP = driveTrain.driveP; this.driveI = driveTrain.driveI; this.driveD = driveTrain.driveD; - this.gyroP = driveTrain.defaultGyroP; - this.gyroI = driveTrain.defaultGyroI; - this.gyroD = driveTrain.defaultGyroD; - this.driveController = new PIDController(this.driveP, this.driveI, - this.driveD); - this.driveController.setDoneRange(0.5); + this.gyroP = driveTrain.driveStraightGyroP; + this.driveController = new PIDController(driveP, driveI, driveD); + this.driveController.setDoneRange(1.0); this.driveController.setMaxOutput(1.0); this.driveController.setMinDoneCycles(5); - - this.gyroController = new PIDController(this.gyroP, this.gyroI, this.gyroD); - this.gyroController.setDoneRange(1); - this.gyroController.setMinDoneCycles(5); } @Override protected void initialize() { this.driveTrain.resetEncoders(); - this.driveTrain.resetGyro(); this.driveController.setSetPoint(this.target); - this.gyroController.setSetPoint(this.driveTrain.getZeroAngle()); + this.zeroAngle = driveTrain.getAngle(); + System.out.println("drive " + target); } @Override protected void execute() { - double xVal = 0; - double yVal = this.driveController - .calcPID(this.driveTrain.getAvgEncoderDistance()); - - if (this.driveTrain.getAngle() - this.driveTrain.getZeroAngle() < 30) { - xVal = -this.gyroController - .calcPID(this.driveTrain.getAngle() - this.driveTrain.getZeroAngle()); - } - // System.out.println("turn: " + xVal); - double leftDrive = MathLib.calcLeftTankDrive(-xVal, yVal); - double rightDrive = MathLib.calcRightTankDrive(xVal, -yVal); + double xVal = gyroP * (driveTrain.getAngle() - zeroAngle); + double yVal = driveController.calcPID(driveTrain.getLeftEncoderDistance()); + double leftDrive = yVal - xVal; + double rightDrive = yVal + xVal; this.driveTrain.setMotorValues(leftDrive, rightDrive); - - System.out.println(driveTrain.getAvgEncoderDistance()); - // System.out.println("motorval: " + yVal); } @Override protected boolean isFinished() { - boolean isDone = this.driveController.isDone(); - if (timeSinceInitialized() >= maxTimeOut || isDone) - System.out.println("time: " + timeSinceInitialized()); - return timeSinceInitialized() >= maxTimeOut || isDone; + return timeSinceInitialized() >= maxTimeOut + || this.driveController.isDone(); } @Override protected void end() { - driveTrain.stop(); } @Override