From 979a957f1fcf7c0434bac877a96b065226a5577b Mon Sep 17 00:00:00 2001 From: "Keenan D. Buckley" Date: Sat, 16 Feb 2019 13:16:51 -0700 Subject: [PATCH] Merge in Climber Code Co-Authored-By: ryan123rudder --- .../java/org/usfirst/frc4388/robot/OI.java | 24 +++++---- .../org/usfirst/frc4388/robot/RobotMap.java | 7 ++- .../robot/commands/InitiateClimber.java | 28 +++++++---- .../frc4388/robot/commands/ratchetFlip.java | 49 +++++++++++++++++++ .../robot/commands/setClimberSafety.java | 47 ++++++++++++++++++ 5 files changed, 134 insertions(+), 21 deletions(-) create mode 100644 2019robot/src/main/java/org/usfirst/frc4388/robot/commands/ratchetFlip.java create mode 100644 2019robot/src/main/java/org/usfirst/frc4388/robot/commands/setClimberSafety.java diff --git a/2019robot/src/main/java/org/usfirst/frc4388/robot/OI.java b/2019robot/src/main/java/org/usfirst/frc4388/robot/OI.java index b0da466..9d4c26b 100644 --- a/2019robot/src/main/java/org/usfirst/frc4388/robot/OI.java +++ b/2019robot/src/main/java/org/usfirst/frc4388/robot/OI.java @@ -51,9 +51,6 @@ public class OI */ //JoystickButton endEfector = new JoystickButton(m_operatorXbox.getJoyStick(), XboxController.X_BUTTON); //endEfector.toggleWhenActive(new WristPlacement(true)); - - - JoystickButton liftHatchIntake = new JoystickButton(m_operatorXbox.getJoyStick(), XboxController.RIGHT_BUMPER_BUTTON); liftHatchIntake.whenPressed(new LiftHatchDropBall()); @@ -64,10 +61,14 @@ public class OI liftBallIntake.whenPressed(new LiftBallDropHatch()); - - - // climbUp.whenPressed(new InitiateClimber(true)); - //climbUp.whenReleased(new InitiateClimber(false)); + JoystickButton climbUp = new JoystickButton(m_operatorXbox.getJoyStick(), XboxController.RIGHT_TRIGGER_AXIS); + double speed = m_driverXbox.getRightTriggerAxis(); + climbUp.whenPressed(new InitiateClimber(true, speed)); + climbUp.whenReleased(new InitiateClimber(false, speed)); + + JoystickButton ratchetFlip = new JoystickButton(m_operatorXbox.getJoyStick(), XboxController.RIGHT_TRIGGER_AXIS); + ratchetFlip.whenPressed(new ratchetFlip(true, speed)); + ratchetFlip.whenReleased(new ratchetFlip(false, speed)); JoystickButton shiftUp = new JoystickButton(m_driverXbox.getJoyStick(), XboxController.RIGHT_BUMPER_BUTTON); shiftUp.whenPressed(new DriveSpeedShift(true)); @@ -84,10 +85,13 @@ public class OI openIntake.whenPressed(new IntakePosition(true)); JoystickButton CloseIntake = new JoystickButton(m_operatorXbox.getJoyStick(), XboxController.RIGHT_BUMPER_BUTTON); - CloseIntake.whenPressed(new IntakePosition(false)); + CloseIntake.whenPressed(new IntakePosition(false)); + */ + JoystickButton safteySwitch = new JoystickButton(m_operatorXbox.getJoyStick(), XboxController.START_BUTTON); + safteySwitch.whenPressed(new setClimberSafety(true)); + safteySwitch.whenReleased(new setClimberSafety(false)); - SmartDashboard.putData("PRE GAME!!!!", new PreGame()); - */ + //SmartDashboard.putData("PRE GAME!!!!", new PreGame()); } catch (Exception e) { System.err.println("An error occurred in the OI constructor"); } diff --git a/2019robot/src/main/java/org/usfirst/frc4388/robot/RobotMap.java b/2019robot/src/main/java/org/usfirst/frc4388/robot/RobotMap.java index 64e015f..075c9f6 100644 --- a/2019robot/src/main/java/org/usfirst/frc4388/robot/RobotMap.java +++ b/2019robot/src/main/java/org/usfirst/frc4388/robot/RobotMap.java @@ -24,7 +24,12 @@ public class RobotMap { //Elevator Motors public static final int ELEVATOR_MOTOR1_ID = 6; public static final int ELEVATOR_MOTOR2_ID = 7; - public static final int CLIMBER_CAN_ID = 10; + + + //Climber Motors + public static final int CLIMBER_CAN_ID = 11; + public static final int CLIMBER_WHEEL1_ID = 12; + public static final int CLIMBER_WHEEL2_ID = 13; // Pneumatics diff --git a/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/InitiateClimber.java b/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/InitiateClimber.java index 8a6e37d..619fc50 100644 --- a/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/InitiateClimber.java +++ b/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/InitiateClimber.java @@ -1,28 +1,36 @@ package org.usfirst.frc4388.robot.commands; import org.usfirst.frc4388.robot.Robot; +import org.usfirst.frc4388.robot.Constants; import edu.wpi.first.wpilibj.command.Command; public class InitiateClimber extends Command { boolean climb; - - public InitiateClimber(boolean climb) { - this.climb=climb; + double speed; + + public InitiateClimber(boolean climb, double speed) { requires(Robot.climber); + this.climb = climb; + this.speed = speed; } @Override protected void initialize() { - Robot.climber.setClimbSpeed(climb); + } @Override protected void execute() { - } - - // Make this return true when this Command no longer needs to run execute() + if(climb){ //If climb button is pressed + Robot.climber.setClimbSpeed(climb, speed); + } + else{ + Robot.climber.setClimbSpeed(false, 0); + } + } + // Make this return true when this Command no longer needs to run execute() protected boolean isFinished() { return true; } @@ -30,9 +38,9 @@ public class InitiateClimber extends Command // Called once after isFinished returns true protected void end() { } - + @Override protected void interrupted() { - + } -} \ No newline at end of file +} diff --git a/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/ratchetFlip.java b/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/ratchetFlip.java new file mode 100644 index 0000000..8b6dfb9 --- /dev/null +++ b/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/ratchetFlip.java @@ -0,0 +1,49 @@ +package org.usfirst.frc4388.robot.commands; + +import org.usfirst.frc4388.robot.Robot; +import org.usfirst.frc4388.robot.Constants; + +import edu.wpi.first.wpilibj.command.Command; + +public class ratchetFlip extends Command { + boolean flip; + double speed; + public ratchetFlip(boolean flip, double speed) { + requires(Robot.climber); + this.flip = flip; + this.speed = speed; + } + + // Called just before this Command runs the first time + @Override + protected void initialize() { + } + + // Called repeatedly when this Command is scheduled to run + @Override + protected void execute() { + if(flip){ + Robot.climber.flipRatchet(true, speed); + } + else{ + Robot.climber.flipRatchet(false, speed); + } + } + + // Make this return true when this Command no longer needs to run execute() + @Override + protected boolean isFinished() { + return false; + } + + // Called once after isFinished returns true + @Override + protected void end() { + } + + // Called when another command which requires one or more of the same + // subsystems is scheduled to run + @Override + protected void interrupted() { + } +} diff --git a/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/setClimberSafety.java b/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/setClimberSafety.java new file mode 100644 index 0000000..c0e459a --- /dev/null +++ b/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/setClimberSafety.java @@ -0,0 +1,47 @@ +package org.usfirst.frc4388.robot.commands; + +import org.usfirst.frc4388.robot.Robot; +import org.usfirst.frc4388.robot.Constants; + +import edu.wpi.first.wpilibj.command.Command; + +public class setClimberSafety extends Command { + boolean safety; + public setClimberSafety(boolean safety) { + requires(Robot.climber); + this.safety = safety; + } + + // Called just before this Command runs the first time + @Override + protected void initialize() { + } + + // Called repeatedly when this Command is scheduled to run + @Override + protected void execute() { + if(safety){ //If saftey button is pressed + Robot.climber.safetySwitch(true); + } + else{ + Robot.climber.safetySwitch(false); + } + } + + // Make this return true when this Command no longer needs to run execute() + @Override + protected boolean isFinished() { + return false; + } + + // Called once after isFinished returns true + @Override + protected void end() { + } + + // Called when another command which requires one or more of the same + // subsystems is scheduled to run + @Override + protected void interrupted() { + } +}