Skip to content

Commit

Permalink
feat: fix bindings, add led tuning mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rutmanz committed Feb 13, 2024
1 parent 102fd7b commit 0335fe4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/team1540/robot2024/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class Constants {
private static final Mode simMode = Mode.SIM; // Can also be Mode.REPLAY

public static final Mode currentMode = Robot.isReal() ? Mode.REAL : simMode;
public static final int LED_STRIP_PORT_PWM = 1;
public static final int LED_STRIP_PORT_PWM = 9;
public static final int LED_STRIP_LENGTH= 80;
public enum Mode {
/**
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/org/team1540/robot2024/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import org.littletonrobotics.junction.wpilog.WPILOGReader;
import org.littletonrobotics.junction.wpilog.WPILOGWriter;
import org.team1540.robot2024.subsystems.led.*;
import org.team1540.robot2024.subsystems.led.patterns.LedPatternFlame;
import org.team1540.robot2024.subsystems.led.patterns.LedPatternRSLState;
import org.team1540.robot2024.subsystems.led.patterns.LedPatternRainbow;
import org.team1540.robot2024.subsystems.led.patterns.SimpleLedPattern;
import org.team1540.robot2024.util.LoggedTunableNumber;
import org.team1540.robot2024.util.MechanismVisualiser;

/**
Expand All @@ -23,6 +28,10 @@ public class Robot extends LoggedRobot {
private Command autonomousCommand;
private RobotContainer robotContainer;

LoggedTunableNumber led_r = new LoggedTunableNumber("led/r", 0);
LoggedTunableNumber led_g = new LoggedTunableNumber("led/g", 0);
LoggedTunableNumber led_b = new LoggedTunableNumber("led/b", 0);

/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
Expand Down Expand Up @@ -104,8 +113,7 @@ public void robotPeriodic() {
*/
@Override
public void disabledInit() {
robotContainer.leds.setPattern(Leds.Zone.ZONE1, SimpleLedPattern.solid(Color.kBlueViolet));
robotContainer.leds.setPattern(Leds.Zone.ZONE2, SimpleLedPattern.solid(Color.kPaleVioletRed));
robotContainer.leds.setPattern(Leds.Zone.ELEVATOR_BACK, new LedPatternFlame());
}

/**
Expand All @@ -120,7 +128,7 @@ public void disabledPeriodic() {
*/
@Override
public void autonomousInit() {
robotContainer.leds.setPattern(Leds.Zone.ZONE1,SimpleLedPattern.alternating(Color.kBlueViolet, Color.kCrimson));
robotContainer.leds.setPattern(Leds.Zone.ELEVATOR_BACK,LedPatternRSLState.matchingColors());
autonomousCommand = robotContainer.getAutonomousCommand();
// schedule the autonomous command (example)
if (autonomousCommand != null) {
Expand Down Expand Up @@ -164,8 +172,7 @@ public void teleopPeriodic() {
*/
@Override
public void testInit() {
robotContainer.leds.setPattern(Leds.Zone.ZONE1,new LedPatternFlame(82));
robotContainer.leds.setPattern(Leds.Zone.ZONE2,new LedPatternFlame(82));
robotContainer.leds.setPattern(Leds.Zone.ELEVATOR_BACK,new LedPatternRainbow(1));
// Cancels all running commands at the start of test mode.
CommandScheduler.getInstance().cancelAll();
}
Expand All @@ -175,6 +182,7 @@ public void testInit() {
*/
@Override
public void testPeriodic() {
robotContainer.leds.setPattern(Leds.Zone.ELEVATOR_BACK,SimpleLedPattern.solid(new Color(led_r.get(), led_g.get(), led_b.get())));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/team1540/robot2024/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ public RobotContainer() {
}

private void configureLedBindings() {
leds.setFatalPattern(new LedPatternFlame());
leds.setFatalPattern(LedPatternFlame::new);
new Trigger(DriverStation::isDSAttached)
.onTrue(Commands.runOnce(leds::clearFatalPattern)
.ignoringDisable(true))
.onFalse(Commands.runOnce(() -> leds.setFatalPattern(new LedPatternFlame()))
.onFalse(Commands.runOnce(() -> leds.setFatalPattern(LedPatternFlame::new))
.ignoringDisable(true));
}
/**
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/team1540/robot2024/subsystems/led/Leds.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.team1540.robot2024.subsystems.led.patterns.LedPattern;


import java.util.function.Supplier;

import static org.team1540.robot2024.Constants.LED_STRIP_PORT_PWM;

public class Leds extends SubsystemBase {
Expand All @@ -20,8 +22,7 @@ public Leds() {
strip.setData(ledBuffer);
strip.start();

buffers[Zone.ZONE1.ordinal()] = new ZonedAddressableLEDBuffer(ledBuffer, 1, 40, false);
buffers[Zone.ZONE2.ordinal()] = new ZonedAddressableLEDBuffer(ledBuffer, 40, 80, false);
buffers[Zone.ELEVATOR_BACK.ordinal()] = new ZonedAddressableLEDBuffer(ledBuffer, 1, 41, false);
for (int i = 0; i < ZONE_COUNT;i++) {
patterns[i] = new LedTriager();
}
Expand Down Expand Up @@ -50,27 +51,24 @@ public void clearPattern(Zone zone, PatternCriticality criticality) {
patterns[zone.ordinal()].clearPattern(criticality);
}

public void setFatalPattern(LedPattern pattern) {
System.out.println("Setting criticality");
public void setFatalPattern(Supplier<LedPattern> patternSupplier) {
for (int i = 0; i<ZONE_COUNT;i++) {
LedPattern pattern = patternSupplier.get();
patterns[i].addPattern(pattern, PatternCriticality.FATAL);
pattern.setLength(buffers[i].getLength());
}
}

public void clearFatalPattern() {
System.out.println("Clearing criticality");
for (int i = 0; i<ZONE_COUNT;i++) {
patterns[i].clearPattern(PatternCriticality.FATAL);
}

}


private static final int ZONE_COUNT=Zone.values().length;
public enum Zone {
ZONE1,
ZONE2;
ELEVATOR_BACK,
}
static final int CRITICALITY_COUNT=PatternCriticality.values().length;
public enum PatternCriticality {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class LedPatternFlame extends LedPattern {
private static final Random generator = new Random();
private static final boolean reverseDirection = true;
private static final boolean reverseDirection = false;

private final int cooling;
private final int sparking = 123;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.team1540.robot2024.subsystems.led.patterns;

import edu.wpi.first.wpilibj.RobotController;
import edu.wpi.first.wpilibj.util.Color;
import org.team1540.robot2024.subsystems.led.ZonedAddressableLEDBuffer;

public class LedPatternRSLState extends LedPattern {
Expand All @@ -20,4 +21,8 @@ public void apply(ZonedAddressableLEDBuffer buffer) {
b.apply(buffer);
}
}

public static LedPattern matchingColors() {
return new LedPatternRSLState(SimpleLedPattern.solid(new Color(1, 0.1, 0)), SimpleLedPattern.solid(Color.kBlack));
}
}

0 comments on commit 0335fe4

Please sign in to comment.