-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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.Command; | ||
import frc.robot.Constants.IntakeConstants; | ||
import frc.robot.subsystems.IntakeSubsystem; | ||
import frc.robot.subsystems.LEDSubsystem; | ||
import frc.robot.subsystems.ShooterSubsystem; | ||
|
||
public class DefaultLEDCommand extends Command { | ||
private LEDSubsystem m_ledSubsystem; | ||
private IntakeSubsystem m_intakeSubsystem; | ||
private ShooterSubsystem m_shooterSubsystem; | ||
|
||
private double armSetpoint; | ||
private double shootSpeed; | ||
private int[] rgb = new int[3]; | ||
|
||
/** Creates a new SetLED. */ | ||
public DefaultLEDCommand(LEDSubsystem LED, IntakeSubsystem intake, ShooterSubsystem shooter) { | ||
m_ledSubsystem = LED; | ||
m_intakeSubsystem = intake; | ||
m_shooterSubsystem = shooter; | ||
addRequirements(m_ledSubsystem); | ||
} | ||
|
||
// Called when the command is initially scheduled. | ||
@Override | ||
public void initialize() { | ||
// default color is invalid so the subsystem will set it to rainbow | ||
rgb[0] = 256; | ||
rgb[1] = 256; | ||
rgb[2] = 256; | ||
|
||
armSetpoint = m_intakeSubsystem.getArmPosition(); | ||
if (armSetpoint == IntakeConstants.kIntakeLoweredAngle) { | ||
rgb[0] = 255; | ||
rgb[1] = 0; | ||
rgb[2] = 0; | ||
} else if (armSetpoint == IntakeConstants.kIntakeRaisedAngle && m_intakeSubsystem.haveNote()) { | ||
rgb[0] = 0; | ||
rgb[1] = 0; | ||
rgb[2] = 255; | ||
} | ||
|
||
shootSpeed = m_shooterSubsystem.returnCurrentSpeed(); | ||
if (shootSpeed > 500 && shootSpeed < 1899 * Math.PI) { // if charging up | ||
rgb[0] = 150; | ||
rgb[1] = 150; | ||
rgb[2] = 0; | ||
} else if (shootSpeed > 1899 * Math.PI) { // if the shooter is ready to shoot | ||
rgb[0] = 0; | ||
rgb[1] = 255; | ||
rgb[2] = 0; | ||
} | ||
|
||
m_ledSubsystem.setLED(rgb[0], rgb[1], rgb[2]); | ||
} | ||
|
||
// Called every time the scheduler runs while the command is scheduled. | ||
@Override | ||
public void execute() { | ||
|
||
} | ||
|
||
// 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 true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// 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.subsystems; | ||
|
||
import edu.wpi.first.wpilibj.AddressableLED; | ||
import edu.wpi.first.wpilibj.AddressableLEDBuffer; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.Constants.LEDConstants; | ||
|
||
public class LEDSubsystem extends SubsystemBase { | ||
private final AddressableLED m_LED = new AddressableLED(LEDConstants.kLEDPort); | ||
private final AddressableLEDBuffer m_LEDBuffer = new AddressableLEDBuffer(LEDConstants.kLEDLength); | ||
private int m_rainbowFirstPixelHue = 0; | ||
|
||
/** Creates a new {@link LEDSubsystem}. */ | ||
public LEDSubsystem() { | ||
m_LED.setLength(LEDConstants.kLEDLength); // 29 | ||
m_LED.setData(m_LEDBuffer); | ||
m_LED.start(); | ||
|
||
// Yellow when bot turns on. | ||
setLED(50, 50, 0); | ||
|
||
SmartDashboard.putString("led", m_LEDBuffer.getLED(1).toString()); | ||
} | ||
|
||
/** | ||
* Sets the rgb value for all LEDs. | ||
* | ||
* @param r Red 0-255 | ||
* @param g Green 0-255 | ||
* @param b Blue 0-255 | ||
*/ | ||
public void setLED(int r, int g, int b) { | ||
|
||
// If we get an invalid value just set it to a rainbow | ||
if (r > 255 || b > 255 || g > 255) { | ||
rainbow(); | ||
return; | ||
} | ||
|
||
for (var i = 0; i < LEDConstants.kLEDLength; i++) { | ||
m_LEDBuffer.setRGB(i, r, g, b); | ||
} | ||
m_LED.setData(m_LEDBuffer); | ||
SmartDashboard.putString("led", m_LEDBuffer.getLED(1).toString()); | ||
} | ||
|
||
private void rainbow() { | ||
// For every pixel | ||
for (var i = 0; i < m_LEDBuffer.getLength(); i++) { | ||
// Calculate the hue - hue is easier for rainbows because the color | ||
// shape is a circle so only one value needs to precess | ||
final var hue = (m_rainbowFirstPixelHue + (i * 180 / m_LEDBuffer.getLength())) % 180; | ||
// Set the value | ||
m_LEDBuffer.setHSV(i, hue, 255, 128); | ||
} | ||
// Increase by to make the rainbow "move" | ||
m_rainbowFirstPixelHue += 2; | ||
// Check bounds | ||
m_rainbowFirstPixelHue %= 180; | ||
|
||
m_LED.setData(m_LEDBuffer); | ||
SmartDashboard.putString("led", m_LEDBuffer.getLED(1).toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters