diff --git a/Prototypes/build.gradle b/Prototypes/build.gradle index 7d5cd54..e0ae565 100644 --- a/Prototypes/build.gradle +++ b/Prototypes/build.gradle @@ -1,6 +1,6 @@ plugins { id "java" - id "edu.wpi.first.GradleRIO" version "2023.4.1" + id "edu.wpi.first.GradleRIO" version "2023.4.2" } sourceCompatibility = JavaVersion.VERSION_11 @@ -110,6 +110,6 @@ repositories { } // AdvantageKit docs say to include this but it breaks the build. -//configurations.all { -// exclude group: "edu.wpi.first.wpilibj" -//} +configurations.all { + exclude group: "edu.wpi.first.wpilibj" +} diff --git a/Prototypes/src/main/java/frc/robot/Robot.java b/Prototypes/src/main/java/frc/robot/Robot.java index 687a0a0..a7fce0d 100644 --- a/Prototypes/src/main/java/frc/robot/Robot.java +++ b/Prototypes/src/main/java/frc/robot/Robot.java @@ -4,9 +4,10 @@ package frc.robot; -import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.CommandScheduler; +import org.littletonrobotics.junction.LoggedRobot; +import org.littletonrobotics.junction.Logger; /** * The VM is configured to automatically run this class, and to call the functions corresponding to @@ -14,7 +15,7 @@ * the package after creating this project, you must also update the build.gradle file in the * project. */ -public class Robot extends TimedRobot { +public class Robot extends LoggedRobot { private Command m_autonomousCommand; private RobotContainer m_robotContainer; diff --git a/Prototypes/src/main/java/frc/robot/RobotContainer.java b/Prototypes/src/main/java/frc/robot/RobotContainer.java index 3824a8b..ef22ea2 100644 --- a/Prototypes/src/main/java/frc/robot/RobotContainer.java +++ b/Prototypes/src/main/java/frc/robot/RobotContainer.java @@ -1,16 +1,12 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - package frc.robot; import frc.robot.Constants.OperatorConstants; -import frc.robot.commands.Autos; -import frc.robot.commands.ExampleCommand; -import frc.robot.subsystems.ExampleSubsystem; +import frc.robot.subsystems.LedSubsystem; +import edu.wpi.first.wpilibj.util.Color; +import edu.wpi.first.wpilibj.util.Color8Bit; import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; -import edu.wpi.first.wpilibj2.command.button.Trigger; /** * This class is where the bulk of the robot should be declared. @@ -18,11 +14,19 @@ public class RobotContainer { // The robot's subsystems and commands are defined here... - private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem(); + private final LedSubsystem ledSubsystem = new LedSubsystem(0, 1, 2); - private final CommandXboxController m_driverController = new CommandXboxController( + private final CommandXboxController driveController = new CommandXboxController( OperatorConstants.DRIVE_CONTROLLER_PORT); + private final Color8Bit red = new Color8Bit(255, 0, 0); + private final Color8Bit green = new Color8Bit(0, 255, 0); + private final Color8Bit blue = new Color8Bit(0, 0, 255); + private final Color8Bit yellow = new Color8Bit(255, 255, 0); + private final Color8Bit cubeColor = new Color8Bit(170, 0, 255); + private final Color8Bit coneColor = new Color8Bit(255, 234, 0); + private final Color8Bit darkRed = new Color8Bit(128,0,0); + /** * The container for the robot. Contains subsystems, OI devices, and commands. */ @@ -37,21 +41,22 @@ public void createSubsystems() { } public void createCommands() { - } /** * Use this method to define your trigger->command mappings. */ private void configureBindings() { - // Schedule `ExampleCommand` when `exampleCondition` changes to `true` - new Trigger(m_exampleSubsystem::exampleCondition) - .onTrue(new ExampleCommand(m_exampleSubsystem)); - // Schedule `exampleMethodCommand` when the Xbox controller's B button is - // pressed, - // cancelling on release. - m_driverController.b().whileTrue(m_exampleSubsystem.exampleMethodCommand()); + driveController.b().onTrue(new InstantCommand(() -> ledSubsystem.setColor(red))); + driveController.a().onTrue(new InstantCommand(() -> ledSubsystem.setColor(green))); + driveController.x().onTrue(new InstantCommand(() -> ledSubsystem.setColor(blue))); + driveController.y().onTrue(new InstantCommand(() -> ledSubsystem.setColor(yellow))); + driveController.rightBumper().onTrue(new InstantCommand(() -> ledSubsystem.setColor(cubeColor))); + driveController.leftBumper().onTrue(new InstantCommand(() -> ledSubsystem.setColor(coneColor))); + + driveController.povLeft().onTrue(new InstantCommand(() -> ledSubsystem.setColor(darkRed))); + driveController.povRight().onTrue(new InstantCommand(() -> ledSubsystem.setColor(red))); } /** @@ -61,6 +66,6 @@ private void configureBindings() { */ public Command getAutonomousCommand() { // An example command will be run in autonomous - return Autos.exampleAuto(m_exampleSubsystem); + return null; } } diff --git a/Prototypes/src/main/java/frc/robot/commands/Autos.java b/Prototypes/src/main/java/frc/robot/commands/Autos.java deleted file mode 100644 index 38345b5..0000000 --- a/Prototypes/src/main/java/frc/robot/commands/Autos.java +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package frc.robot.commands; - -import frc.robot.subsystems.ExampleSubsystem; -import edu.wpi.first.wpilibj2.command.CommandBase; -import edu.wpi.first.wpilibj2.command.Commands; - -public final class Autos { - /** Example static factory for an autonomous command. */ - public static CommandBase exampleAuto(ExampleSubsystem subsystem) { - return Commands.sequence(subsystem.exampleMethodCommand(), new ExampleCommand(subsystem)); - } - - private Autos() { - throw new UnsupportedOperationException("This is a utility class!"); - } -} diff --git a/Prototypes/src/main/java/frc/robot/commands/ExampleCommand.java b/Prototypes/src/main/java/frc/robot/commands/ExampleCommand.java deleted file mode 100644 index 029b6f9..0000000 --- a/Prototypes/src/main/java/frc/robot/commands/ExampleCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package frc.robot.commands; - -import frc.robot.subsystems.ExampleSubsystem; -import edu.wpi.first.wpilibj2.command.CommandBase; - -/** An example command that uses an example subsystem. */ -public class ExampleCommand extends CommandBase { - @SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField", "unused"}) - private final ExampleSubsystem m_subsystem; - - /** - * Creates a new ExampleCommand. - * - * @param subsystem The subsystem used by this command. - */ - public ExampleCommand(ExampleSubsystem subsystem) { - m_subsystem = subsystem; - // Use addRequirements() here to declare subsystem dependencies. - addRequirements(subsystem); - } - - // Called when the command is initially scheduled. - @Override - public void initialize() {} - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() {} - - // Called once the command ends or is interrupted. - @Override - public void end(boolean interrupted) {} - - // Returns true when the command should end. - @Override - public boolean isFinished() { - return false; - } -} diff --git a/Prototypes/src/main/java/frc/robot/subsystems/ExampleSubsystem.java b/Prototypes/src/main/java/frc/robot/subsystems/ExampleSubsystem.java deleted file mode 100644 index 3057963..0000000 --- a/Prototypes/src/main/java/frc/robot/subsystems/ExampleSubsystem.java +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package frc.robot.subsystems; - -import edu.wpi.first.wpilibj2.command.CommandBase; -import edu.wpi.first.wpilibj2.command.SubsystemBase; - -public class ExampleSubsystem extends SubsystemBase { - /** Creates a new ExampleSubsystem. */ - public ExampleSubsystem() {} - - /** - * Example command factory method. - * - * @return a command - */ - public CommandBase exampleMethodCommand() { - // Inline construction of command goes here. - // Subsystem::RunOnce implicitly requires `this` subsystem. - return runOnce( - () -> { - /* one-time action goes here */ - }); - } - - /** - * An example method querying a boolean state of the subsystem (for example, a digital sensor). - * - * @return value of some boolean subsystem state, such as a digital sensor. - */ - public boolean exampleCondition() { - // Query some boolean state, such as a digital sensor. - return false; - } - - @Override - public void periodic() { - // This method will be called once per scheduler run - } - - @Override - public void simulationPeriodic() { - // This method will be called once per scheduler run during simulation - } -} diff --git a/Prototypes/src/main/java/frc/robot/subsystems/LedSubsystem.java b/Prototypes/src/main/java/frc/robot/subsystems/LedSubsystem.java new file mode 100644 index 0000000..9671b1e --- /dev/null +++ b/Prototypes/src/main/java/frc/robot/subsystems/LedSubsystem.java @@ -0,0 +1,35 @@ +package frc.robot.subsystems; + +import edu.wpi.first.wpilibj.DigitalOutput; +import edu.wpi.first.wpilibj.util.Color8Bit; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + + +public class LedSubsystem extends SubsystemBase { + + private final double pwmRateHz = 100.0; + + private DigitalOutput red; + private DigitalOutput green; + private DigitalOutput blue; + + public LedSubsystem(int redChannel, int greenChannel, int blueChannel) { + + red = new DigitalOutput(redChannel); + red.setPWMRate(pwmRateHz); + red.enablePWM(0); + + green = new DigitalOutput(greenChannel); + green.enablePWM(0); + + blue = new DigitalOutput(blueChannel); + blue.enablePWM(0); + } + + public void setColor(Color8Bit color) { + + red.updateDutyCycle((double)color.red / 255.0); + green.updateDutyCycle((double)color.green / 255.0); + blue.updateDutyCycle((double)color.blue / 255.0); + } +}