From 74b13a3b9d620f03162ea98160e8849078196f0a Mon Sep 17 00:00:00 2001 From: aarav18 Date: Sat, 12 Mar 2022 19:01:16 -0700 Subject: [PATCH] manual and normal button box switching --- src/main/java/frc4388/robot/Robot.java | 10 +-- .../java/frc4388/robot/RobotContainer.java | 33 +++------- .../robot/commands/RunMiddleSwitch.java | 61 +++++++++++++++++++ 3 files changed, 70 insertions(+), 34 deletions(-) create mode 100644 src/main/java/frc4388/robot/commands/RunMiddleSwitch.java diff --git a/src/main/java/frc4388/robot/Robot.java b/src/main/java/frc4388/robot/Robot.java index 416d090..04a55bc 100644 --- a/src/main/java/frc4388/robot/Robot.java +++ b/src/main/java/frc4388/robot/Robot.java @@ -269,15 +269,7 @@ public class Robot extends TimedRobot { * This function is called periodically during operator control. */ @Override - public void teleopPeriodic() { - boolean robotManual = m_robotContainer.manual; - - if (robotManual) { - m_robotContainer.configureManualButtonBindings(); - } else { - m_robotContainer.configureAutomaticButtonBindings(); - } - } + public void teleopPeriodic() {} @Override public void testInit() { diff --git a/src/main/java/frc4388/robot/RobotContainer.java b/src/main/java/frc4388/robot/RobotContainer.java index df8cd63..d00505f 100644 --- a/src/main/java/frc4388/robot/RobotContainer.java +++ b/src/main/java/frc4388/robot/RobotContainer.java @@ -32,6 +32,7 @@ import java.util.stream.Collectors; import com.ctre.phoenix.motorcontrol.NeutralMode; import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX; import com.diffplug.common.base.Errors; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor; import com.pathplanner.lib.PathPlanner; import com.pathplanner.lib.PathPlannerTrajectory; import com.pathplanner.lib.PathPlannerTrajectory.PathPlannerState; @@ -51,6 +52,7 @@ import edu.wpi.first.wpilibj.Filesystem; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.RobotBase; import edu.wpi.first.wpilibj.XboxController; +import edu.wpi.first.wpilibj.PS4Controller.Button; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.InstantCommand; @@ -63,6 +65,7 @@ import frc4388.robot.Constants.OIConstants; import frc4388.robot.Constants.StorageConstants; import frc4388.robot.Constants.SwerveDriveConstants; import frc4388.robot.commands.AimToCenter; +import frc4388.robot.commands.RunMiddleSwitch; import frc4388.robot.commands.Shoot; import frc4388.robot.commands.TrackTarget; import frc4388.robot.subsystems.BoomBoom; @@ -226,11 +229,6 @@ public class RobotContainer { // .whenPressed(() -> m_robotMap.leftBack.reset()) // .whenPressed(() -> m_robotMap.rightBack.reset()); - - - - - /* Operator Buttons */ // X > Extend Intake @@ -263,7 +261,7 @@ public class RobotContainer { // .whenReleased(new RunCommand(() -> m_robotBoomBoom.runDrumShooter(0.0))); new JoystickButton(getOperatorController(), XboxController.Button.kLeftBumper.value) - .whileHeld(new RunCommand(() -> m_robotStorage.runStorage(-0.9), m_robotStorage)) + .whenPressed(new RunCommand(() -> m_robotStorage.runStorage(-0.9), m_robotStorage)) .whenReleased(new RunCommand(() -> m_robotStorage.runStorage(0.0), m_robotStorage)); new JoystickButton(getOperatorController(), XboxController.Button.kRightBumper.value) @@ -286,7 +284,6 @@ public class RobotContainer { // .whileHeld(new RunCommand(() -> m_robotStorage.runStorage(-StorageConstants.STORAGE_SPEED))) // .whenReleased(new RunCommand(() -> m_robotStorage.runStorage(0.0))); - // A > Shoot with Odo /*new JoystickButton(getOperatorController(), XboxController.Button.kA.value) .whenPressed(new Shoot(m_robotSwerveDrive, m_robotBoomBoom, m_robotTurret, m_robotHood));*/ @@ -297,11 +294,11 @@ public class RobotContainer { /* Button Box Buttons */ new JoystickButton(getButtonFox(), ButtonBox.Button.kLeftSwitch.value) - .whenPressed(new RunCommand(() -> setManual(true))) - .whenReleased(new RunCommand(() -> setManual(false))); + .whileHeld(new RunCommand(() -> RunMiddleSwitch.setManual(true))) + .whenReleased(new RunCommand(() -> RunMiddleSwitch.setManual(false))); - // new JoystickButton(getButtonFox(), ButtonBox.Button.kMiddleSwitch.value) - // .whileHeld(new RunCommand(() -> System.out.println("MiddleSwitch"))); + new JoystickButton(getButtonFox(), ButtonBox.Button.kMiddleSwitch.value) + .whileHeld(new RunMiddleSwitch()); new JoystickButton(getButtonFox(), ButtonBox.Button.kRightSwitch.value) .whileHeld(new RunCommand(() -> System.out.println("RightSwitch"))); @@ -313,20 +310,6 @@ public class RobotContainer { .whileHeld(new RunCommand(() -> System.out.println("RightButton"))); } - public void configureManualButtonBindings() { - - new JoystickButton(getButtonFox(), ButtonBox.Button.kMiddleSwitch.value) - .whileHeld(new RunCommand(() -> System.out.println("MANUAL"))); - - } - - public void configureAutomaticButtonBindings() { - - new JoystickButton(getButtonFox(), ButtonBox.Button.kMiddleSwitch.value) - .whileHeld(new RunCommand(() -> System.out.println("AUTOMATIC"))); - - } - /** * Use this to pass the autonomous command to the main {@link Robot} class. * diff --git a/src/main/java/frc4388/robot/commands/RunMiddleSwitch.java b/src/main/java/frc4388/robot/commands/RunMiddleSwitch.java new file mode 100644 index 0000000..3a61d55 --- /dev/null +++ b/src/main/java/frc4388/robot/commands/RunMiddleSwitch.java @@ -0,0 +1,61 @@ +// 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. + +package frc4388.robot.commands; + +import edu.wpi.first.wpilibj2.command.CommandBase; + +public class RunMiddleSwitch extends CommandBase { + + private static boolean manual = false; + private boolean newManual = false; + private boolean changes = false; + + /** Creates a new RunMiddleSwitch. */ + public RunMiddleSwitch() { + // Use addRequirements() here to declare subsystem dependencies. + } + + // 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() { + + changes = (newManual == manual); + + if (manual) { + printManual(); + } else { + printNormal(); + } + + newManual = manual; + } + + public void printNormal(){ + System.out.println("Normal"); + } + + public void printManual(){ + System.out.println("Manual"); + } + + public static void setManual(boolean set) + { + manual = set; + } + + // 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 changes; + } +}