From e0478d2f0de0ca91034442c8786d48c4a22e7bb3 Mon Sep 17 00:00:00 2001 From: "Keenan D. Buckley" Date: Sun, 5 Jan 2020 20:47:09 -0700 Subject: [PATCH 1/4] Change GamerMove into an inline command --- .../java/frc4388/robot/RobotContainer.java | 3 +- .../robot/commands/Drive/GamerMove.java | 47 ------------------- 2 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 src/main/java/frc4388/robot/commands/Drive/GamerMove.java diff --git a/src/main/java/frc4388/robot/RobotContainer.java b/src/main/java/frc4388/robot/RobotContainer.java index 9ba1572..4f86d17 100644 --- a/src/main/java/frc4388/robot/RobotContainer.java +++ b/src/main/java/frc4388/robot/RobotContainer.java @@ -13,7 +13,6 @@ import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.button.JoystickButton; import frc4388.robot.Constants.*; import frc4388.robot.commands.Drive.DriveWithJoystick; -import frc4388.robot.commands.Drive.GamerMove; import frc4388.robot.commands.LED.UpdateLED; import frc4388.robot.subsystems.Drive; import frc4388.robot.subsystems.LED; @@ -55,7 +54,7 @@ public class RobotContainer { */ private void configureButtonBindings() { new JoystickButton(getDriverJoystick(), XboxController.A_BUTTON) - .whenPressed(new GamerMove(m_robotDrive)) + .whenPressed(() -> m_robotDrive.driveWithInput(0, 1)) .whenReleased(new DriveWithJoystick(m_robotDrive, getDriverController())); } diff --git a/src/main/java/frc4388/robot/commands/Drive/GamerMove.java b/src/main/java/frc4388/robot/commands/Drive/GamerMove.java deleted file mode 100644 index d42fe4a..0000000 --- a/src/main/java/frc4388/robot/commands/Drive/GamerMove.java +++ /dev/null @@ -1,47 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* 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.Drive; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import frc4388.robot.subsystems.Drive; - -public class GamerMove extends CommandBase { - - private final Drive m_drive; - - /** - * Creates a new GamerMove. - */ - public GamerMove(Drive subsystem) { - m_drive = subsystem; - addRequirements(m_drive); - } - - // 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() { - m_drive.driveWithInput(0, 1); - } - - // 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; - } -} From 732a849a5a136068b548f3ba005c1e7b8450cd6f Mon Sep 17 00:00:00 2001 From: "Keenan D. Buckley" Date: Sun, 5 Jan 2020 21:06:38 -0700 Subject: [PATCH 2/4] Add Documentation to Commands in RobotContainer.java --- src/main/java/frc4388/robot/RobotContainer.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/frc4388/robot/RobotContainer.java b/src/main/java/frc4388/robot/RobotContainer.java index 4406d88..fe2e6c2 100644 --- a/src/main/java/frc4388/robot/RobotContainer.java +++ b/src/main/java/frc4388/robot/RobotContainer.java @@ -43,6 +43,8 @@ public class RobotContainer { /* Default Commands */ m_robotDrive.setDefaultCommand(new DriveWithJoystick(m_robotDrive, getDriverController())); + // drives the robot with a two-axis input from the driver controller + // continually sends updates to the Blinkin LED controller to keep the lights on m_robotLED.setDefaultCommand(new UpdateLED(m_robotLED)); } @@ -53,9 +55,13 @@ public class RobotContainer { * {@link edu.wpi.first.wpilibj2.command.button.JoystickButton}. */ private void configureButtonBindings() { + /* Driver Buttons */ + //Test command to spin the robot while pressing A on the driver controller new JoystickButton(getDriverJoystick(), XboxController.A_BUTTON) .whenPressed(() -> m_robotDrive.driveWithInput(0, 1)) .whenReleased(new DriveWithJoystick(m_robotDrive, getDriverController())); + + /* Operator Buttons */ } /** From 48e2e2238a53e352f87a1bacc59512c57f477f2e Mon Sep 17 00:00:00 2001 From: "Keenan D. Buckley" Date: Sun, 5 Jan 2020 21:07:16 -0700 Subject: [PATCH 3/4] Replaced DriveWithJoystick with Inline Command --- .../java/frc4388/robot/RobotContainer.java | 9 ++-- .../commands/Drive/DriveWithJoystick.java | 52 ------------------- 2 files changed, 5 insertions(+), 56 deletions(-) delete mode 100644 src/main/java/frc4388/robot/commands/Drive/DriveWithJoystick.java diff --git a/src/main/java/frc4388/robot/RobotContainer.java b/src/main/java/frc4388/robot/RobotContainer.java index fe2e6c2..ee3506c 100644 --- a/src/main/java/frc4388/robot/RobotContainer.java +++ b/src/main/java/frc4388/robot/RobotContainer.java @@ -10,9 +10,9 @@ package frc4388.robot; import edu.wpi.first.wpilibj.Joystick; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.InstantCommand; +import edu.wpi.first.wpilibj2.command.RunCommand; import edu.wpi.first.wpilibj2.command.button.JoystickButton; import frc4388.robot.Constants.*; -import frc4388.robot.commands.Drive.DriveWithJoystick; import frc4388.robot.commands.LED.UpdateLED; import frc4388.robot.subsystems.Drive; import frc4388.robot.subsystems.LED; @@ -42,8 +42,10 @@ public class RobotContainer { configureButtonBindings(); /* Default Commands */ - m_robotDrive.setDefaultCommand(new DriveWithJoystick(m_robotDrive, getDriverController())); // drives the robot with a two-axis input from the driver controller + m_robotDrive.setDefaultCommand(new RunCommand(() -> m_robotDrive.driveWithInput( + getDriverController().getLeftYAxis(), + getDriverController().getRightXAxis()))); // continually sends updates to the Blinkin LED controller to keep the lights on m_robotLED.setDefaultCommand(new UpdateLED(m_robotLED)); } @@ -58,8 +60,7 @@ public class RobotContainer { /* Driver Buttons */ //Test command to spin the robot while pressing A on the driver controller new JoystickButton(getDriverJoystick(), XboxController.A_BUTTON) - .whenPressed(() -> m_robotDrive.driveWithInput(0, 1)) - .whenReleased(new DriveWithJoystick(m_robotDrive, getDriverController())); + .whileHeld(() -> m_robotDrive.driveWithInput(0, 1)); /* Operator Buttons */ } diff --git a/src/main/java/frc4388/robot/commands/Drive/DriveWithJoystick.java b/src/main/java/frc4388/robot/commands/Drive/DriveWithJoystick.java deleted file mode 100644 index 04b6870..0000000 --- a/src/main/java/frc4388/robot/commands/Drive/DriveWithJoystick.java +++ /dev/null @@ -1,52 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* 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.Drive; - -import edu.wpi.first.wpilibj2.command.CommandBase; -import frc4388.robot.subsystems.Drive; -import frc4388.utility.controller.IHandController; - -public class DriveWithJoystick extends CommandBase { - - private final Drive m_drive; - private final IHandController m_driverXbox; - public double m_inputMove, m_inputSteer; - - /** - * Creates a new DriveWithJoystick, driving the robot with the given controller - */ - public DriveWithJoystick(Drive subsystem, IHandController controller) { - m_drive = subsystem; - m_driverXbox = controller; - addRequirements(m_drive); - } - - // 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() { - m_inputMove = m_driverXbox.getLeftYAxis(); - m_inputSteer = m_driverXbox.getRightXAxis(); - m_drive.driveWithInput(m_inputMove, m_inputSteer); - } - - // 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; - } -} From 1f35e8831ac4d88727bb6e2d40eda310012617c6 Mon Sep 17 00:00:00 2001 From: "Keenan D. Buckley" Date: Sun, 5 Jan 2020 21:26:49 -0700 Subject: [PATCH 4/4] Replaced LED Commands with Inline Commands --- src/main/java/frc4388/robot/Constants.java | 4 ++ .../java/frc4388/robot/RobotContainer.java | 10 ++-- .../robot/commands/LED/SetLEDPattern.java | 37 --------------- .../frc4388/robot/commands/LED/UpdateLED.java | 47 ------------------- .../java/frc4388/robot/subsystems/LED.java | 2 +- 5 files changed, 12 insertions(+), 88 deletions(-) delete mode 100644 src/main/java/frc4388/robot/commands/LED/SetLEDPattern.java delete mode 100644 src/main/java/frc4388/robot/commands/LED/UpdateLED.java diff --git a/src/main/java/frc4388/robot/Constants.java b/src/main/java/frc4388/robot/Constants.java index d5ab37e..933908d 100644 --- a/src/main/java/frc4388/robot/Constants.java +++ b/src/main/java/frc4388/robot/Constants.java @@ -7,6 +7,8 @@ package frc4388.robot; +import frc4388.utility.LEDPatterns; + /** * The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean * constants. This class should not be used for any other purpose. All constants should be @@ -25,6 +27,8 @@ public final class Constants { public static final class LEDConstants { public static final int LED_SPARK_ID = 0; + + public static final LEDPatterns DEFAULT_PATTERN = LEDPatterns.FOREST_WAVES; } public static final class OIConstants { diff --git a/src/main/java/frc4388/robot/RobotContainer.java b/src/main/java/frc4388/robot/RobotContainer.java index ee3506c..5421acf 100644 --- a/src/main/java/frc4388/robot/RobotContainer.java +++ b/src/main/java/frc4388/robot/RobotContainer.java @@ -13,9 +13,9 @@ import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.RunCommand; import edu.wpi.first.wpilibj2.command.button.JoystickButton; import frc4388.robot.Constants.*; -import frc4388.robot.commands.LED.UpdateLED; import frc4388.robot.subsystems.Drive; import frc4388.robot.subsystems.LED; +import frc4388.utility.LEDPatterns; import frc4388.utility.controller.IHandController; import frc4388.utility.controller.XboxController; @@ -47,7 +47,7 @@ public class RobotContainer { getDriverController().getLeftYAxis(), getDriverController().getRightXAxis()))); // continually sends updates to the Blinkin LED controller to keep the lights on - m_robotLED.setDefaultCommand(new UpdateLED(m_robotLED)); + m_robotLED.setDefaultCommand(new RunCommand(() -> m_robotLED.updateLED())); } /** @@ -58,11 +58,15 @@ public class RobotContainer { */ private void configureButtonBindings() { /* Driver Buttons */ - //Test command to spin the robot while pressing A on the driver controller + // test command to spin the robot while pressing A on the driver controller new JoystickButton(getDriverJoystick(), XboxController.A_BUTTON) .whileHeld(() -> m_robotDrive.driveWithInput(0, 1)); /* Operator Buttons */ + // activates "Lit Mode" + new JoystickButton(getOperatorJoystick(), XboxController.A_BUTTON) + .whenPressed(() -> m_robotLED.setPattern(LEDPatterns.LAVA_RAINBOW)) + .whenReleased(() -> m_robotLED.setPattern(LEDConstants.DEFAULT_PATTERN)); } /** diff --git a/src/main/java/frc4388/robot/commands/LED/SetLEDPattern.java b/src/main/java/frc4388/robot/commands/LED/SetLEDPattern.java deleted file mode 100644 index a7e793e..0000000 --- a/src/main/java/frc4388/robot/commands/LED/SetLEDPattern.java +++ /dev/null @@ -1,37 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* 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.LED; - -import edu.wpi.first.wpilibj2.command.InstantCommand; - -import frc4388.robot.subsystems.LED; -import frc4388.utility.LEDPatterns; - -// NOTE: Consider using this command inline, rather than writing a subclass. For more -// information, see: -// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html -public class SetLEDPattern extends InstantCommand { - - private final LED m_led; - public static LEDPatterns m_pattern; - - /** - * Add your docs here. - */ - public SetLEDPattern(LED subsystem, LEDPatterns pattern) { - m_led = subsystem; - m_pattern = pattern; - addRequirements(m_led); - } - - // Called when the command is initially scheduled. - @Override - public void initialize() { - m_led.setPattern(m_pattern); - } -} diff --git a/src/main/java/frc4388/robot/commands/LED/UpdateLED.java b/src/main/java/frc4388/robot/commands/LED/UpdateLED.java deleted file mode 100644 index 7baab4e..0000000 --- a/src/main/java/frc4388/robot/commands/LED/UpdateLED.java +++ /dev/null @@ -1,47 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* 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.LED; - -import edu.wpi.first.wpilibj2.command.CommandBase; - -import frc4388.robot.subsystems.LED; - -public class UpdateLED extends CommandBase { - - private final LED m_LED; - - /** - * Creates a new UpdateLED that continually runs updateLED in the LED subsystem. - */ - public UpdateLED(LED subsystem) { - m_LED = subsystem; - addRequirements(m_LED); - } - - // 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() { - m_LED.updateLED(); - } - - // 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/subsystems/LED.java b/src/main/java/frc4388/robot/subsystems/LED.java index 1b9008c..a68c124 100644 --- a/src/main/java/frc4388/robot/subsystems/LED.java +++ b/src/main/java/frc4388/robot/subsystems/LED.java @@ -28,7 +28,7 @@ public class LED extends SubsystemBase { */ public LED(){ LEDController = new Spark(LEDConstants.LED_SPARK_ID); - setPattern(LEDPatterns.FOREST_WAVES); + setPattern(LEDConstants.DEFAULT_PATTERN); LEDController.set(currentLED); System.err.println("In the Beginning, there was Joe.\nAnd he said, 'Let there be LEDs.'\nAnd it was good."); }