From d678ceabb6fcc52ac38ab1f7ee43aa5285ecfc7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=AEZach=20Wilke?= <90875734+76842@users.noreply.github.com> Date: Mon, 25 Oct 2021 16:21:50 -0600 Subject: [PATCH] USB edition --- .../java/frc4388/robot/RobotContainer.java | 40 ++++++++--- .../frc4388/robot/commands/ShootYourShot.java | 10 +-- .../frc4388/robot/subsystems/ShootTube.java | 70 +++++++++++++++---- 3 files changed, 88 insertions(+), 32 deletions(-) diff --git a/src/main/java/frc4388/robot/RobotContainer.java b/src/main/java/frc4388/robot/RobotContainer.java index 92bdd18..b113e74 100644 --- a/src/main/java/frc4388/robot/RobotContainer.java +++ b/src/main/java/frc4388/robot/RobotContainer.java @@ -1,3 +1,4 @@ +/* Dumb Command Version, Smart Subsytem Version */ /*----------------------------------------------------------------------------*/ /* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ @@ -15,6 +16,7 @@ import edu.wpi.first.wpilibj2.command.button.JoystickButton; import frc4388.robot.Constants.*; import frc4388.robot.subsystems.Drive; import frc4388.robot.subsystems.Horn; +import frc4388.robot.subsystems.ShootTube; import frc4388.robot.subsystems.LED; import frc4388.utility.LEDPatterns; import frc4388.utility.controller.IHandController; @@ -39,11 +41,7 @@ public class RobotContainer { private final Horn m_robotHorn = new Horn(m_robotMap.HornSolenoid); - /* 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 Solenoid[] tubes = { + private final Solenoid[] SolenoidArray = { m_robotMap.ShooterSolenoid0, m_robotMap.ShooterSolenoid1, m_robotMap.ShooterSolenoid2, @@ -51,7 +49,15 @@ public class RobotContainer { m_robotMap.ShooterSolenoid4, m_robotMap.ShooterSolenoid5, m_robotMap.ShooterSolenoid6, - m_robotMap.ShooterSolenoid7}; + m_robotMap.ShooterSolenoid7 + }; + + private final ShootTube m_robotShooter = new ShootTube(SolenoidArray); + + /* Controllers */ + private final XboxController m_driverXbox = new XboxController(OIConstants.XBOX_DRIVER_ID); + private final XboxController m_operatorXbox = new XboxController(OIConstants.XBOX_OPERATOR_ID); + /** * The container for the robot. Contains subsystems, OI devices, and commands. @@ -87,15 +93,29 @@ public class RobotContainer { .whenPressed(() -> m_robotLED.setPattern(LEDPatterns.LAVA_RAINBOW)) .whenReleased(() -> m_robotLED.setPattern(LEDConstants.DEFAULT_PATTERN)); */ - // Fire horn + /* Fire horn */ new JoystickButton(getOperatorJoystick(), XboxController.LEFT_TRIGGER_AXIS) .whenPressed(() -> m_robotHorn.hornSet(true)) .whenReleased(() -> m_robotHorn.hornSet(false)); + /* Shoot T-Shirt */ new JoystickButton(getOperatorJoystick(), XboxController.RIGHT_TRIGGER_AXIS) - .whenPressed(() -> new ShootYourShot(true)) /*Fire one per once triger*/ - .whenReleased(() -> new ShootYourShot(false)); + .whenPressed(() -> m_robotShooter.ShootTubeSet(true)) + .whenReleased(() -> m_robotShooter.ShootTubeSet(false)); + /* TODO: Check if these binds work */ + /* Cycle Between Solenoids */ + new JoystickButton(getOperatorJoystick(), XboxController.DPAD_LEFT) + .whenPressed(() -> m_robotShooter.CycleDown()); + + new JoystickButton(getOperatorJoystick(), XboxController.DPAD_RIGHT) + .whenPressed(() -> m_robotShooter.CycleUp()); + + /* Fire All of the Solenoids In the Shooter Array */ + /* Extra power. this will be truly worth "I Survived the T Shirt Cannon" T-shirt */ + new JoystickButton(getOperatorJoystick(), XboxController.DPAD_DOWN) + .whenPressed(() -> m_robotShooter.ShootTubeALL(true)) + .whenReleased(() -> m_robotShooter.ShootTubeALL(false)); } @@ -137,4 +157,4 @@ public class RobotContainer { public Joystick getDriverJoystick() { return m_driverXbox.getJoyStick(); } -} +} \ No newline at end of file diff --git a/src/main/java/frc4388/robot/commands/ShootYourShot.java b/src/main/java/frc4388/robot/commands/ShootYourShot.java index 22709f2..cb6b346 100644 --- a/src/main/java/frc4388/robot/commands/ShootYourShot.java +++ b/src/main/java/frc4388/robot/commands/ShootYourShot.java @@ -1,3 +1,4 @@ +/* Dumb Command Version, Smart Subsytem Version */ // Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. @@ -7,14 +8,10 @@ package frc4388.robot.commands; import edu.wpi.first.wpilibj2.command.CommandBase; public class ShootYourShot extends CommandBase { - private Solenoid[] m_solenoids = {}; - private int counter; /** Creates a new ShootYourShot *. */ public ShootYourShot(Solenoid[] solenoids) { - m_solenoids = solenoids; - counter = 0; } // Called when the command is initially scheduled. @@ -24,13 +21,12 @@ public class ShootYourShot extends CommandBase { // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - ShootTube.ShootTubeSet(m_solenoids[counter]); + ShootTube.ShootTubeSet(true); } // Called once the command ends or is interrupted. @Override public void end(boolean interrupted) { - counter += 1; } // Returns true when the command should end. @@ -38,4 +34,4 @@ public class ShootYourShot extends CommandBase { public boolean isFinished() { return false; } -} +} \ No newline at end of file diff --git a/src/main/java/frc4388/robot/subsystems/ShootTube.java b/src/main/java/frc4388/robot/subsystems/ShootTube.java index 65e3f02..8aacebb 100644 --- a/src/main/java/frc4388/robot/subsystems/ShootTube.java +++ b/src/main/java/frc4388/robot/subsystems/ShootTube.java @@ -1,3 +1,4 @@ +/* Dumb Command Version, Smart Subsytem Version */ // Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. @@ -9,18 +10,57 @@ import edu.wpi.first.wpilibj2.command.SubsystemBase; import edu.wpi.first.wbilib.Solnoid; public class ShootTube extends SubsystemBase { - /** Creates a new ShootTube. */ - Solenoid m_solenoids; - public ShootTube(Solenoid[] solenoids) { - m_solenoids = solenoids; - } - - public void ShootTubeSet(boolean arg, Solenoid tube) { - tube.set(arg); - } - - @Override - public void periodic() { - // This method will be called once per scheduler run - } -} + /** Creates a new ShootTube. */ + Solenoid[] m_solenoids; + int m_cycleCount = 0; + int m_maxCount; + public ShootTube(Solenoid[] solenoids) { + m_solenoids = solenoidArray; + m_maxCount = m_solenoids.length; + } + /* + Functions designed for the DPAD left and right buttions to + Cycle the tube to be shooting out of + */ + public void CycleUp() { + m_cycleCount++; + if (m_cycleCount >= m_maxCount || m_cycleCount < 0) { + m_cycleCount = 0; + } + } + public void CycleDown() { + m_cycleCount--; + if (m_cycleCount >= m_maxCount || m_cycleCount < 0) { + m_cycleCount = 0; + } + } + /* + Normal Shoot Tube and Normal Shoot Tube Index Functions + */ + public void ShootTubeSet(Boolean arg) { + m_solenoids[CycleCount].set(arg); + if (arg == false) { + CycleCount++; + if (m_cycleCount >= m_maxCount || m_cycleCount < 0) { + m_cycleCount = 0; + } + } + } + public void ShootTubeIndex(Boolean arg, int i) { + m_solenoids[i].set(arg); + } + /* + Just Normal Shoot Tube But it Shoots all of the tubes + Designed for DPAD Down + */ + public void ShootTubeALL(Boolean arg) { + for (Solenoid x : m_solenoids) { + x.set(arg); + } + m_cycleCount = 0; + } + @Override + public void periodic() { + // This method will be called once per scheduler run + } +} \ No newline at end of file