Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8e70a13
Merge branch 'main' into ShuffleBoardPOC
YuvalRashman Jun 25, 2023
536000e
startingShufflebord
Eytan123123 Jun 25, 2023
ced7460
Init commit
Negbi2 Jun 25, 2023
b89b7a2
Made led subsystem
Negbi2 Jun 25, 2023
ecd0252
upsi dupsi
Negbi2 Jun 25, 2023
68890df
trying shuffle bord
Eytan123123 Jun 25, 2023
b5a2332
CR changes, all aesthetic
Negbi2 Jun 29, 2023
21c1038
Merge remote-tracking branch 'origin/LedSubsystemDemo-Itzhak' into Sh…
Eytan123123 Jul 1, 2023
55a2f71
Merge remote-tracking branch 'origin/SwerveDriveSubsystem' into Shuff…
Eytan123123 Jul 1, 2023
96c7926
Update DriveTrainShuffleBoard.java
Eytan123123 Jul 1, 2023
7b60b6f
starting ShuffleBord
Eytan123123 Jul 1, 2023
dce7ce9
angle, pose, angle Models
Eytan123123 Jul 1, 2023
815aa33
Trying ChangeColor as a check to the go 90d
Eytan123123 Jul 1, 2023
070cf3f
added description
Eytan123123 Jul 2, 2023
0a8ee75
Added a field to know what color the leds currently are
Negbi2 Jul 4, 2023
1b6d0de
Added a method to light the colors in a rainbow pattern, \n since rai…
Negbi2 Jul 4, 2023
cc8ff17
ctrl + alt + L, ctrl + alt + O
Negbi2 Jul 4, 2023
74224b9
git problem fixed
Eytan123123 Jul 4, 2023
5ce2c5c
Merge branch 'LedSubsystemDemo-Itzhak' into ShuffleBoardPOC
Eytan123123 Jul 4, 2023
6ff72c2
added all commends, didn't check yes because leds aren't working and …
Eytan123123 Jul 4, 2023
5269504
trying getCurent Color
Eytan123123 Jul 4, 2023
84a9d59
fixing double B files
Eytan123123 Jul 4, 2023
d2b37e7
change color and rainbow, working! get current NOT
Eytan123123 Jul 4, 2023
9fe1341
fixed rainbow
Negbi2 Jul 6, 2023
f0a0462
made a command to light the leds in a rainbow pattern
Negbi2 Jul 6, 2023
4e7fe77
fixed get current color
Negbi2 Jul 6, 2023
3ff5e24
Merge branch 'LedSubsystemDemo-Itzhak' into ShuffleBoardPOC
Eytan123123 Jul 8, 2023
422f384
fixing GetCurrentColor
Eytan123123 Jul 8, 2023
b4f8f22
Done, truning 90 not working (have told its optional)
Eytan123123 Jul 8, 2023
c439d93
added ColorNull
Eytan123123 Jul 8, 2023
077c92e
Allegedly fixed the problem
Negbi2 Jul 8, 2023
9526f42
getCurrentColor Working - Done
Eytan123123 Jul 8, 2023
b3addf3
limit switch
Gooshon Jul 13, 2023
f345222
limit switch check on disable
killery2201 Jul 14, 2023
8a65f1f
created blink
Eytan123123 Jul 17, 2023
7a9ba9b
Blink ~ hasn't been tested
Eytan123123 Jul 17, 2023
4f5d3be
added Gaming
Eytan123123 Jul 17, 2023
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ gradle-app.setting
# End of https://www.gitignore.io/api/gradle,intellij+all

imgui.ini
.settings/org.eclipse.buildship.core.prefs
.settings/org.eclipse.jdt.core.prefs
.project
.classpath
15 changes: 15 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package frc.robot;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc.robot.commands.Test;
import frc.robot.led.LED;
import frc.robot.led.LEDComponentsImpl;
import frc.robot.robotControl.DeputyOi;
import frc.robot.robotControl.DriverOi;
import frc.robot.subsystems.driveTrain.DriveTrain;
Expand All @@ -10,6 +14,7 @@
import frc.robot.subsystems.driveTrain.features.KeepAngleController;
import frc.robot.subsystems.driveTrain.features.PoseEstimator;
import frc.robot.subsystems.driveTrain.features.SwerveModule;
import sensors.Switch.Switch;

/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
Expand All @@ -20,6 +25,9 @@
public class Robot extends TimedRobot {
private DriverOi driverOi;
private DeputyOi deputyOi;
private DigitalInput toplimitSwitch;



/**
* This function is run when the robot is first started up and should be used for any
Expand All @@ -28,10 +36,12 @@ public class Robot extends TimedRobot {
@Override
public void robotInit() {
DriveTrain.init(new DriveTrainComponentsImpl());
LED.init(new LEDComponentsImpl());
PoseEstimator.init();
KeepAngleController.init();
driverOi = new DriverOi();
deputyOi = new DeputyOi();
toplimitSwitch = new DigitalInput(9);
}

/**
Expand Down Expand Up @@ -59,6 +69,11 @@ public void disabledInit() {

@Override
public void disabledPeriodic() {
if(! toplimitSwitch.get()){
LED.getInstance().setStrip(0,255,0);
}else {
LED.getInstance().setStrip(255,0,0);
}
}

/**
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/frc/robot/commands/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.led.LED;

public class Test extends CommandBase {
private DigitalInput toplimitSwitch;

public Test() {
toplimitSwitch = new DigitalInput(9);
}

@Override
public void execute() {
if(! toplimitSwitch.get()){
LED.getInstance().setStrip(0,255,0);
}else {
LED.getInstance().setStrip(255,0,0);
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/frc/robot/commands/led/Blink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package frc.robot.commands.led;

import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import edu.wpi.first.wpilibj2.command.WaitCommand;
import frc.robot.led.LED;

import static frc.robot.led.LEDConstants.BLACK;

public class Blink extends SequentialCommandGroup {
private int ranTimes = 0;

public Blink(int red, int green, int blue, double blinkDelays, int timesToBlink) {
addCommands
(
new SequentialCommandGroup(
new BlinkOnce(red, green, blue, blinkDelays),
new InstantCommand(() -> ranTimes++)
).repeatedly().until(() -> ranTimes == timesToBlink)
);
}

private class BlinkOnce extends SequentialCommandGroup {

private LED led;

public BlinkOnce(int red, int green, int blue, double blinkDelays) {
led = LED.getInstance();
addRequirements(led);
addCommands(
new InstantCommand(() -> led.setStrip(red, green, blue)),
new WaitCommand(blinkDelays),
new InstantCommand(() -> led.setStrip(BLACK.getRed(), BLACK.getGreen(), BLACK.getBlue())),
new WaitCommand(blinkDelays)
);
}
}
}
26 changes: 26 additions & 0 deletions src/main/java/frc/robot/commands/led/Gaming.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package frc.robot.commands.led;

import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.led.LED;

public class Gaming extends CommandBase {

private LED led;
private int jumps;

public Gaming(int jumps) {
this.led = LED.getInstance();
this.jumps = jumps;
addRequirements(led);
}

@Override
public void execute() {
led.setGaming(jumps);
}

@Override
public void end(boolean interrupted) {
led.setStripOff();
}
}
81 changes: 81 additions & 0 deletions src/main/java/frc/robot/led/LED.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package frc.robot.led;

import static frc.robot.led.LEDConstants.BLACK;
import static frc.robot.led.LEDConstants.MAX_HUE;
import static frc.robot.led.LEDConstants.RAINBOW_INDICATOR;
import static frc.robot.led.LEDConstants.RAINBOW_SATURATION;
import static frc.robot.led.LEDConstants.RAINBOW_VALUE;
import static frc.robot.led.LEDConstants.STRIP_LENGTH;

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

public class LED extends SubsystemBase {

private int red;
private int green;
private int blue;

private final LEDComponents components;

private LED(LEDComponents components) {
this.components = components;
}

public String getCurrentColor() {
return "Red: " + red +
" Green: " + green +
" Blue: " + blue;
}

private void setOneLed(int ledIndex, int red, int green, int blue) {
components.getBuffer().setRGB(ledIndex, red, green, blue);
}

public void setStrip(int red, int green, int blue) {
for (int ledIndex = 0; ledIndex < STRIP_LENGTH; ++ledIndex)
setOneLed(ledIndex, red, green, blue);

this.red = red;
this.blue = blue;
this.green = green;

Update();
}

public void setStripOff() {
setStrip(BLACK.getRed(), BLACK.getGreen(), BLACK.getBlue());
}

public void setGaming(int ledJumps) {
int hue;
int ledOffset = 0;
for (int ledIndex = 0; ledIndex < STRIP_LENGTH; ++ledIndex) {
hue = (ledOffset + (ledIndex * MAX_HUE / STRIP_LENGTH)) % MAX_HUE;

components.getBuffer().setHSV(ledIndex, hue, RAINBOW_SATURATION, RAINBOW_VALUE);
}

ledOffset += ledJumps;
ledOffset %= MAX_HUE;

this.red = RAINBOW_INDICATOR.getRed();
this.green = RAINBOW_INDICATOR.getGreen();
this.blue = RAINBOW_INDICATOR.getBlue();

Update();
}

public void Update() {
components.getStrip().setData(components.getBuffer());
}

private static LED instance;

public static void init(LEDComponents components) {
instance = new LED(components);
}

public static LED getInstance() {
return instance;
}
}
11 changes: 11 additions & 0 deletions src/main/java/frc/robot/led/LEDComponents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package frc.robot.led;

import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;

public interface LEDComponents {

AddressableLED getStrip();

AddressableLEDBuffer getBuffer();
}
34 changes: 34 additions & 0 deletions src/main/java/frc/robot/led/LEDComponentsImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package frc.robot.led;

import static frc.robot.led.LEDConstants.PORT;
import static frc.robot.led.LEDConstants.STRIP_LENGTH;

import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;

public class LEDComponentsImpl implements LEDComponents {

private final AddressableLED Strip;
private final AddressableLEDBuffer Buffer;

public LEDComponentsImpl() {
Strip = new AddressableLED(PORT);
Buffer = new AddressableLEDBuffer(STRIP_LENGTH);


Strip.setLength(STRIP_LENGTH);

Strip.setData(Buffer);
Strip.start();
}

@Override
public AddressableLED getStrip() {
return Strip;
}

@Override
public AddressableLEDBuffer getBuffer() {
return Buffer;
}
}
15 changes: 15 additions & 0 deletions src/main/java/frc/robot/led/LEDConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package frc.robot.led;

import java.awt.Color;

public class LEDConstants {

public static Color BLACK = new Color(0, 0, 0);
public static Color RAINBOW_INDICATOR = new Color(210, 52, 235);

public static final int STRIP_LENGTH = 144;
public static final int PORT = 9;
public static final int RAINBOW_SATURATION = 255;
public static final int RAINBOW_VALUE = 128;
public static final int MAX_HUE = 180;
}
57 changes: 51 additions & 6 deletions src/main/java/frc/robot/logging/DriveTrainShuffleBoard.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,65 @@
package frc.robot.logging;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.PrintCommand;
import frc.robot.commands.driveTrain.MoveByDistance;
import frc.robot.commands.led.Blink;
import frc.robot.commands.led.Gaming;
import frc.robot.subsystems.driveTrain.DriveTrain;
import frc.robot.subsystems.driveTrain.DriveTrainComponents;
import frc.robot.subsystems.driveTrain.features.PoseEstimator;
import frc.robot.subsystems.driveTrain.features.SwerveModule;
import frc.robot.led.LED;

import java.util.function.DoubleSupplier;
import java.util.function.IntSupplier;
import java.util.function.LongSupplier;

public class DriveTrainShuffleBoard {

public DriveTrainShuffleBoard(DriveTrain driveTrain, DriveTrainComponents components) {
private DriveTrain driveTrain;
private ShuffleboardTab tab;

private int red;

ShuffleboardTab tab = Shuffleboard.getTab("Swerve");
public DriveTrainShuffleBoard(DriveTrainComponents components) {
driveTrain = DriveTrain.getInstance();
SwerveModule[] swerveModules = components.getSwerveModules();
tab.addString("Pose",()-> PoseEstimator.getInstance().getPose2d().toString());
tab.addNumber("CurrentModuleAngle", () -> swerveModules[0].getCurrentAbsoluteDeg());
tab.addNumber("cancoderAng", () -> swerveModules[0].getAbsEncDeg() - swerveModules[0].getAngleOffset());}

}
tab = Shuffleboard.getTab("DriveTrain");
tab.addNumber("FL encoderUnits ", () -> swerveModules[0].getAbsEncDeg());
// tab.addNumber("FR encoderUnits ", () -> swerveModules[1].getAbsEncDeg());
// tab.addNumber("BL encoderUnits ", () -> swerveModules[2].getAbsEncDeg());
// tab.addNumber("BR encoderUnits ", () -> swerveModules[3].getAbsEncDeg());

tab.addNumber("FL CurrentModuleAngle", () -> swerveModules[0].getCurrentAbsoluteDeg());
// tab.addNumber("FR CurrentModuleAngle", () -> swerveModules[1].getCurrentAbsoluteDeg());
// tab.addNumber("BL CurrentModuleAngle", () -> swerveModules[2].getCurrentAbsoluteDeg());
// tab.addNumber("BR CurrentModuleAngle", () -> swerveModules[3].getCurrentAbsoluteDeg());

tab.addNumber("Robot's angle", () -> PoseEstimator.getInstance().getHeading().getDegrees());

//tab.add("Turning 90 ",new MoveByDistance(new Pose2d(0, 0, Rotation2d.fromDegrees(90))));
// rotate 90d, (not working)


tab.add("change color Red", new InstantCommand(()-> LED.getInstance().setStrip(255, 0, 0)));
//change color to red
tab.add("change color Rainbow", new InstantCommand(()-> LED.getInstance().setGaming(3)));
//change to rainbow (not working)

tab.addString("get current color", ()-> LED.getInstance().getCurrentColor());
// Get current color

tab.add("change color null", new InstantCommand(()-> LED.getInstance().setStrip(0, 0, 0)));


tab.add("change color Blink", new InstantCommand(()-> new Blink(183,30,190,1.5,5)));
tab.add("change color Gaming", new InstantCommand(()-> new Gaming(3)));
}
}
Loading