Autoformatted

This commit is contained in:
Adam Long 2016-09-28 18:54:01 +00:00
parent a9b18bc58a
commit b1f2c54ad2
14 changed files with 53 additions and 51 deletions

View File

@ -35,9 +35,9 @@ public class OI {
// Print log when button 1 pressed // Print log when button 1 pressed
//joystickButtons[0][0].whenPressed(new LogEncoder()); //joystickButtons[0][0].whenPressed(new LogEncoder());
joystickButtons[0][0].whileHeld(new SetShooterState(true)); joystickButtons[0][0].whileHeld(new SetShooterState(true));
joystickButtons[0][2].whileHeld(new SpinRollers(-0.5,false)); joystickButtons[0][2].whileHeld(new SpinRollers(-0.5, false));
joystickButtons[0][3].whileHeld(new SpinRollers(1,false)); joystickButtons[0][3].whileHeld(new SpinRollers(1, false));
joystickButtons[0][6].whileHeld(new SpinRollers(1,true)); joystickButtons[0][6].whileHeld(new SpinRollers(1, true));
// joystickButtons[0][2].whileHeld(new PIDDrive(400)); // joystickButtons[0][2].whileHeld(new PIDDrive(400));
joystickButtons[1][0].whileHeld(new MoveArm(1)); joystickButtons[1][0].whileHeld(new MoveArm(1));
joystickButtons[1][1].whileHeld(new MoveArm(-1)); joystickButtons[1][1].whileHeld(new MoveArm(-1));

View File

@ -31,7 +31,7 @@ public class Robot extends IterativeRobot {
SmartDashboard.putData("MainArm", CommandBase.mainArm.getPIDController()); SmartDashboard.putData("MainArm", CommandBase.mainArm.getPIDController());
SmartDashboard.putData("LeftEncoderController", CommandBase.driveBase.getLeftController()); SmartDashboard.putData("LeftEncoderController", CommandBase.driveBase.getLeftController());
SmartDashboard.putData("gyroPID", CommandBase.driveBase.getGyroController()); SmartDashboard.putData("gyroPID", CommandBase.driveBase.getGyroController());
SmartDashboard.putNumber("GyroCorrection",0.13); SmartDashboard.putNumber("GyroCorrection", 0.13);
SmartDashboard.putBoolean("CompressorEnabled", true); SmartDashboard.putBoolean("CompressorEnabled", true);
//Automatically determine if rolling in or rolling out //Automatically determine if rolling in or rolling out
SmartDashboard.putBoolean("SmartRollers", false); SmartDashboard.putBoolean("SmartRollers", false);
@ -67,7 +67,7 @@ public class Robot extends IterativeRobot {
SmartDashboard.putNumber("ArmAngleRaw", CommandBase.mainArm.getRaw()); SmartDashboard.putNumber("ArmAngleRaw", CommandBase.mainArm.getRaw());
SmartDashboard.putNumber("ArmAngleDegrees", CommandBase.mainArm.getDegrees()); SmartDashboard.putNumber("ArmAngleDegrees", CommandBase.mainArm.getDegrees());
SmartDashboard.putNumber("tmpRotations", CommandBase.driveBase.getLeftRotations()); SmartDashboard.putNumber("tmpRotations", CommandBase.driveBase.getLeftRotations());
if (Robot.oi.getJoysticks()[1].getRawButton(3)){ if (Robot.oi.getJoysticks()[1].getRawButton(3)) {
CommandBase.pneumatics.setArmStopState(true); CommandBase.pneumatics.setArmStopState(true);
} else { } else {
CommandBase.pneumatics.setArmStopState(false); CommandBase.pneumatics.setArmStopState(false);

View File

@ -22,7 +22,7 @@ public class AutoDrive extends CommandBase {
} }
protected void execute() { protected void execute() {
if (startDriving) { if (startDriving) {
driveBase.pidDrive(distance,SmartDashboard.getNumber("GyroCorrection")); driveBase.pidDrive(distance, SmartDashboard.getNumber("GyroCorrection"));
} }
startDriving = false; startDriving = false;
} }

View File

@ -7,14 +7,14 @@ public class AutoDriveStraightDistance extends CommandBase {
public AutoDriveStraightDistance(double distance, double timeout) { public AutoDriveStraightDistance(double distance, double timeout) {
requires(driveBase); requires(driveBase);
setTimeout(timeout); setTimeout(timeout);
this.distance=distance; this.distance = distance;
} }
protected void initialize() { protected void initialize() {
driveBase.resetGyro(); driveBase.resetGyro();
driveBase.getLeftEncoder().reset(); driveBase.getLeftEncoder().reset();
} }
protected void execute() { protected void execute() {
driveBase.pidDrive(distance,SmartDashboard.getNumber("GyroCorrection")); driveBase.pidDrive(distance, SmartDashboard.getNumber("GyroCorrection"));
} }
protected void end() { protected void end() {
driveBase.getLeftController().disable(); driveBase.getLeftController().disable();
@ -24,7 +24,7 @@ public class AutoDriveStraightDistance extends CommandBase {
end(); end();
} }
protected boolean isFinished() { protected boolean isFinished() {
return isTimedOut() || Math.abs(distance-driveBase.getLeftRotations()) <= 3; return isTimedOut() || Math.abs(distance - driveBase.getLeftRotations()) <= 3;
} }
} }
// vim: sw=2:ts=2:sts=2 // vim: sw=2:ts=2:sts=2

View File

@ -7,13 +7,13 @@ public class AutoDriveStraightTime extends CommandBase {
public AutoDriveStraightTime(double speed, double time) { public AutoDriveStraightTime(double speed, double time) {
requires(driveBase); requires(driveBase);
setTimeout(time); setTimeout(time);
this.speed=speed; this.speed = speed;
} }
protected void initialize() { protected void initialize() {
driveBase.resetGyro(); driveBase.resetGyro();
} }
protected void execute() { protected void execute() {
driveBase.driveStraight(-speed,SmartDashboard.getNumber("GyroCorrection")); driveBase.driveStraight(-speed, SmartDashboard.getNumber("GyroCorrection"));
} }
protected void end() { protected void end() {
driveBase.stopDriving(); driveBase.stopDriving();

View File

@ -6,7 +6,7 @@ public class AutoRotate extends CommandBase {
double degrees; double degrees;
public AutoRotate(double degrees) { public AutoRotate(double degrees) {
requires(driveBase); requires(driveBase);
this.degrees=degrees; this.degrees = degrees;
setTimeout(2.5); setTimeout(2.5);
} }
protected void initialize() { protected void initialize() {

View File

@ -6,6 +6,6 @@ public class RoutineDriveStraightDistance extends CommandGroup {
public RoutineDriveStraightDistance() { public RoutineDriveStraightDistance() {
addSequential(new AutoSetArmStopState(true)); addSequential(new AutoSetArmStopState(true));
addSequential(new AutoResetLower(-1)); addSequential(new AutoResetLower(-1));
addSequential(new AutoDriveStraightDistance(200,5)); addSequential(new AutoDriveStraightDistance(200, 5));
} }
} }

View File

@ -6,6 +6,6 @@ public class RoutineDriveStraightTime extends CommandGroup {
public RoutineDriveStraightTime() { public RoutineDriveStraightTime() {
addSequential(new AutoSetArmStopState(true)); addSequential(new AutoSetArmStopState(true));
addSequential(new AutoResetLower(-1)); addSequential(new AutoResetLower(-1));
addSequential(new AutoDriveStraightTime(0.5,1)); addSequential(new AutoDriveStraightTime(0.5, 1));
} }
} }

View File

@ -6,8 +6,10 @@ public class RoutineRaiseArmFire extends CommandGroup {
public RoutineRaiseArmFire() { public RoutineRaiseArmFire() {
addSequential(new AutoSetArmPosition(90)); addSequential(new AutoSetArmPosition(90));
//Raise the arm a little before spinning rollers //Raise the arm a little before spinning rollers
try{ wait(2); }catch(Exception e){ } try {
addParallel(new AutoSpinRollers(0.5,5)); wait(2);
} catch (Exception e) { }
addParallel(new AutoSpinRollers(0.5, 5));
addSequential(new AutoSetShooterState(true)); addSequential(new AutoSetShooterState(true));
} }
} }

View File

@ -6,11 +6,11 @@ public class RoutineShoot extends CommandGroup {
public RoutineShoot() { public RoutineShoot() {
addSequential(new AutoSetArmStopState(true)); addSequential(new AutoSetArmStopState(true));
addSequential(new AutoResetLower(-1)); addSequential(new AutoResetLower(-1));
addSequential(new AutoDriveStraightTime(0.5,1)); addSequential(new AutoDriveStraightTime(0.5, 1));
addParallel(new AutoSetArmPosition(90)); addParallel(new AutoSetArmPosition(90));
addSequential(new AutoRotate(45)); addSequential(new AutoRotate(45));
addSequential(new AutoDriveStraightTime(0.4,1.5)); addSequential(new AutoDriveStraightTime(0.4, 1.5));
addSequential(new AutoSpinRollers(1,2)); addSequential(new AutoSpinRollers(1, 2));
addSequential(new AutoSetShooterState(true)); addSequential(new AutoSetShooterState(true));
addSequential(new AutoSetArmStopState(false)); addSequential(new AutoSetArmStopState(false));
addParallel(new AutoSetArmPosition(10)); addParallel(new AutoSetArmPosition(10));

View File

@ -6,19 +6,19 @@ public class RoutineTwoBallDropOff extends CommandGroup {
public RoutineTwoBallDropOff() { public RoutineTwoBallDropOff() {
addSequential(new AutoSetArmStopState(true)); addSequential(new AutoSetArmStopState(true));
addSequential(new AutoResetLower(-1)); addSequential(new AutoResetLower(-1));
addSequential(new AutoDriveStraightTime(0.5,2)); addSequential(new AutoDriveStraightTime(0.5, 2));
addSequential(new AutoMoveArm(0.5,1)); addSequential(new AutoMoveArm(0.5, 1));
addSequential(new AutoSpinRollers(1,2)); addSequential(new AutoSpinRollers(1, 2));
addSequential(new AutoSetShooterState(true)); addSequential(new AutoSetShooterState(true));
addSequential(new AutoResetLower(-1)); addSequential(new AutoResetLower(-1));
addSequential(new AutoRotate(180)); addSequential(new AutoRotate(180));
addSequential(new AutoSetShooterState(false)); addSequential(new AutoSetShooterState(false));
addParallel(new AutoSpinRollers(-0.5,3)); addParallel(new AutoSpinRollers(-0.5, 3));
addSequential(new AutoDriveStraightTime(0.5,2)); addSequential(new AutoDriveStraightTime(0.5, 2));
addSequential(new AutoRotate(180)); addSequential(new AutoRotate(180));
addSequential(new AutoDriveStraightTime(0.5,2)); addSequential(new AutoDriveStraightTime(0.5, 2));
addSequential(new AutoMoveArm(0.5,1)); addSequential(new AutoMoveArm(0.5, 1));
addSequential(new AutoSpinRollers(1,2)); addSequential(new AutoSpinRollers(1, 2));
addSequential(new AutoSetShooterState(true)); addSequential(new AutoSetShooterState(true));
addSequential(new AutoRotate(180)); addSequential(new AutoRotate(180));
addSequential(new AutoSetShooterState(false)); addSequential(new AutoSetShooterState(false));

View File

@ -16,7 +16,7 @@ public class PIDDrive extends CommandBase {
} }
// Called repeatedly when this Command is scheduled to run // Called repeatedly when this Command is scheduled to run
protected void execute() { protected void execute() {
driveBase.pidDrive(count,SmartDashboard.getNumber("GyroCorrection")); driveBase.pidDrive(count, SmartDashboard.getNumber("GyroCorrection"));
} }
// Make this return true when this Command no longer needs to run execute() // Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() { protected boolean isFinished() {

View File

@ -17,9 +17,9 @@ public class DriveBase extends Subsystem {
CANTalon rightMotorTwo = new CANTalon(RobotMap.driveRightMotorTwo); CANTalon rightMotorTwo = new CANTalon(RobotMap.driveRightMotorTwo);
Encoder leftEncoder = new Encoder(RobotMap.driveLeftEncoderA, RobotMap.driveLeftEncoderB, false, Encoder.EncodingType.k4X); Encoder leftEncoder = new Encoder(RobotMap.driveLeftEncoderA, RobotMap.driveLeftEncoderB, false, Encoder.EncodingType.k4X);
AnalogGyro gyro = new AnalogGyro(RobotMap.gyro); AnalogGyro gyro = new AnalogGyro(RobotMap.gyro);
PIDController gyroController = new PIDController(0.07,0.002,0.08, new GyroPIDSource(), new MotorsPIDOutputReversed()); PIDController gyroController = new PIDController(0.07, 0.002, 0.08, new GyroPIDSource(), new MotorsPIDOutputReversed());
PIDController leftEncoderController = new PIDController(0.02, 0.002, 0.017, leftEncoder, new MotorsPIDOutput()); PIDController leftEncoderController = new PIDController(0.02, 0.002, 0.017, leftEncoder, new MotorsPIDOutput());
double encoderGyroCorrection=1; double encoderGyroCorrection = 1;
public void initDefaultCommand() { public void initDefaultCommand() {
setDefaultCommand(new Drive()); setDefaultCommand(new Drive());
} }
@ -35,40 +35,40 @@ public class DriveBase extends Subsystem {
rightMotorOne.set((y + (x + z)) * sensitivity); rightMotorOne.set((y + (x + z)) * sensitivity);
rightMotorTwo.set((y + (x + z)) * sensitivity); rightMotorTwo.set((y + (x + z)) * sensitivity);
} }
public void driveStraight(double y, double correction){ public void driveStraight(double y, double correction) {
SmartDashboard.putNumber("GyroAngle",gyro.getAngle()); SmartDashboard.putNumber("GyroAngle", gyro.getAngle());
leftMotorOne.set((-y + -gyro.getAngle()*correction)); leftMotorOne.set((-y + -gyro.getAngle() * correction));
leftMotorTwo.set((-y + -gyro.getAngle()*correction)); leftMotorTwo.set((-y + -gyro.getAngle() * correction));
rightMotorOne.set((y + -gyro.getAngle()*correction)); rightMotorOne.set((y + -gyro.getAngle() * correction));
rightMotorTwo.set((y + -gyro.getAngle()*correction)); rightMotorTwo.set((y + -gyro.getAngle() * correction));
} }
public void pidDrive(double setpoint, double correction) { public void pidDrive(double setpoint, double correction) {
leftEncoder.reset(); leftEncoder.reset();
leftEncoderController.enable(); leftEncoderController.enable();
leftEncoderController.setSetpoint(setpoint); leftEncoderController.setSetpoint(setpoint);
encoderGyroCorrection=-gyro.getAngle()*correction; encoderGyroCorrection = -gyro.getAngle() * correction;
} }
public void rotateAngle(double angle){ public void rotateAngle(double angle) {
SmartDashboard.putNumber("GyroAngle",gyro.getAngle()); SmartDashboard.putNumber("GyroAngle", gyro.getAngle());
gyroController.enable(); gyroController.enable();
gyroController.setSetpoint(angle); gyroController.setSetpoint(angle);
} }
public PIDController getLeftController() { public PIDController getLeftController() {
return leftEncoderController; return leftEncoderController;
} }
public PIDController getGyroController(){ public PIDController getGyroController() {
return gyroController; return gyroController;
} }
public double getLeftRotations() { public double getLeftRotations() {
return leftEncoder.get(); return leftEncoder.get();
} }
public void resetGyro(){ public void resetGyro() {
gyro.reset(); gyro.reset();
} }
public Encoder getLeftEncoder(){ public Encoder getLeftEncoder() {
return leftEncoder; return leftEncoder;
} }
public AnalogGyro getGyro(){ public AnalogGyro getGyro() {
return gyro; return gyro;
} }
public class MotorsPIDOutput implements PIDOutput { public class MotorsPIDOutput implements PIDOutput {
@ -89,14 +89,14 @@ public class DriveBase extends Subsystem {
rightMotorTwo.pidWrite(output); rightMotorTwo.pidWrite(output);
} }
} }
public class GyroPIDSource implements PIDSource{ public class GyroPIDSource implements PIDSource {
public double pidGet(){ public double pidGet() {
return gyro.getAngle(); return gyro.getAngle();
} }
public PIDSourceType getPIDSourceType(){ public PIDSourceType getPIDSourceType() {
return PIDSourceType.kDisplacement; return PIDSourceType.kDisplacement;
} }
public void setPIDSourceType(PIDSourceType type){ public void setPIDSourceType(PIDSourceType type) {
} }
} }
} }