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

feat: epic Led effects #40

Open
wants to merge 72 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
0d6b4fe
feat: balance lights
ProgrammingSR Mar 25, 2023
01656be
feat: tip colors
ProgrammingSR Mar 25, 2023
3240954
fix: Added override
ProgrammingSR Mar 25, 2023
dc67780
feat: is tipped indicator light
ProgrammingSR Mar 26, 2023
802d90a
fix: LED brightness
ProgrammingSR Mar 26, 2023
9fcc407
fix: comments
ProgrammingSR Mar 26, 2023
a04897f
fix: blink speed
ProgrammingSR Mar 26, 2023
d610057
refactor: removed comments
ProgrammingSR Mar 26, 2023
315fc5e
fix: implemented reset
ProgrammingSR Mar 26, 2023
756f8c6
WIP
ProgrammingSR Mar 26, 2023
bda8b06
feat: LED swipe command
ProgrammingSR Mar 26, 2023
72d0104
feat: LED effects
ProgrammingSR Mar 26, 2023
1e08afa
feat: Switched to effect queue based
ProgrammingSR Mar 26, 2023
320b2e1
Merged from remote
ProgrammingSR Mar 26, 2023
d29cbe4
feat: alternating LEDs
ProgrammingSR Mar 26, 2023
a08fec2
feat: more options for LEDSwipeCommand
ProgrammingSR Mar 26, 2023
df4025b
Merge branch 'LED-effects' of https://github.com/SaintsRobotics/Charg…
ProgrammingSR Mar 26, 2023
646f91f
Merge branch 'LED-effects' of https://github.com/SaintsRobotics/Charg…
ProgrammingSR Mar 26, 2023
87a3daa
chore: formatting
ProgrammingSR Mar 26, 2023
17bad35
refactor: removed isTipped
ProgrammingSR Mar 28, 2023
dafcde1
feat: added tip command (untested)
ProgrammingSR Mar 28, 2023
f24fe26
fix: update led speed
ProgrammingSR Mar 28, 2023
1888350
fix: tip LEDs work
ProgrammingSR Mar 28, 2023
b3aa3de
feat: robot boot LED sequence
ProgrammingSR Mar 28, 2023
dd836e1
feat: epic LED boot sequence v2.0
LeonardAbbas Mar 28, 2023
ba7b211
cleanup
LeonardAbbas Mar 28, 2023
0d39499
fix: boot sequence
LeonardAbbas Mar 28, 2023
fbb852a
fix: LEDBlinkCommand
LeonardAbbas Mar 28, 2023
b31df08
refactor: removed LEDEffectCommand
LeonardAbbas Mar 28, 2023
be03e30
refactor: startup command
ProgrammingSR Mar 28, 2023
02458d2
refactor: LEDBlinkCommand
ProgrammingSR Mar 28, 2023
86bd1e0
docs
ProgrammingSR Mar 28, 2023
49433a2
feat: random LEDs
ProgrammingSR Mar 29, 2023
fa52058
feat: LED countdown command (very cool)
ProgrammingSR Mar 29, 2023
82a98cd
fix: balance command LEDs
ProgrammingSR Mar 29, 2023
3d82afb
fix: balance command fade
LeonardAbbas Mar 29, 2023
9118e47
fix: small balance command fix
LeonardAbbas Mar 29, 2023
9f5b186
fix: led swipe command
LeonardAbbas Mar 29, 2023
45023b7
refactor: LEDSwipeCommand
LeonardAbbas Mar 29, 2023
10cca47
feat: RGB idle
ProgrammingSR Apr 4, 2023
bb580cb
Merge branch 'main' into LED-effects
ProgrammingSR Apr 4, 2023
cf66318
chore: remove unused command
ProgrammingSR Apr 4, 2023
44117ce
Merge branch 'LED-effects' of https://github.com/SaintsRobotics/Charg…
ProgrammingSR Apr 4, 2023
3523423
chore: rename m_fade
ProgrammingSR Apr 4, 2023
dee1a3a
feat: bumper colors don’t get overridden, WIP
mebrahimaleem Apr 6, 2023
c17e7a7
fix: added missing returns, untested
mebrahimaleem Apr 6, 2023
02a807f
Fix: parenthesis, WIP
mebrahimaleem Apr 6, 2023
cd24f91
fix: imports, WIP
mebrahimaleem Apr 6, 2023
4ae5a03
WIP: implement LED locks
mebrahimaleem Apr 7, 2023
ba256ad
fix: missing new, WIP
mebrahimaleem Apr 7, 2023
c3f1ab8
fix: missing semicolons
mebrahimaleem Apr 7, 2023
269b1a9
feat: lockLED, untested
mebrahimaleem Apr 7, 2023
08370b1
fix: switched from lambda to supplier syntax
mebrahimaleem Apr 7, 2023
0fa3132
fix: renamed symbols
mebrahimaleem Apr 7, 2023
59c24fe
docs: Added more docs
mebrahimaleem Apr 7, 2023
04caa7a
refactor: Moved LED commands to a seperate directory
mebrahimaleem Apr 7, 2023
5073ae9
fix: LED locks noe work
ProgrammingSR Apr 7, 2023
2bbb067
feat: User button toggles idle mode
ProgrammingSR Apr 7, 2023
0a7a4e2
refactor: changed comments
ProgrammingSR Apr 7, 2023
1b579e8
feat: allowed also toggling compressor
ProgrammingSR Apr 7, 2023
cd44ad2
feat: LED notification on coast mode
ProgrammingSR Apr 7, 2023
242e545
fix: LED logic
ProgrammingSR Apr 7, 2023
55a8d0d
merge: user button motor code
ProgrammingSR Apr 7, 2023
7f71876
feat: Added rainbow command option to default
ProgrammingSR Apr 7, 2023
81a4d58
fix: Implemented LED lock for balance command
ProgrammingSR Apr 7, 2023
a9c7869
fix: LED bugs related to scheduling composed cmds
ProgrammingSR Apr 8, 2023
abbbadb
feat: countdown works on sim
ProgrammingSR Apr 8, 2023
71d744e
docs: Added LEDdocs.md
ProgrammingSR Apr 8, 2023
8f97ae3
refactor: Renamed LEDdocs.md to CircutreeDocs.md
ProgrammingSR Apr 8, 2023
8b10903
feat: Forced motor to be on break mode on enable
ProgrammingSR Apr 8, 2023
4fef779
feat: improved random generation
ProgrammingSR Apr 8, 2023
5bf8931
WIP: Raindow swipe
ProgrammingSR Apr 8, 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
3 changes: 3 additions & 0 deletions simgui-ds.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
{
"guid": "78696e70757401000000000000000000",
"useGamepad": true
},
{
"useGamepad": true
}
]
}
38 changes: 35 additions & 3 deletions simgui.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"HALProvider": {
"Addressable LEDs": {
"0": {
"columns": 1,
"start": 1
},
"window": {
"visible": true
}
Expand All @@ -9,6 +13,37 @@
"NTProvider": {
"types": {
"/FMSInfo": "FMSInfo",
"/LiveWindow/DriveSubsystem": "Subsystem",
"/LiveWindow/Ungrouped/DigitalInput[8]": "Digital Input",
"/LiveWindow/Ungrouped/DigitalInput[9]": "Digital Input",
"/LiveWindow/Ungrouped/PIDController[10]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[11]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[12]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[13]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[14]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[15]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[16]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[17]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[18]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[19]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[1]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[20]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[21]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[22]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[23]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[24]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[25]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[26]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[2]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[3]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[4]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[5]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[6]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[7]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[8]": "PIDController",
"/LiveWindow/Ungrouped/PIDController[9]": "PIDController",
"/LiveWindow/Ungrouped/Scheduler": "Scheduler",
"/LiveWindow/Ungrouped/navX-Sensor[4]": "Gyro",
"/SmartDashboard/Field": "Field2d",
"/SmartDashboard/SendableChooser[0]": "String Chooser",
"/SmartDashboard/SendableChooser[1]": "String Chooser"
Expand Down Expand Up @@ -52,8 +87,5 @@
"open": true
}
}
},
"NetworkTables View": {
"visible": false
}
}
15 changes: 12 additions & 3 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public static final class DriveConstants {
new Translation2d(-kWheelBase / 2, -kTrackWidth / 2));

public static final double kMaxSpeedMetersPerSecond = 3.6576;
public static final double kMaxAngularSpeedRadiansPerSecond = 15.24/3;
public static final double kMaxAngularSpeedRadiansPerSecond = 15.24 / 3;

public static final double kTurningStopTime = 0.2; // TODO: tune heading correction stop time
public static final double kTurningStopTime = 0.2;
public static final double kSpeedIncreasePerPeriod = 0.15;

public static final double kPSnapRotate = 6;
Expand Down Expand Up @@ -145,6 +145,15 @@ public static final class GrabberConstants {
public static final class LEDConstants {
public static final int kLEDPort = 0;
public static final int kLEDLength = 28;

public static final double kSwipeTime = 0.02;
public static final double kLEDOnTime = 0.3;

public static final int kBlinkAmount = 3;
public static final double kBlinkTime = 0.2;

public static final double kTipMin = 5;
public static final double kTipMax = 55;
}

public static final class OIConstants {
Expand All @@ -168,7 +177,7 @@ public static final class VisionConstants {
public static final Transform3d kCameraOffset = new Transform3d(new Translation3d(0.5, 0, 0.5),
new Rotation3d(0, 0, 0));
// Currently set as cam mounted facing forward, half a meter forward of center,
// half a meter up from center. // TODO adjust vision offset values
// half a meter up from center.

public static final AprilTagFieldLayout kAprilTagFieldLayout = loadFieldLayout();

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
public class Robot extends TimedRobot {
private Command m_autonomousCommand;
private Command m_startupCommand;
private Command m_idleCommand;

private RobotContainer m_robotContainer;

Expand All @@ -28,6 +30,13 @@ public class Robot extends TimedRobot {
public void robotInit() {
m_robotContainer = new RobotContainer();
m_buttonTimer.start();

m_startupCommand = m_robotContainer.getStartupCommand();
m_idleCommand = m_robotContainer.getIdleCommand();

if (m_startupCommand != null) {
m_startupCommand.schedule();
}
}

@Override
Expand All @@ -37,6 +46,9 @@ public void robotPeriodic() {

@Override
public void disabledInit() {
if (!m_startupCommand.isScheduled() && m_idleCommand != null) {
m_idleCommand.schedule();
}
}

@Override
Expand All @@ -56,6 +68,14 @@ public void autonomousInit() {
if (m_autonomousCommand != null) {
m_autonomousCommand.schedule();
}

if (m_startupCommand != null) {
m_startupCommand.cancel();
}

if (m_idleCommand != null) {
m_idleCommand.cancel();
}
}

@Override
Expand All @@ -67,6 +87,14 @@ public void teleopInit() {
if (m_autonomousCommand != null) {
m_autonomousCommand.cancel();
}

if (m_startupCommand != null) {
m_startupCommand.cancel();
}

if (m_idleCommand != null) {
m_idleCommand.cancel();
}
}

@Override
Expand Down
53 changes: 49 additions & 4 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.pathplanner.lib.auto.SwerveAutoBuilder;

import edu.wpi.first.math.MathUtil;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.XboxController.Button;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
Expand All @@ -23,17 +24,27 @@
import edu.wpi.first.wpilibj2.command.WaitCommand;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
import edu.wpi.first.wpilibj2.command.button.POVButton;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.Constants.ArmConstants;
import frc.robot.Constants.AutonConstants;
import frc.robot.Constants.DriveConstants;
import frc.robot.Constants.OIConstants;
import frc.robot.commands.ArmCommand;
import frc.robot.commands.BalanceCommand;
import frc.robot.commands.LEDBlinkCommand;
import frc.robot.commands.LEDBlinkCommand.BlinkType;
import frc.robot.commands.LEDCountdownCommand;
import frc.robot.commands.LEDDefaultCommand;
import frc.robot.commands.LEDRainbowCommand;
import frc.robot.commands.LEDSwipeCommand;
import frc.robot.commands.LEDSwipeCommand.SwipeType;
import frc.robot.commands.LEDTipCommand;
import frc.robot.commands.SnapRotateCommand;
import frc.robot.subsystems.ArmSubsystem;
import frc.robot.subsystems.DriveSubsystem;
import frc.robot.subsystems.GrabberSubsystem;
import frc.robot.subsystems.LEDSubsystem;
import edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup;

/*
* This class is where the bulk of the robot should be declared. Since Command-based is a
Expand All @@ -51,6 +62,8 @@ public class RobotContainer {
private final XboxController m_operatorController = new XboxController(OIConstants.kOperatorControllerPort);
private final SendableChooser<String> m_chooser = new SendableChooser<>();

private boolean m_lockLED = false;

private final HashMap<String, Command> m_eventMap = new HashMap<>();
private final SwerveAutoBuilder m_autoBuilder = new SwerveAutoBuilder(
m_robotDrive::getPose,
Expand Down Expand Up @@ -110,6 +123,8 @@ public RobotContainer() {
!m_driverController.getRightBumper()),
m_robotDrive));

m_LEDSubsystem.setDefaultCommand(new LEDDefaultCommand(m_LEDSubsystem, () -> m_lockLED));

m_chooser.addOption("Far", "Far");
m_chooser.addOption("Charger", "Charger");
m_chooser.addOption("Charger-comms", "Charger-comms");
Expand All @@ -132,7 +147,7 @@ public RobotContainer() {
new InstantCommand(grabberSubsystem::toggle, grabberSubsystem),
new WaitCommand(0.5)));

m_eventMap.put("Balance", new BalanceCommand(m_robotDrive));
m_eventMap.put("Balance", new BalanceCommand(m_robotDrive, m_LEDSubsystem));
}

/**
Expand All @@ -149,7 +164,7 @@ private void configureButtonBindings() {
.onTrue(new InstantCommand(m_robotDrive::zeroHeading, m_robotDrive));

new JoystickButton(m_driverController, Button.kY.value)
.whileTrue(new BalanceCommand(m_robotDrive));
.whileTrue(new BalanceCommand(m_robotDrive, m_LEDSubsystem));
new JoystickButton(m_driverController, Button.kA.value)
.onTrue(new SnapRotateCommand(m_robotDrive));

Expand All @@ -166,9 +181,15 @@ private void configureButtonBindings() {
.onTrue(new ArmCommand(m_armSubsystem, 34, ArmConstants.kElevatorMinPosition));

new JoystickButton(m_operatorController, Button.kLeftBumper.value)
.onTrue(new InstantCommand(() -> m_LEDSubsystem.setLED(50, 50, 0))); // Yellow
.whileTrue(new RunCommand(() -> m_LEDSubsystem.setCone(), m_LEDSubsystem))
.onFalse(new SequentialCommandGroup(new InstantCommand(() -> {m_lockLED = true;}, m_LEDSubsystem), new WaitCommand(10), new InstantCommand(() -> {m_lockLED = false;}, m_LEDSubsystem)));
new JoystickButton(m_operatorController, Button.kRightBumper.value)
.onTrue(new InstantCommand(() -> m_LEDSubsystem.setLED(27, 8, 44))); // Purple
.whileTrue(new RunCommand(() -> m_LEDSubsystem.setCube(), m_LEDSubsystem))
.onFalse(new SequentialCommandGroup(new InstantCommand(() -> {m_lockLED = true;}, m_LEDSubsystem), new WaitCommand(10), new InstantCommand(() -> {m_lockLED = false;}, m_LEDSubsystem)));

new Trigger(() -> m_robotDrive.isTipped() && !m_lockLED).whileTrue(new LEDTipCommand(m_LEDSubsystem, m_robotDrive.getGyro()));
new Trigger(() -> DriverStation.getMatchTime() < 10 && DriverStation.isTeleop() && !m_lockLED)
.whileTrue(new LEDCountdownCommand(m_LEDSubsystem));
}

/**
Expand All @@ -190,4 +211,28 @@ public Command getAutonomousCommand() {
AutonConstants.maxVelocity - (path.equals("Charger-comms") ? 0.75 : 0),
AutonConstants.maxAcceleration)));
}

/**
* Returns a command that does LED startup effects.
*
* @return Startup command.
*/
public Command getStartupCommand() {
if (m_lockLED) return new SequentialCommandGroup();
return new SequentialCommandGroup(
new LEDSwipeCommand(m_LEDSubsystem, SwipeType.kUp, 0, 0, 100, true),
new LEDBlinkCommand(m_LEDSubsystem, BlinkType.kBlink, 0, 0, 0),
new WaitCommand(5),
new LEDRainbowCommand(m_LEDSubsystem));
}

/**
* Returns RGB idle command.
*
* @return RGB idle command.
*/
public Command getIdleCommand() {
if (m_lockLED) return new SequentialCommandGroup();
return new LEDRainbowCommand(m_LEDSubsystem);
}
}
51 changes: 38 additions & 13 deletions src/main/java/frc/robot/commands/BalanceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,68 @@
package frc.robot.commands;

import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.Constants.DriveConstants;
import frc.robot.subsystems.DriveSubsystem;
import frc.robot.subsystems.LEDSubsystem;

/** Uses a PID and the gyroscope to balance the robot on the charger. */
public class BalanceCommand extends CommandBase {
private final DriveSubsystem m_subsystem;
private final DriveSubsystem m_driveSubsystem;
private final LEDSubsystem m_LEDSubsystem;

private final PIDController m_PID = new PIDController(0.025, 0, 0);
private final Timer m_timer = new Timer();

private boolean m_isRed;
private int m_fade;

/**
* Creates a new {@link BalanceCommand}.
*
* @param subsystem The required subsystem.
* @param driveSubsystem The required drive subsystem.
* @param LEDSubsystem The required LED subsystem.
*/
public BalanceCommand(DriveSubsystem subsystem) {
m_subsystem = subsystem;
addRequirements(m_subsystem);
public BalanceCommand(DriveSubsystem driveSubsystem, LEDSubsystem LEDSubsystem) {
m_driveSubsystem = driveSubsystem;
m_LEDSubsystem = LEDSubsystem;
addRequirements(m_driveSubsystem, m_LEDSubsystem);

m_PID.setTolerance(DriveConstants.kToleranceBalance);
}

@Override
public void initialize() {
m_timer.restart();
m_fade = 100;
m_isRed = true;
m_LEDSubsystem.setLED(100, 0, 0);
}

@Override
public void execute() {
m_subsystem.drive(
m_PID.calculate(m_subsystem.getGyroPitch(), 0),
m_driveSubsystem.drive(
m_PID.calculate(m_driveSubsystem.getGyroPitch(), 0),
0,
0,
false);
}

@Override
public void end(boolean interrupted) {
m_subsystem.drive(0, 0, 0, false);
if (m_PID.atSetpoint()) {
m_LEDSubsystem.setLED(0, m_fade, 0, false);
m_fade = m_fade <= 0 ? 100 : m_fade - 2;
m_isRed = false;
} else if (m_timer.hasElapsed(0.3)) {
m_fade = 100;
m_LEDSubsystem.setLED(m_isRed ? 0 : 100, 0, 0, false);
m_isRed = !m_isRed;
m_timer.reset();
}
}

@Override
public boolean isFinished() {
return false;
public void end(boolean interrupted) {
m_driveSubsystem.drive(0, 0, 0, false);
m_LEDSubsystem.unsetLED();
}
}
Loading