generated from SciBorgs/Hydrogen
-
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
14 changed files
with
272 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.sciborgs1155.lib; | ||
|
||
import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import java.util.function.DoubleConsumer; | ||
|
||
public class SimpleMotor { | ||
private final DoubleConsumer set; | ||
private final Runnable close; | ||
|
||
public SimpleMotor(DoubleConsumer set, Runnable close) { | ||
this.set = set; | ||
this.close = close; | ||
} | ||
|
||
public static SimpleMotor talon(TalonFX talon, TalonFXConfiguration config) { | ||
FaultLogger.register(talon); | ||
TalonUtils.addMotor(talon); | ||
talon.getConfigurator().apply(config); | ||
return new SimpleMotor(talon::set, talon::close); | ||
} | ||
|
||
public static SimpleMotor none() { | ||
return new SimpleMotor(v -> {}, () -> {}); | ||
} | ||
|
||
public void set(double power) { | ||
set.accept(power); | ||
} | ||
|
||
public void close() { | ||
close.run(); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/org/sciborgs1155/robot/led/LEDConstants.java
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,12 @@ | ||
package org.sciborgs1155.robot.led; | ||
|
||
import static edu.wpi.first.units.Units.Meters; | ||
|
||
import edu.wpi.first.units.measure.Distance; | ||
|
||
public class LEDConstants { | ||
// The length of the LED Strip. | ||
public static final int LED_LENGTH = 64; | ||
// The distance between two LEDs on the LED Strip. | ||
public static final Distance LED_SPACING = Meters.of(0.01); | ||
} |
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,96 @@ | ||
package org.sciborgs1155.robot.led; | ||
|
||
import static edu.wpi.first.units.Units.MetersPerSecond; | ||
import static edu.wpi.first.units.Units.Seconds; | ||
import static org.sciborgs1155.robot.Ports.LEDs.*; | ||
import static org.sciborgs1155.robot.led.LEDConstants.*; | ||
|
||
import edu.wpi.first.wpilibj.AddressableLED; | ||
import edu.wpi.first.wpilibj.AddressableLEDBuffer; | ||
import edu.wpi.first.wpilibj.DriverStation.Alliance; | ||
import edu.wpi.first.wpilibj.LEDPattern; | ||
import edu.wpi.first.wpilibj.RobotController; | ||
import edu.wpi.first.wpilibj.util.Color; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import java.util.Map; | ||
import java.util.function.DoubleSupplier; | ||
import monologue.Logged; | ||
import org.sciborgs1155.robot.Constants; | ||
|
||
public class LEDStrip extends SubsystemBase implements Logged, AutoCloseable { | ||
|
||
private final AddressableLED led = new AddressableLED(LED_PORT); | ||
private final AddressableLEDBuffer buffer; | ||
|
||
public LEDStrip() { | ||
led.setLength(LED_LENGTH); | ||
buffer = new AddressableLEDBuffer(LED_LENGTH); | ||
led.setData(buffer); | ||
led.start(); | ||
} | ||
|
||
/** Rainbow LEDs, scrolling at 0.5 m/s. Very cool. */ | ||
public Command rainbow() { | ||
return set( | ||
LEDPattern.rainbow(225, 225).scrollAtAbsoluteSpeed(MetersPerSecond.of(0.5), LED_SPACING)); | ||
} | ||
|
||
/** | ||
* A gradient of green to yellow LEDs, with an applied mask of how much the elevator is raised. | ||
* | ||
* @param percent A double supplier that supplies the elevator's percent raised. | ||
*/ | ||
public Command elevatorLED(DoubleSupplier percent) { | ||
return set( | ||
LEDPattern.gradient(LEDPattern.GradientType.kDiscontinuous, Color.kGreen, Color.kYellow) | ||
.mask(LEDPattern.progressMaskLayer(percent))); | ||
} | ||
|
||
/** A gradient of green to yellow LEDs, moving at 60 bpm, which synchronizes with many song. */ | ||
public Command music() { | ||
return set( | ||
LEDPattern.gradient(LEDPattern.GradientType.kDiscontinuous, Color.kGreen, Color.kYellow) | ||
.mask( | ||
LEDPattern.progressMaskLayer( | ||
() -> | ||
Math.sin(RobotController.getMeasureTime().in(Seconds) * Math.PI * 2) / 3 | ||
+ 0.5))); | ||
} | ||
|
||
/** A solid yellow green that is scrolled through. */ | ||
public Command scrolling() { | ||
return set( | ||
LEDPattern.solid(Color.kGreenYellow) | ||
.mask( | ||
LEDPattern.steps(Map.of(0, Color.kWhite, 0.5, Color.kBlack)) | ||
.scrollAtAbsoluteSpeed(MetersPerSecond.of(0.5), LED_SPACING))); | ||
} | ||
|
||
/** A breathing gradient that matches the alliance colors. */ | ||
public Command autos() { | ||
if (Constants.alliance() == Alliance.Red) { | ||
return set( | ||
LEDPattern.gradient( | ||
LEDPattern.GradientType.kDiscontinuous, Color.kFirstRed, Color.kOrangeRed) | ||
.breathe(Seconds.of(2))); | ||
} else { | ||
return set( | ||
LEDPattern.gradient(LEDPattern.GradientType.kDiscontinuous, Color.kFirstBlue, Color.kAqua) | ||
.breathe(Seconds.of(2))); | ||
} | ||
} | ||
|
||
public Command set(LEDPattern pattern) { | ||
return run( | ||
() -> { | ||
pattern.applyTo(buffer); | ||
led.setData(buffer); | ||
}); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
led.close(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
src/main/java/org/sciborgs1155/robot/scoral/RealScoral.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.