diff --git a/tasks/java-evaluation/Elevator.class b/tasks/java-evaluation/Elevator.class new file mode 100644 index 0000000..1d7baa0 Binary files /dev/null and b/tasks/java-evaluation/Elevator.class differ diff --git a/tasks/java-evaluation/Elevator.java b/tasks/java-evaluation/Elevator.java new file mode 100644 index 0000000..8539459 --- /dev/null +++ b/tasks/java-evaluation/Elevator.java @@ -0,0 +1,43 @@ +import java.util.Scanner; +public class Elevator { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int floorafter = 1; + int floorbefore = 1; + boolean floortrue = true; + System.out.println("Welcome to the elevator"); + System.out.println("Elevator initiated at floor 1"); + while (true) { + System.out.println("Floor request:"); + floorafter = scan.nextInt(); + if (floorafter > 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/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() { 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