Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bling Subsystem and Command #46

Merged
merged 4 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/java/frc/robot/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ else if (RobotBase.isSimulation()) {
*
* ID 0: Competition Robot (Crescendo) (NEEDS UPDATE ON robot.conf)
* ID 1: Simulation of Comp Robot (Crescendo in Simulation)
* ID 2: Poseidon (Charged Up) (NEEDS UPDATE ON robot.conf)
* ID 3: Clutch (Rapid React) (NEEDS UPDATE ON robot.conf)
* ID 2: Beetle (Test robot) (NEEDS UPDATE ON robot.conf)
* ID 3: Poseidon (Charged up) (NEEDS UPDATE ON robot.conf)
**/

/** ADD CONSTANTS BELOW THIS LINE */
Expand Down Expand Up @@ -257,6 +257,9 @@ public static final class AutoConstants {
new TrapezoidProfile.Constraints(
kMaxAngularSpeedRadiansPerSecond, kMaxAngularSpeedRadiansPerSecondSquared);
}
public static final class BlingConstants {
public static int CANDLE = 15;
GabbyGenereux marked this conversation as resolved.
Show resolved Hide resolved
}
public class ArmConfig {
public static final boolean SET_INVERTED = true;
public static final boolean setInvered = true;
Expand Down
171 changes: 171 additions & 0 deletions src/main/java/frc/robot/commands/BlingCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// 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 frc.robot.commands;

import edu.wpi.first.wpilibj2.command.InstantCommand;
import frc.robot.subsystems.BlingSubsystem;
import com.ctre.phoenix.led.FireAnimation;
import com.ctre.phoenix.led.RainbowAnimation;
import com.ctre.phoenix.led.RgbFadeAnimation;
import com.ctre.phoenix.led.StrobeAnimation;

// NOTE: Consider using this command inline, rather than writing a subclass. For more
// information, see:
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html

public class BlingCommand extends InstantCommand {
public enum BlingColour {
DISABLED,
PURPLE,
BLUE,
RED,
YELLOW,
HONEYDEW,
RAINBOW,
FIRE,
RGBFADE,
WHITESTROBE,
REDSTROBE,
YELLOWSTROBE,
BLUESTROBE,
PURPLESTROBE,
}
public BlingSubsystem bling = BlingSubsystem.getINSTANCE();
public BlingColour blingColour;

public BlingCommand(BlingColour colour) {
blingColour = colour;

// Use addRequirements() here to declare subsystem dependencies.
if( bling != null )
addRequirements(bling);

}

// Called when the command is initially scheduled.
@Override
public void initialize() {
if (bling != null)
{
if (blingColour != null) {
bling.setBrightness();
}
switch( blingColour )
{
case DISABLED:
bling.setDisabled();
break;
case PURPLE:
bling.setPurple();
break;
case BLUE:
bling.setBlue();
break;
case RED:
bling.setRed();
break;
case YELLOW:
bling.setYellow();
break;
case HONEYDEW:
bling.setHoneydew();
break;
case RAINBOW:
setRainbow();
break;
case FIRE:
setFire();
break;
case RGBFADE:
setRgbFade();
break;
case WHITESTROBE:
setWhiteStrobe();
break;
case REDSTROBE:
setRedStrobe();
break;
case YELLOWSTROBE:
setYellowStrobe();
break;
case BLUESTROBE:
setBlueStrobe();
break;
case PURPLESTROBE:
setPurpleStrobe();
break;
default:
break;
}
}

}

public void setRainbow() {
// create a rainbow animation:
// - max brightness
// - half speed
// - 64 LEDs
RainbowAnimation rainbowAnim = new RainbowAnimation(1, 0.01, 64);

bling.candle.animate(rainbowAnim);

}

public void setFire()
{
FireAnimation fireAnimation = new FireAnimation(1, 0.000001, 64, 0.8, 0.4);

bling.candle.animate(fireAnimation);
}

public void setWhiteStrobe()
{
StrobeAnimation strobeAnimation = new StrobeAnimation(255, 255, 255, 255, 0.8, 64);

bling.candle.animate(strobeAnimation);
}

public void setPurpleStrobe()
{
StrobeAnimation strobeAnimation = new StrobeAnimation(138, 43, 226, 127, 0.001, 64); //TODO: test all of the rgbw bling values

bling.candle.animate(strobeAnimation);
}

public void setRedStrobe()
{
StrobeAnimation strobeAnimation = new StrobeAnimation(255, 0, 0, 127, 0.001, 64);

bling.candle.animate(strobeAnimation);
}

public void setBlueStrobe()
{
StrobeAnimation strobeAnimation = new StrobeAnimation(0, 0, 255, 127, 0.001, 64);

bling.candle.animate(strobeAnimation);
}

public void setYellowStrobe()
{
StrobeAnimation strobeAnimation = new StrobeAnimation(255, 255, 0, 127, 0.001, 64);

bling.candle.animate(strobeAnimation);
}

public void setRgbFade()
{
RgbFadeAnimation rgbFadeAnimation = new RgbFadeAnimation(0.7, 0.1, 64);

bling.candle.animate(rgbFadeAnimation);
}

@Override
public boolean runsWhenDisabled() {
return true;
}

}
10 changes: 7 additions & 3 deletions src/main/java/frc/robot/robotcontainers/BeetleContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import frc.robot.Robot;
import frc.robot.subsystems.DiffTalonSubsystem;
import frc.robot.commands.ArcadeDrive;
import frc.robot.commands.BlingCommand;
import frc.robot.commands.BlingCommand.BlingColour;
import frc.robot.subsystems.DiffTalonSubsystem;

/**
* This class is where the bulk of the robot should be declared. Since Command-based is a
Expand All @@ -27,15 +29,17 @@ public BeetleContainer() {
configureButtonBindings();
}

/**
/**
* Use this method to define your button->command mappings. Buttons can be created by
* instantiating a {@link GenericHID} or one of its subclasses ({@link
* edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link
* edu.wpi.first.wpilibj2.command.button.JoystickButton}.
*/
private void configureButtonBindings() {
CommandXboxController driver = new CommandXboxController(0);
CommandXboxController operator = new CommandXboxController(1);
CommandXboxController operator = new CommandXboxController(1);

driver.a().onTrue(new BlingCommand(BlingColour.HONEYDEW));

DiffTalonSubsystem.getInstance().setDefaultCommand(
new ArcadeDrive(driver, XboxController.Axis.kLeftY.value, XboxController.Axis.kRightX.value));
Expand Down
98 changes: 98 additions & 0 deletions src/main/java/frc/robot/subsystems/BlingSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*----------------------------------------------------------------------------*/
/* 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 frc.robot.subsystems;
import frc.robot.commands.BlingCommand;
import frc.robot.Config;

import edu.wpi.first.wpilibj2.command.SubsystemBase;
import com.ctre.phoenix.led.CANdle;
import com.ctre.phoenix.led.CANdleConfiguration;
import com.ctre.phoenix.led.CANdle.LEDStripType;

public class BlingSubsystem extends SubsystemBase {

public CANdle candle;
public final double Brightness = 0.5;
private static BlingSubsystem INSTANCE = null;

/**
* Creates a new Bling.
*/
private BlingSubsystem() {
if ( Config.BlingConstants.CANDLE != -1 )
{
candle = new CANdle( Config.BlingConstants.CANDLE );

CANdleConfiguration config = new CANdleConfiguration();
config.stripType = LEDStripType.RGB; // set the strip type to RGB
config.brightnessScalar = Brightness; // dim the LEDs to half brightness

candle.configAllSettings(config);
}
else
{
candle = null;
}

}

public static BlingSubsystem getINSTANCE() {
if ( Config.BlingConstants.CANDLE == -1 )
{
INSTANCE = null;
}
else if ( INSTANCE == null )
{
INSTANCE = new BlingSubsystem();
}

return INSTANCE;
}

public void setBrightness()
{
candle.configBrightnessScalar(Brightness);
}

public void setDisabled()
{
candle.configBrightnessScalar(0.0);
candle.clearAnimation(0);
}

public void setPurple()
{
candle.setLEDs(138, 43, 226);
}

public void setBlue()
{
candle.setLEDs(0, 0, 255);
}

public void setRed()
{
candle.setLEDs(255, 0, 0);
}

public void setHoneydew()
{
candle.setLEDs(240, 255, 240);
}

public void setYellow()
{
candle.setLEDs(255, 255, 0);
}

@Override
public void periodic() {
// This method will be called once per scheduler run

}
}