mirror of
https://github.com/Team4388/Robot-Essentials.git
synced 2026-06-09 00:38:01 -06:00
Replaced LED Commands with Inline Commands
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
package frc4388.robot;
|
package frc4388.robot;
|
||||||
|
|
||||||
|
import frc4388.utility.LEDPatterns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
|
* 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
|
* 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 class LEDConstants {
|
||||||
public static final int LED_SPARK_ID = 0;
|
public static final int LED_SPARK_ID = 0;
|
||||||
|
|
||||||
|
public static final LEDPatterns DEFAULT_PATTERN = LEDPatterns.FOREST_WAVES;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class OIConstants {
|
public static final class OIConstants {
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ import edu.wpi.first.wpilibj2.command.InstantCommand;
|
|||||||
import edu.wpi.first.wpilibj2.command.RunCommand;
|
import edu.wpi.first.wpilibj2.command.RunCommand;
|
||||||
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
|
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
|
||||||
import frc4388.robot.Constants.*;
|
import frc4388.robot.Constants.*;
|
||||||
import frc4388.robot.commands.LED.UpdateLED;
|
|
||||||
import frc4388.robot.subsystems.Drive;
|
import frc4388.robot.subsystems.Drive;
|
||||||
import frc4388.robot.subsystems.LED;
|
import frc4388.robot.subsystems.LED;
|
||||||
|
import frc4388.utility.LEDPatterns;
|
||||||
import frc4388.utility.controller.IHandController;
|
import frc4388.utility.controller.IHandController;
|
||||||
import frc4388.utility.controller.XboxController;
|
import frc4388.utility.controller.XboxController;
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ public class RobotContainer {
|
|||||||
getDriverController().getLeftYAxis(),
|
getDriverController().getLeftYAxis(),
|
||||||
getDriverController().getRightXAxis())));
|
getDriverController().getRightXAxis())));
|
||||||
// continually sends updates to the Blinkin LED controller to keep the lights on
|
// 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() {
|
private void configureButtonBindings() {
|
||||||
/* Driver Buttons */
|
/* 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)
|
new JoystickButton(getDriverJoystick(), XboxController.A_BUTTON)
|
||||||
.whileHeld(() -> m_robotDrive.driveWithInput(0, 1));
|
.whileHeld(() -> m_robotDrive.driveWithInput(0, 1));
|
||||||
|
|
||||||
/* Operator Buttons */
|
/* 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -28,7 +28,7 @@ public class LED extends SubsystemBase {
|
|||||||
*/
|
*/
|
||||||
public LED(){
|
public LED(){
|
||||||
LEDController = new Spark(LEDConstants.LED_SPARK_ID);
|
LEDController = new Spark(LEDConstants.LED_SPARK_ID);
|
||||||
setPattern(LEDPatterns.FOREST_WAVES);
|
setPattern(LEDConstants.DEFAULT_PATTERN);
|
||||||
LEDController.set(currentLED);
|
LEDController.set(currentLED);
|
||||||
System.err.println("In the Beginning, there was Joe.\nAnd he said, 'Let there be LEDs.'\nAnd it was good.");
|
System.err.println("In the Beginning, there was Joe.\nAnd he said, 'Let there be LEDs.'\nAnd it was good.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user