diff --git a/tasks/lesson3-shooter-task/simgui-ds.json b/tasks/lesson3-shooter-task/simgui-ds.json index 69b1a3c..6b7aa03 100644 --- a/tasks/lesson3-shooter-task/simgui-ds.json +++ b/tasks/lesson3-shooter-task/simgui-ds.json @@ -1,4 +1,14 @@ { + "Joysticks": { + "window": { + "visible": false + } + }, + "System Joysticks": { + "window": { + "visible": false + } + }, "keyboardJoysticks": [ { "axisConfig": [ @@ -92,6 +102,9 @@ "robotJoysticks": [ { "guid": "Keyboard0" + }, + { + "guid": "Keyboard1" } ] } diff --git a/tasks/lesson3-shooter-task/src/main/java/frc/robot/RobotContainer.java b/tasks/lesson3-shooter-task/src/main/java/frc/robot/RobotContainer.java index 4a1f5c7..e92edcb 100644 --- a/tasks/lesson3-shooter-task/src/main/java/frc/robot/RobotContainer.java +++ b/tasks/lesson3-shooter-task/src/main/java/frc/robot/RobotContainer.java @@ -10,23 +10,31 @@ public class RobotContainer { private final CommandJoystick joystick = new CommandJoystick(0); - // private final Shooter shooter; + private final Shooter shooter; public RobotContainer() { // Use real or sim ShooterIO - // shooter = new Shooter(RobotBase.isReal() ? new ShooterIOTalonFX() : new ShooterIOSim()); - + shooter = new Shooter(RobotBase.isReal() ? new ShooterIOTalonFX() : new ShooterIOSim()); + if (!RobotBase.isReal()) { + shooter.spin(0.0);} configureBindings(); } private void configureBindings() { // Example binding: spin shooter at 50% while holding button 1 // Once the shooter is implemented, you should see the motor spinning at 3000rpm when button 1 is held down - /* + /* joystick .button(1) .whileTrue(Commands.run(() -> shooter.spin(0.5), shooter)) .onFalse(Commands.run(() -> shooter.stop(), shooter)); */ + + joystick + .button(1) + .whileTrue(Commands.run(() -> shooter.spin(0.5), shooter)) + .whileFalse(Commands.run(() -> shooter.stop(), shooter)); + + } } diff --git a/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/Shooter.java b/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/Shooter.java index 8e170c4..5c209fd 100644 --- a/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/Shooter.java +++ b/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/Shooter.java @@ -1,27 +1,49 @@ package frc.robot.subsystems.shooter; +import edu.wpi.first.wpilibj.RobotBase; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc.robot.subsystems.shooter.ShooterIO.ShooterIOInputs; +import static edu.wpi.first.units.Units.RPM; +import static edu.wpi.first.units.Units.Percent; // Main Shooter subsystem logic public class Shooter extends SubsystemBase { // TODO: Add a private field for your ShooterIO instance + private ShooterIO io; + // TODO: Add a private field for your ShooterIOInputs instance and initialize it + private ShooterIO.ShooterIOInputs inputs = new ShooterIO.ShooterIOInputs(); // TODO: Create the constructor that takes a ShooterIO instance as a parameter // public Shooter(ShooterIO io) { ... } + public Shooter(ShooterIO io) { + this.io = io; + } + @Override public void periodic() { // This method will be called once per scheduler run // TODO: Call the updateInputs method on your ShooterIO instance + io.updateInputs(inputs); + System.out.println("Current motor RPM: " + inputs.motorRPM); } // TODO: Add a public method to spin the shooter motor at a given percentage output // public void spin(double percent) { ... } + public void spin(double percent) { + io.setMotorPercentOutput(percent); + } // TODO: Add a public method to stop the shooter motor // public void stop() { ... } + public void stop() { + io.setMotorPercentOutput(0.0); + } // TODO: Add a public method to return the current motor RPM // public double getCurrentRPM() { ... } + public double getCurrentRPM() { + return inputs.motorRPM; + } } diff --git a/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/ShooterIOSim.java b/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/ShooterIOSim.java index 5e92fa6..b7680ba 100644 --- a/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/ShooterIOSim.java +++ b/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/ShooterIOSim.java @@ -6,15 +6,17 @@ public class ShooterIOSim implements ShooterIO { private static final double MAX_RPM = 6000.0; // TODO: Add a private field `simulatedMotorPercent` to store the simulated motor percentage + private double simulatedMotorPercent; @Override public void updateInputs(ShooterIOInputs inputs) { // TODO: Simulate motorRPM by multiplying the stored simulatedMotorPercent by the max RPM - inputs.motorRPM = 0.0; // Placeholder - replace 0.0 + inputs.motorRPM = simulatedMotorPercent * MAX_RPM; // Placeholder - replace 0.0 } @Override public void setMotorPercentOutput(double percent) { // TODO: Store the given `percent` in your simulated motor percentage field + simulatedMotorPercent = percent; } } diff --git a/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/ShooterIOTalonFX.java b/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/ShooterIOTalonFX.java index eec4fbb..b01ac53 100644 --- a/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/ShooterIOTalonFX.java +++ b/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/ShooterIOTalonFX.java @@ -27,13 +27,18 @@ public ShooterIOTalonFX() { public void updateInputs(ShooterIOInputs inputs) { // TODO: Read the motor’s velocity (rotations per second) as a double using // motor.getVelocity().getValueAsDouble() - + double rps = motor.getVelocity().getValueAsDouble(); + // TODO: Save the RPM to inputs.motorRPM (convert from rotations per second) + inputs.motorRPM = rps * 60; + + } @Override public void setMotorPercentOutput(double percent) { // TODO: Use motor.setControl and the dutyCycleOut variable to set the motor’s percent output // Tip: Search up documentation for DutyCycleOut methods + motor.setControl(dutyCycleOut.withOutput(percent)); } }