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

led subsystem (WIP) #49

Merged
merged 9 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion src/main/java/org/jmhsrobotics/frc2024/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void robotInit() {
public void setupLogs() {
if (Robot.isSimulation()) {
// Filesystem.getOperatingDirectory().getAbsolutePath().
DataLogManager.start(Filesystem.getOperatingDirectory().getAbsolutePath() + "\\logs");
DataLogManager.start(Filesystem.getOperatingDirectory().getAbsolutePath() + "/logs");
} else {
DataLogManager.start();
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jmhsrobotics/frc2024/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.jmhsrobotics.frc2024.controlBoard.CompControl;
import org.jmhsrobotics.frc2024.controlBoard.ControlBoard;
import org.jmhsrobotics.frc2024.subsystems.LED.LEDSubsystem;
import org.jmhsrobotics.frc2024.subsystems.LED.commands.LEDCommand;
import org.jmhsrobotics.frc2024.subsystems.drive.DriveConstants;
import org.jmhsrobotics.frc2024.subsystems.drive.DriveSubsystem;
import org.jmhsrobotics.frc2024.subsystems.drive.commands.DriveCommand;
Expand Down Expand Up @@ -35,11 +37,14 @@ public class RobotContainer {

private final VisionSubsystem vision = new VisionSubsystem(this.driveSubsystem);

private final LEDSubsystem ledSubsystem = new LEDSubsystem();

private final SendableChooser<Command> autoChooser;

public RobotContainer() {

this.driveSubsystem.setDefaultCommand(new DriveCommand(this.driveSubsystem, this.control));
this.ledSubsystem.setDefaultCommand(new LEDCommand(this.ledSubsystem));
SmartDashboard.putData("Schedular", CommandScheduler.getInstance());
configureBindings();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.jmhsrobotics.frc2024.subsystems.LED;

import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj.RobotBase;
import edu.wpi.first.wpilibj.simulation.AddressableLEDSim;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class LEDSubsystem extends SubsystemBase {
private AddressableLED LED;
m10653 marked this conversation as resolved.
Show resolved Hide resolved
private AddressableLEDBuffer ledBuffer;

private int rainBowPixelHue = 0;
public LEDSubsystem() {
if (RobotBase.isSimulation()) {
initSim();
}

// TODO: find the real port
this.LED = new AddressableLED(9);

// TODO: get the real length
this.ledBuffer = new AddressableLEDBuffer(60);
m10653 marked this conversation as resolved.
Show resolved Hide resolved

this.LED.setLength(this.ledBuffer.getLength());
this.LED.setData(this.ledBuffer);

}

public void startLED() {
this.LED.start();
}

public void endLED() {
this.LED.stop();;
}

public void setRGB(int r, int g, int b) {
for (int i = 0; i < this.ledBuffer.getLength(); i++) {
this.ledBuffer.setRGB(i, r, g, b);
}
this.LED.setData(this.ledBuffer);

}

public void rainBow() {
for (var i = 0; i < this.ledBuffer.getLength(); i++) {
final var hue = (rainBowPixelHue + (i * 180 / this.ledBuffer.getLength())) % 180;
this.ledBuffer.setHSV(i, hue, 225, 128);
}
this.LED.setData(this.ledBuffer);
rainBowPixelHue += 3;

rainBowPixelHue %= 180;
}

private AddressableLEDSim simLEDs;
private void initSim() {
simLEDs = new AddressableLEDSim(LED);
simLEDs.setLength(60);

}

@Override
public void simulationPeriodic() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.jmhsrobotics.frc2024.subsystems.LED.commands;

import org.jmhsrobotics.frc2024.subsystems.LED.LEDSubsystem;

import edu.wpi.first.wpilibj2.command.Command;

public class LEDCommand extends Command {
m10653 marked this conversation as resolved.
Show resolved Hide resolved

private LEDSubsystem ledSubsystem;

public LEDCommand(LEDSubsystem ledSubsystem) {
this.ledSubsystem = ledSubsystem;

addRequirements(this.ledSubsystem);
}

@Override
public void initialize() {
this.ledSubsystem.startLED();

}

@Override
public void execute() {

// create a rainbow effect
// this.ledSubsystem.rainBow();
this.ledSubsystem.setRGB(255, 0, 0);
m10653 marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public boolean isFinished() {
return false;
}

@Override
public void end(boolean interrupted) {
this.ledSubsystem.endLED();
}
}