From 0860a28536d85cac7b47ee10beaed8ac01b4aba1 Mon Sep 17 00:00:00 2001 From: Ishan Venkataraman Date: Sat, 20 Sep 2025 13:41:51 -0700 Subject: [PATCH 1/2] Ishan Venkataraman complete lesson 3 shooter task --- tasks/java-evaluation/Elevator.class | Bin 0 -> 1553 bytes tasks/java-evaluation/Elevator.java | 43 ++++++++++++++++++ tasks/java-evaluation/Indexer.java | 12 +++++ tasks/lesson3-shooter-task/build.gradle | 2 +- .../src/main/java/frc/robot/Constants.java | 2 +- .../src/main/java/frc/robot/Main.java | 2 +- .../src/main/java/frc/robot/Robot.java | 2 +- .../main/java/frc/robot/RobotContainer.java | 6 ++- .../robot/subsystems/ExampleSubsystem.java | 2 +- .../frc/robot/subsystems/shooter/Shooter.java | 21 ++++++++- .../robot/subsystems/shooter/ShooterIO.java | 2 +- .../subsystems/shooter/ShooterIOSim.java | 8 ++-- .../subsystems/shooter/ShooterIOTalonFX.java | 6 ++- 13 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 tasks/java-evaluation/Elevator.class create mode 100644 tasks/java-evaluation/Elevator.java create mode 100644 tasks/java-evaluation/Indexer.java diff --git a/tasks/java-evaluation/Elevator.class b/tasks/java-evaluation/Elevator.class new file mode 100644 index 0000000000000000000000000000000000000000..1d7baa00b4c29c82227b02b83402825130c47a21 GIT binary patch literal 1553 zcmah}&uaRS6CtrBc;%|CIg-6>9os*J+Is!5-$#zIi{s_q{js=RbSD1GtI% zNep1ngkd9rA%>AHzQfBN_czM-*SADNF$`UEeOE0o3{IEUOjrz~kx@svUb)`jzAu7d zByr4yZ6k&BD^cpZp%N{I0oP~9Ek~ZNEZ6*YN7Ypzc&n0xi4mQDlwo4}NR!f<&M;=< zE#wG@>=3U1gFOgb{~(x!afb1S!fVKuaFle^rf`HOcDRy36321E#7P?k6dA@2(DVgh zFxxtur{VU%M05~X*Waj=)-0T6DBkLYbTm0GSEA`~<$U2u890|LoMA{WMn8f0vLixu zRabe=#w4aFg)bhdnomU#r!@-~7*5w^5bP3KisFWjFO|cc9qzf!IH-jZgS8|HgVSke zsd=+D-o`srY>RJ;s`MLNJ#^J3?Lx(U6>9voQcP!m1s2K-`PE(`O;5;)stCG;OAN_4 zOH+R3XTdOQ;sZ*3P%wj0l}*8rS$2JKuhUu=!75+(NMp3P?s9(mv%^_SYYeHn;*ISU z-j3`|RHy|;w(5=<2AcgUlCoyJ)y>NU1^<@b-#Oo3a^N_=G5p*=81QyrDZR zGlZK-+`^)XCC%Y&hRJ9WB9>f#M{bL9-0qmxMc$y{*=6{?e;|5>F^JpTZ+aq}T$XaX z)2Is>j1ngeLAXOdYD}D5xe@ z7*4(3l-_{2E}X&p^j_$1fF^@p3|c>=zamLSGBNW4>?v&+=4jQ&+H@F~@e%FGlx<*; z^uQm#!Tj_YhF{Pi8S}=1F=sqOHk*Hr2`x|cq(gG{InK@(tS7Jv#!nd4$LC2sIA?Ux zC=`Fjj8;vPsyLU(B??cFCq*u?hZ%sh-y~Rf|F14C7m7b3t!*!owu=jT`|f{kj}N)+ zlUvUC0g1u_nHKl(UKEd@cK1b8nXYmRCulWrj0j0lZ5g`hSy-eU##z$Nz($!)t{{!; zbh?BQEMpX_Wc4}5$Uln^c|5{6zNQ!ITk`x4C-InM7Y=?Q+JD74?9t 5 || floorafter < 1) { + System.out.println("Sorry that is not a valid floor"); + floortrue = false; + } else if (floorafter > floorbefore) { + System.out.println("Going up"); + for (int i = floorbefore; i <= floorafter; i++) { + System.out.println("Floor " + i); + } + + } else if (floorafter == floorbefore) { + System.out.println("That is the same floor"); + } else { + System.out.println("Going down"); + for (int i = floorbefore; i >= floorafter; i--) { + System.out.println("Floor " + i); + } + + } + + if (floortrue) { + floorbefore = floorafter; + } + System.out.println("Elevator initiated at floor "+floorbefore); + floortrue = true; + + } + + } +} + + diff --git a/tasks/java-evaluation/Indexer.java b/tasks/java-evaluation/Indexer.java new file mode 100644 index 0000000..11b386e --- /dev/null +++ b/tasks/java-evaluation/Indexer.java @@ -0,0 +1,12 @@ + + + + + +/*In `Indexer.java`: +- Add a boolean field `indexing` +- Create methods: + - `public void startIndexing()`: set `indexing` to true + - `public void stopIndexing()`: set `indexing` to false + - `public boolean isIndexing()`: return `indexing` +*/ diff --git a/tasks/lesson3-shooter-task/build.gradle b/tasks/lesson3-shooter-task/build.gradle index 48a2abe..dec1c8c 100644 --- a/tasks/lesson3-shooter-task/build.gradle +++ b/tasks/lesson3-shooter-task/build.gradle @@ -101,4 +101,4 @@ wpi.java.configureTestTasks(test) // Configure string concat to always inline compile tasks.withType(JavaCompile) { options.compilerArgs.add '-XDstringConcat=inline' -} +} \ No newline at end of file diff --git a/tasks/lesson3-shooter-task/src/main/java/frc/robot/Constants.java b/tasks/lesson3-shooter-task/src/main/java/frc/robot/Constants.java index c50ba05..e88f060 100644 --- a/tasks/lesson3-shooter-task/src/main/java/frc/robot/Constants.java +++ b/tasks/lesson3-shooter-task/src/main/java/frc/robot/Constants.java @@ -16,4 +16,4 @@ public final class Constants { public static class OperatorConstants { public static final int kDriverControllerPort = 0; } -} +} \ No newline at end of file diff --git a/tasks/lesson3-shooter-task/src/main/java/frc/robot/Main.java b/tasks/lesson3-shooter-task/src/main/java/frc/robot/Main.java index 8776e5d..c5f297a 100644 --- a/tasks/lesson3-shooter-task/src/main/java/frc/robot/Main.java +++ b/tasks/lesson3-shooter-task/src/main/java/frc/robot/Main.java @@ -22,4 +22,4 @@ private Main() {} public static void main(String... args) { RobotBase.startRobot(Robot::new); } -} +} \ No newline at end of file diff --git a/tasks/lesson3-shooter-task/src/main/java/frc/robot/Robot.java b/tasks/lesson3-shooter-task/src/main/java/frc/robot/Robot.java index 4f042c5..a754a3a 100644 --- a/tasks/lesson3-shooter-task/src/main/java/frc/robot/Robot.java +++ b/tasks/lesson3-shooter-task/src/main/java/frc/robot/Robot.java @@ -91,4 +91,4 @@ public void simulationInit() {} /** This function is called periodically whilst in simulation. */ @Override public void simulationPeriodic() {} -} +} \ No newline at end of file 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..3489ce4 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 @@ -11,17 +11,19 @@ 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()); 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) @@ -29,4 +31,4 @@ private void configureBindings() { .onFalse(Commands.run(() -> shooter.stop(), shooter)); */ } -} +} \ No newline at end of file diff --git a/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/ExampleSubsystem.java b/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/ExampleSubsystem.java index 6b375da..a697f95 100644 --- a/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/ExampleSubsystem.java +++ b/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/ExampleSubsystem.java @@ -44,4 +44,4 @@ public void periodic() { public void simulationPeriodic() { // This method will be called once per scheduler run during simulation } -} +} \ No newline at end of file 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..20243a8 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,44 @@ package frc.robot.subsystems.shooter; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc.robot.subsystems.shooter.ShooterIO.ShooterIOInputs; // Main Shooter subsystem logic public class Shooter extends SubsystemBase { // TODO: Add a private field for your ShooterIO instance + private final ShooterIO io; // TODO: Add a private field for your ShooterIOInputs instance and initialize it - + private final ShooterIOInputs ShooterIOInput = new ShooterIOInputs(); // TODO: Create the constructor that takes a ShooterIO instance as a parameter + public Shooter(ShooterIO io) { + this.io = io; + } // public Shooter(ShooterIO 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(ShooterIOInput); + + System.out.println("Shooter RPM: " + ShooterIOInput.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 ShooterIOInput.motorRPM; + } +} \ No newline at end of file diff --git a/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/ShooterIO.java b/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/ShooterIO.java index aa1d720..634fdb3 100644 --- a/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/ShooterIO.java +++ b/tasks/lesson3-shooter-task/src/main/java/frc/robot/subsystems/shooter/ShooterIO.java @@ -15,4 +15,4 @@ class ShooterIOInputs { * @param percent Output percentage from -1.0 to 1.0. */ void setMotorPercentOutput(double percent); -} +} \ No newline at end of file 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..9cf2f48 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 = 0.0; + @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; // } @Override public void setMotorPercentOutput(double percent) { // TODO: Store the given `percent` in your simulated motor percentage field + simulatedMotorPercent = percent; } -} +} \ No newline at end of file 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..79e96f4 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 @@ -26,14 +26,16 @@ public ShooterIOTalonFX() { @Override public void updateInputs(ShooterIOInputs inputs) { // TODO: Read the motor’s velocity (rotations per second) as a double using - // motor.getVelocity().getValueAsDouble() + double motorVelocityRPM = motor.getVelocity().getValueAsDouble(); // TODO: Save the RPM to inputs.motorRPM (convert from rotations per second) + inputs.motorRPM = motorVelocityRPM * 60.0; } @Override public void setMotorPercentOutput(double percent) { // TODO: Use motor.setControl and the dutyCycleOut variable to set the motor’s percent output + motor.setControl(dutyCycleOut.withOutput(percent)); // Tip: Search up documentation for DutyCycleOut methods } -} +} \ No newline at end of file From 687d1357ff714cc53596dd09bf450650f1849efa Mon Sep 17 00:00:00 2001 From: Ishan Venkataraman Date: Sat, 20 Sep 2025 14:38:08 -0700 Subject: [PATCH 2/2] Ishan Venkataraman complete lesson 2 --- tasks/lesson2-indexer-task/build.gradle | 3 +-- .../src/main/java/frc/robot/RobotContainer.java | 1 + .../src/main/java/frc/robot/subsystems/Indexer.java | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tasks/lesson2-indexer-task/build.gradle b/tasks/lesson2-indexer-task/build.gradle index 48a2abe..efbfe11 100644 --- a/tasks/lesson2-indexer-task/build.gradle +++ b/tasks/lesson2-indexer-task/build.gradle @@ -4,8 +4,7 @@ plugins { } java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + } def ROBOT_MAIN_CLASS = "frc.robot.Main" diff --git a/tasks/lesson2-indexer-task/src/main/java/frc/robot/RobotContainer.java b/tasks/lesson2-indexer-task/src/main/java/frc/robot/RobotContainer.java index 1500ca0..6a68404 100644 --- a/tasks/lesson2-indexer-task/src/main/java/frc/robot/RobotContainer.java +++ b/tasks/lesson2-indexer-task/src/main/java/frc/robot/RobotContainer.java @@ -22,6 +22,7 @@ public RobotContainer() { private void configureBindings() { // TODO: Bind indexForSeconds(1.5) to joystick button 1 + joystick.button(1).whileTrue(indexer.indexForSeconds(1.5)); } public Command getAutonomousCommand() { diff --git a/tasks/lesson2-indexer-task/src/main/java/frc/robot/subsystems/Indexer.java b/tasks/lesson2-indexer-task/src/main/java/frc/robot/subsystems/Indexer.java index e89f0e5..f2d6eaf 100644 --- a/tasks/lesson2-indexer-task/src/main/java/frc/robot/subsystems/Indexer.java +++ b/tasks/lesson2-indexer-task/src/main/java/frc/robot/subsystems/Indexer.java @@ -5,9 +5,12 @@ package frc.robot.subsystems; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.Commands; public class Indexer extends SubsystemBase { // TODO: Add indexing state variable here + boolean indexing; /** Creates a new Indexer subsystem. */ public Indexer() {} @@ -15,11 +18,13 @@ public Indexer() {} /** Starts the indexing process. */ public void startIndexing() { // TODO: Set indexing state to true + indexing = true; } /** Stops the indexing process. */ public void stopIndexing() { // TODO: Set indexing state to false + indexing = false; } /** @@ -29,10 +34,14 @@ public void stopIndexing() { */ public boolean isIndexing() { // TODO: Return indexing state - return false; + return indexing; + } // TODO: Implement indexForSeconds() command factory + public Command indexForSeconds(double time) { + return Commands.run(() -> startIndexing()).withTimeout(time).finallyDo(() -> stopIndexing()); + } @Override public void periodic() {