From db128a328a938186c55240b93ca53f442ab10ac7 Mon Sep 17 00:00:00 2001 From: ryan123rudder <42309874+ryan123rudder@users.noreply.github.com> Date: Wed, 11 Mar 2020 20:56:18 -0600 Subject: [PATCH] Added Hood with joy, full manual all programmed but not might not work --- .../java/frc4388/robot/RobotContainer.java | 36 +++++++------ .../commands/shooter/RunHoodWithJoystick.java | 54 +++++++++++++++++++ .../robot/commands/shooter/ShooterManual.java | 45 ++++++++++++++++ .../frc4388/robot/subsystems/ShooterHood.java | 5 ++ .../controller/JoystickManualButton.java | 53 ++++++++++++++++++ .../utility/controller/XboxController.java | 4 ++ 6 files changed, 181 insertions(+), 16 deletions(-) create mode 100644 src/main/java/frc4388/robot/commands/shooter/RunHoodWithJoystick.java create mode 100644 src/main/java/frc4388/robot/commands/shooter/ShooterManual.java create mode 100644 src/main/java/frc4388/utility/controller/JoystickManualButton.java diff --git a/src/main/java/frc4388/robot/RobotContainer.java b/src/main/java/frc4388/robot/RobotContainer.java index 3612c9d..cfd064b 100644 --- a/src/main/java/frc4388/robot/RobotContainer.java +++ b/src/main/java/frc4388/robot/RobotContainer.java @@ -39,9 +39,12 @@ import frc4388.robot.commands.drive.PlaySongDrive; import frc4388.robot.commands.drive.TurnDegrees; import frc4388.robot.commands.intake.RunIntakeWithTriggers; import frc4388.robot.commands.shooter.CalibrateShooter; +import frc4388.robot.commands.shooter.RunHoodWithJoystick; import frc4388.robot.commands.shooter.ShootPrepGroup; import frc4388.robot.commands.shooter.ShooterGoalPosition; +import frc4388.robot.commands.shooter.ShooterManual; import frc4388.robot.commands.shooter.ShooterTrenchPosition; +import frc4388.robot.commands.shooter.ShooterVelocityControlPID; import frc4388.robot.commands.shooter.TrackTarget; import frc4388.robot.commands.shooter.TrimShooter; import frc4388.robot.commands.storage.ManageStorage; @@ -61,6 +64,7 @@ import frc4388.robot.subsystems.Storage; import frc4388.robot.subsystems.Storage.StorageMode; import frc4388.utility.controller.ButtonFox; import frc4388.utility.controller.IHandController; +import frc4388.utility.controller.JoystickManualButton; import frc4388.utility.controller.XboxController; import frc4388.utility.controller.XboxTriggerButton; @@ -90,10 +94,12 @@ public class RobotContainer { private final LimeLight m_robotLime = new LimeLight(); /* Controllers */ - private final XboxController m_driverXbox = new XboxController(OIConstants.XBOX_DRIVER_ID); - private final XboxController m_operatorXbox = new XboxController(OIConstants.XBOX_OPERATOR_ID); - private final XboxController m_buttonFox = new XboxController(OIConstants. BUTTON_FOX_ID); + private static XboxController m_driverXbox = new XboxController(OIConstants.XBOX_DRIVER_ID); + private static XboxController m_operatorXbox = new XboxController(OIConstants.XBOX_OPERATOR_ID); + private static XboxController m_buttonFox = new XboxController(OIConstants. BUTTON_FOX_ID); + private static XboxController m_manualXbox = new XboxController(3); + public static boolean m_isShooterManual = false; /** * The container for the robot. Contains subsystems, OI devices, and commands. @@ -121,6 +127,8 @@ public class RobotContainer { m_robotIntake.setDefaultCommand(new RunIntakeWithTriggers(m_robotIntake, getOperatorController())); // runs the turret with joystick m_robotShooterAim.setDefaultCommand(new RunCommand(() -> m_robotShooterAim.runShooterWithInput(-m_operatorXbox.getLeftXAxis()), m_robotShooterAim)); + // runs the hood with joystick + m_robotShooterHood.setDefaultCommand(new RunHoodWithJoystick(m_robotShooterHood, getOperatorController())); // moves the drum not m_robotShooter.setDefaultCommand(new RunCommand(() -> m_robotShooter.runDrumShooterVelocityPID(1500), m_robotShooter)); // drives climber with input from triggers on the opperator controller @@ -226,23 +234,18 @@ public class RobotContainer { new JoystickButton(getOperatorJoystick(), XboxController.START_BUTTON) .whileHeld(new CalibrateShooter(m_robotShooter, m_robotShooterAim, m_robotShooterHood)); - //Prepares storage for intaking - //new XboxTriggerButton(m_operatorXbox, XboxTriggerButton.LEFT_TRIGGER) - //.whileHeld(new RunCommand(() -> m_robotStorage.runStorage(0.8))) - //.whenReleased(new RunCommand(() -> m_robotStorage.runStorage(0.0))); - //.whileHeld(new StorageIntake(m_robotIntake, m_robotStorage)); - - //Runs storage to outtake - //new XboxTriggerButton(m_operatorXbox, XboxTriggerButton.RIGHT_TRIGGER) - //.whileHeld(new RunCommand(() -> m_robotStorage.runStorage(-0.8))) - //.whenReleased(new RunCommand(() -> m_robotStorage.runStorage(0.0))); //Run drum - new JoystickButton(getOperatorJoystick(), XboxController.B_BUTTON) + new JoystickManualButton(getOperatorJoystick(), XboxController.B_BUTTON, false) .whileHeld(new ShootPrepGroup(m_robotShooter, m_robotShooterAim, m_robotShooterHood, m_robotStorage), false) //.whenReleased(new ManageStorage(m_robotStorage, StorageMode.RESET)) .whenReleased(new InstantCommand(() -> m_robotLime.limeOff())); + //Run drum manual + new JoystickManualButton(getOperatorJoystick(), XboxController.B_BUTTON, true) + .whileHeld(new RunCommand(() -> m_robotShooter.runDrumShooterVelocityPID(10000))) + .whenReleased(new RunCommand(() -> m_robotShooter.runDrumShooterVelocityPID(0))); + @@ -259,8 +262,8 @@ public class RobotContainer { // Shooter Manual new JoystickButton(getButtonFox(), ButtonFox.RIGHT_SWITCH) - .whileHeld(new PlaySongDrive(m_robotDrive)) - .whenReleased(new InterruptSubystem(m_robotDrive)); + .whileHeld(new ShooterManual(true)) + .whenReleased(new ShooterManual(false)); // Goal Shooter Position new JoystickButton(getButtonFox(), ButtonFox.LEFT_BUTTON) @@ -384,6 +387,7 @@ public class RobotContainer { return m_buttonFox; } + /** * Gets the {@link edu.wpi.first.wpilibj.GenericHID#GenericHID(int) Generic HID} for the Operator Xbox Controller. * Generic HIDs/Joysticks can be used to set up JoystickButtons. diff --git a/src/main/java/frc4388/robot/commands/shooter/RunHoodWithJoystick.java b/src/main/java/frc4388/robot/commands/shooter/RunHoodWithJoystick.java new file mode 100644 index 0000000..29ca105 --- /dev/null +++ b/src/main/java/frc4388/robot/commands/shooter/RunHoodWithJoystick.java @@ -0,0 +1,54 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package frc4388.robot.commands.shooter; + +import edu.wpi.first.wpilibj2.command.CommandBase; +import frc4388.robot.subsystems.Leveler; +import frc4388.robot.subsystems.ShooterHood; +import frc4388.utility.controller.IHandController; + +public class RunHoodWithJoystick extends CommandBase { + private ShooterHood m_hood; + private IHandController m_controller; + + /** + * Creates a new RunLevelerWithJoystick to control the leveler with an Xbox controller. + * @param subsystem pass the Hood subsystem from {@link frc4388.robot.RobotContainer#RobotContainer() RobotContainer} + * @param controller pass the Operator {@link frc4388.utility.controller.IHandController#getClass() IHandController} using the + * {@link frc4388.robot.RobotContainer#getOperatorJoystick() getOperatorJoystick()} method in + * {@link frc4388.robot.RobotContainer#RobotContainer() RobotContainer} + */ + public RunHoodWithJoystick(ShooterHood subsystem, IHandController controller) { + m_hood = subsystem; + m_controller = controller; + addRequirements(m_hood); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + double input = m_controller.getRightXAxis(); + m_hood.runHood(input); + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc4388/robot/commands/shooter/ShooterManual.java b/src/main/java/frc4388/robot/commands/shooter/ShooterManual.java new file mode 100644 index 0000000..2017ff4 --- /dev/null +++ b/src/main/java/frc4388/robot/commands/shooter/ShooterManual.java @@ -0,0 +1,45 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package frc4388.robot.commands.shooter; + +import edu.wpi.first.wpilibj.XboxController; +import edu.wpi.first.wpilibj2.command.CommandBase; +import frc4388.robot.RobotContainer; + +public class ShooterManual extends CommandBase { + public boolean isManual = false; + /** + * Creates a new ShooterManual. + */ + public ShooterManual(boolean man) { + isManual = man; + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + RobotContainer.m_isShooterManual = isManual; + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + RobotContainer.m_isShooterManual = isManual; + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc4388/robot/subsystems/ShooterHood.java b/src/main/java/frc4388/robot/subsystems/ShooterHood.java index c177c38..e286a2e 100644 --- a/src/main/java/frc4388/robot/subsystems/ShooterHood.java +++ b/src/main/java/frc4388/robot/subsystems/ShooterHood.java @@ -86,6 +86,11 @@ public class ShooterHood extends SubsystemBase { m_angleAdjustPIDController.setReference(targetAngle, ControlType.kPosition); } + public void runHood(double input) + { + m_angleAdjustMotor.set(input); + } + public void resetGyroAngleAdj(){ m_angleEncoder.setPosition(0); } diff --git a/src/main/java/frc4388/utility/controller/JoystickManualButton.java b/src/main/java/frc4388/utility/controller/JoystickManualButton.java new file mode 100644 index 0000000..6455639 --- /dev/null +++ b/src/main/java/frc4388/utility/controller/JoystickManualButton.java @@ -0,0 +1,53 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package frc4388.utility.controller; + +import edu.wpi.first.wpilibj.GenericHID; +import edu.wpi.first.wpilibj2.command.button.Button; +import frc4388.robot.RobotContainer; + +import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam; + +/** + * A {@link Button} that gets its state from a {@link GenericHID}. + */ +public class JoystickManualButton extends Button { + private final GenericHID m_joystick; + private final int m_buttonNumber; + private boolean m_buttonType; + + /** + * Creates a joystick button for triggering commands. + * + * @param joystick The GenericHID object that has the button (e.g. Joystick, + * KinectStick, etc) + * @param buttonNumber The button number (see + * {@link GenericHID#getRawButton(int) } + */ + public JoystickManualButton(GenericHID joystick, int buttonNumber, boolean buttonType) { + requireNonNullParam(joystick, "joystick", "JoystickButton"); + + m_joystick = joystick; + m_buttonNumber = buttonNumber; + } + + /** + * Gets the value of the joystick button. + * + * @return The value of the joystick button + */ + @Override + public boolean get() { + boolean m = RobotContainer.m_isShooterManual; + if (m_buttonType == m) { + return m_joystick.getRawButton(m_buttonNumber); + } else { + return false; + } + } +} diff --git a/src/main/java/frc4388/utility/controller/XboxController.java b/src/main/java/frc4388/utility/controller/XboxController.java index 4353d1e..38c4736 100644 --- a/src/main/java/frc4388/utility/controller/XboxController.java +++ b/src/main/java/frc4388/utility/controller/XboxController.java @@ -60,6 +60,10 @@ public class XboxController implements IHandController m_stick = new Joystick(portNumber); } + public void setJoystick(Joystick joy) { + m_stick = joy; + } + /** * @return Joystick for Xbox Controller */