From 40271c4d04e8b27938bcf81fbbdfd34eaf251f3d Mon Sep 17 00:00:00 2001 From: ryan123rudder <42309874+ryan123rudder@users.noreply.github.com> Date: Tue, 12 Feb 2019 20:35:09 -0700 Subject: [PATCH] safety fixes WIP --- 2019robot/build.gradle | 3 +- .../java/org/usfirst/frc4388/robot/OI.java | 9 ++-- .../robot/commands/InitiateClimber.java | 10 +--- .../robot/commands/setClimberSafety.java | 47 +++++++++++++++++++ .../frc4388/robot/subsystems/Climber.java | 13 +++-- 5 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 2019robot/src/main/java/org/usfirst/frc4388/robot/commands/setClimberSafety.java diff --git a/2019robot/build.gradle b/2019robot/build.gradle index f15e84c..23028c6 100644 --- a/2019robot/build.gradle +++ b/2019robot/build.gradle @@ -1,6 +1,6 @@ plugins { id "java" - id "edu.wpi.first.GradleRIO" version "2019.1.1" + id "edu.wpi.first.GradleRIO" version "2019.2.1" } def ROBOT_MAIN_CLASS = "org.usfirst.frc4388.robot.Main" @@ -50,7 +50,6 @@ dependencies { nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio) nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop) testCompile 'junit:junit:4.12' - compile pathfinder() } // Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar') 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 82c7cfd..d29bbfe 100644 --- a/2019robot/src/main/java/org/usfirst/frc4388/robot/OI.java +++ b/2019robot/src/main/java/org/usfirst/frc4388/robot/OI.java @@ -26,6 +26,7 @@ import jaci.pathfinder.Pathfinder; + public class OI { private static OI instance; @@ -49,7 +50,7 @@ public class OI CarriageEject.whenPressed(new IntakeSetSpeed(Carriage.CUBE_INTAKE_SPEED)); CarriageEject.whenReleased(new IntakeSetSpeed(0.0)); */ - JoystickButton climbUp = new XBoxTriggerButton(m_operatorXbox, XboxController.RIGHT_TRIGGER); + JoystickButton climbUp = new JoystickButton(m_operatorXbox.getJoyStick(), XboxController.RIGHT_TRIGGER_AXIS); float speed = XboxController.RIGHT_TRIGGER_AXIS; climbUp.whenPressed(new InitiateClimber(true, speed)); climbUp.whenReleased(new InitiateClimber(false, speed)); @@ -72,10 +73,10 @@ public class OI CloseIntake.whenPressed(new IntakePosition(false)); */ JoystickButton safteySwitch = new JoystickButton(m_operatorXbox.getJoyStick(), XboxController.START_BUTTON); - safteySwitch.whenPressed(new startSaftey(true)); - safteySwitch.whenReleased(new startSaftey(false)); + 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/commands/InitiateClimber.java b/2019robot/src/main/java/org/usfirst/frc4388/robot/commands/InitiateClimber.java index f899d0d..243dcef 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 @@ -8,27 +8,21 @@ import edu.wpi.first.wpilibj.command.Command; public class InitiateClimber extends Command { boolean climb; - boolean saftey; float speed; - public InitiateClimber(boolean Climb, int speed) { + public InitiateClimber(boolean Climb, float speed) { requires(Robot.climber); this.climb = Climb; this.speed = speed; } - public startSaftey(boolean saftey){ - requires(Robot.climber); - this.saftey = saftey; - } - @Override protected void initialize() { } @Override protected void execute() { - if(climb && saftey){ //If climb and saftey button are pressed + if(climb){ //If climb and saftey button are pressed Robot.climber.setClimbSpeed(climb, speed); } else{ 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..9526aff --- /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){ + 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() { + } +} diff --git a/2019robot/src/main/java/org/usfirst/frc4388/robot/subsystems/Climber.java b/2019robot/src/main/java/org/usfirst/frc4388/robot/subsystems/Climber.java index 533692d..2f6a672 100644 --- a/2019robot/src/main/java/org/usfirst/frc4388/robot/subsystems/Climber.java +++ b/2019robot/src/main/java/org/usfirst/frc4388/robot/subsystems/Climber.java @@ -50,7 +50,7 @@ public class Climber extends Subsystem{ //Limit and Saftey vars LimitSwitchSource limitSwitchSource; SensorCollection isPressed; - boolean safteySwitch; + boolean safetySwitch; public Climber(){ try{ @@ -79,7 +79,8 @@ public class Climber extends Subsystem{ } public void setClimbSpeed(boolean Climb, float speed) { - if (Climb) { + if (Climb && safetySwitch) { + System.out.println("TriggerVal = " + speed); if(isPressed.isFwdLimitSwitchClosed()){ //If back at max height climberBack.set(0); climberFront.set(FRONT_FREQ * speed); @@ -89,14 +90,18 @@ public class Climber extends Subsystem{ climberFront.set(FRONT_FREQ * speed); } } - if (Climb == false) { + if (Climb == false || safetySwitch == false) { climberBack.set(0); climberFront.set(0); } } - public flipRatchet(){ + public void safetySwitch(boolean safetySwitch){ + this.safetySwitch = safetySwitch; + } + + public void flipRatchet(){ //Code to flip out the front arms of the climber WIP } }