X-Git-Url: http://challenge-bot.com/repos/?a=blobdiff_plain;f=src%2Forg%2Fusfirst%2Ffrc3501%2FRiceCatRobot%2Fsubsystems%2FDriveTrain.java;h=c02dea95c941048dd6fd9651de673386fb576864;hb=eb9e6bd8da48f0833680f6e6705542bacacd4dd8;hp=dda70f85b0fc09390cbf931149d4bc066dc3c673;hpb=fb376f02820fc8dd8404759e2b45fa582969dc3e;p=3501%2F2015-FRC-Spark diff --git a/src/org/usfirst/frc3501/RiceCatRobot/subsystems/DriveTrain.java b/src/org/usfirst/frc3501/RiceCatRobot/subsystems/DriveTrain.java index dda70f8..c02dea9 100644 --- a/src/org/usfirst/frc3501/RiceCatRobot/subsystems/DriveTrain.java +++ b/src/org/usfirst/frc3501/RiceCatRobot/subsystems/DriveTrain.java @@ -8,108 +8,108 @@ import edu.wpi.first.wpilibj.CounterBase.EncodingType; import edu.wpi.first.wpilibj.command.Subsystem; public class DriveTrain extends Subsystem { - private CANJaguar frontLeft, frontRight, rearLeft, rearRight; - private Encoder leftEncoder, rightEncoder; + private CANJaguar frontLeft, frontRight, rearLeft, rearRight; + private Encoder leftEncoder, rightEncoder; - public DriveTrain() { - frontLeft = new CANJaguar(RobotMap.DRIVE_FRONT_LEFT); - frontRight = new CANJaguar(RobotMap.DRIVE_FRONT_RIGHT); - rearLeft = new CANJaguar(RobotMap.DRIVE_REAR_LEFT); - rearRight = new CANJaguar(RobotMap.DRIVE_REAR_RIGHT); - leftEncoder = new Encoder(RobotMap.DRIVE_LEFT_A, RobotMap.DRIVE_LEFT_B, - false, EncodingType.k4X); - rightEncoder = new Encoder(RobotMap.DRIVE_RIGHT_A, - RobotMap.DRIVE_RIGHT_B, false, EncodingType.k4X); - leftEncoder.setDistancePerPulse(RobotMap.DISTANCE_PER_PULSE); - rightEncoder.setDistancePerPulse(RobotMap.DISTANCE_PER_PULSE); - } + public DriveTrain() { + frontLeft = new CANJaguar(RobotMap.DRIVE_FRONT_LEFT); + frontRight = new CANJaguar(RobotMap.DRIVE_FRONT_RIGHT); + rearLeft = new CANJaguar(RobotMap.DRIVE_REAR_LEFT); + rearRight = new CANJaguar(RobotMap.DRIVE_REAR_RIGHT); + leftEncoder = new Encoder(RobotMap.DRIVE_LEFT_A, RobotMap.DRIVE_LEFT_B, + false, EncodingType.k4X); + rightEncoder = new Encoder(RobotMap.DRIVE_RIGHT_A, RobotMap.DRIVE_RIGHT_B, + false, EncodingType.k4X); + leftEncoder.setDistancePerPulse(RobotMap.DISTANCE_PER_PULSE); + rightEncoder.setDistancePerPulse(RobotMap.DISTANCE_PER_PULSE); + } - public void resetEncoders() { - leftEncoder.reset(); - rightEncoder.reset(); - } + public void resetEncoders() { + leftEncoder.reset(); + rightEncoder.reset(); + } - public double getRightSpeed() { - // Returns inches per second - return rightEncoder.getRate(); - } + public double getRightSpeed() { + // Returns inches per second + return rightEncoder.getRate(); + } - public double getLeftSpeed() { - return leftEncoder.getRate(); - } - - public double getAverageSpeed() { - return (getRightSpeed() + getLeftSpeed())/2; - } + public double getLeftSpeed() { + return leftEncoder.getRate(); + } - public double getRightDistance() { - // Returns distance in inches - return rightEncoder.getDistance(); - } + public double getAverageSpeed() { + return (getRightSpeed() + getLeftSpeed()) / 2; + } - public double getLeftDistance() { - // Returns distance in inches - return leftEncoder.getDistance(); - } + public double getRightDistance() { + // Returns distance in inches + return rightEncoder.getDistance(); + } + + public double getLeftDistance() { + // Returns distance in inches + return leftEncoder.getDistance(); + } + + public void stop() { + setMotorSpeeds(0, 0); + } - public void stop() { - setMotorSpeeds(0, 0); + public void setMotorSpeeds(double leftSpeed, double rightSpeed) { + if (Math.abs(leftSpeed) < RobotMap.DRIVE_DEAD_ZONE) { + leftSpeed = 0; } - - public void setMotorSpeeds(double leftSpeed, double rightSpeed) { - if (Math.abs(leftSpeed) < RobotMap.DRIVE_DEAD_ZONE) { - leftSpeed = 0; - } - if (Math.abs(rightSpeed) < RobotMap.DRIVE_DEAD_ZONE) { - rightSpeed = 0; - } - this.frontLeft.set(leftSpeed); - this.frontRight.set(-rightSpeed); - this.rearLeft.set(leftSpeed); - this.rearRight.set(-rightSpeed); + if (Math.abs(rightSpeed) < RobotMap.DRIVE_DEAD_ZONE) { + rightSpeed = 0; } + this.frontLeft.set(leftSpeed); + this.frontRight.set(-rightSpeed); + this.rearLeft.set(leftSpeed); + this.rearRight.set(-rightSpeed); + } - public void arcadeDrive(double yVal, double twist) { - if (yVal < 0 && Math.abs(yVal) < 0.1125) { - yVal = 0; - } else if (yVal > 0 && Math.abs(yVal) < 0.25) { - yVal = 0; - } else if (yVal > 0) { - yVal -= 0.25; - } else if (yVal < 0) { - yVal += 0.15; - } - if (Math.abs(twist) < RobotMap.DRIVE_DEAD_ZONE) { - twist = 0; - } - - double leftMotorSpeed; - double rightMotorSpeed; - // adjust the sensitivity (yVal+rootof (yval)) / 2 - yVal = (yVal + Math.signum(yVal) * Math.sqrt(Math.abs(yVal))) / 2; - // adjust the sensitivity (twist+rootof (twist)) / 2 - twist = (twist + Math.signum(twist) * Math.sqrt(Math.abs(twist))) / 2; - if (yVal > 0) { - if (twist > 0) { - leftMotorSpeed = yVal - twist; - rightMotorSpeed = Math.max(yVal, twist); - } else { - leftMotorSpeed = Math.max(yVal, -twist); - rightMotorSpeed = yVal + twist; - } - } else { - if (twist > 0.0) { - leftMotorSpeed = -Math.max(-yVal, twist); - rightMotorSpeed = yVal + twist; - } else { - leftMotorSpeed = yVal - twist; - rightMotorSpeed = -Math.max(-yVal, -twist); - } - } - setMotorSpeeds(leftMotorSpeed, rightMotorSpeed); + public void arcadeDrive(double yVal, double twist) { + if (yVal < 0 && Math.abs(yVal) < 0.1125) { + yVal = 0; + } else if (yVal > 0 && Math.abs(yVal) < 0.25) { + yVal = 0; + } else if (yVal > 0) { + yVal -= 0.25; + } else if (yVal < 0) { + yVal += 0.15; + } + if (Math.abs(twist) < RobotMap.DRIVE_DEAD_ZONE) { + twist = 0; } - @Override - protected void initDefaultCommand() { + double leftMotorSpeed; + double rightMotorSpeed; + // adjust the sensitivity (yVal+rootof (yval)) / 2 + yVal = (yVal + Math.signum(yVal) * Math.sqrt(Math.abs(yVal))) / 2; + // adjust the sensitivity (twist+rootof (twist)) / 2 + twist = (twist + Math.signum(twist) * Math.sqrt(Math.abs(twist))) / 2; + if (yVal > 0) { + if (twist > 0) { + leftMotorSpeed = yVal - twist; + rightMotorSpeed = Math.max(yVal, twist); + } else { + leftMotorSpeed = Math.max(yVal, -twist); + rightMotorSpeed = yVal + twist; + } + } else { + if (twist > 0.0) { + leftMotorSpeed = -Math.max(-yVal, twist); + rightMotorSpeed = yVal + twist; + } else { + leftMotorSpeed = yVal - twist; + rightMotorSpeed = -Math.max(-yVal, -twist); + } } + setMotorSpeeds(leftMotorSpeed, rightMotorSpeed); + } + + @Override + protected void initDefaultCommand() { + } }