diff --git a/tasks/lesson2-indexer-task/README.md b/tasks/lesson2-indexer-task/README.md index dca26ae..724d2fb 100644 --- a/tasks/lesson2-indexer-task/README.md +++ b/tasks/lesson2-indexer-task/README.md @@ -41,7 +41,7 @@ This should return a command that: - Bind `indexForSeconds(1.5)` to button 1 on the joystick -## 4. Run and test in simulation +## 4. Run and test in simu8lation - Start your robot in simulation - Switch to teleoperated mode diff --git a/tasks/lesson2-indexer-task/simgui-ds.json b/tasks/lesson2-indexer-task/simgui-ds.json index 69b1a3c..2cec2ca 100644 --- a/tasks/lesson2-indexer-task/simgui-ds.json +++ b/tasks/lesson2-indexer-task/simgui-ds.json @@ -1,4 +1,9 @@ { + "Keyboard 0 Settings": { + "window": { + "visible": true + } + }, "keyboardJoysticks": [ { "axisConfig": [ @@ -20,10 +25,10 @@ "axisCount": 3, "buttonCount": 4, "buttonKeys": [ - 90, - 88, - 67, - 86 + 49, + 50, + 51, + 52 ], "povConfig": [ { 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..441bdac 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 @@ -5,6 +5,7 @@ package frc.robot; import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.InstantCommand; import edu.wpi.first.wpilibj2.command.button.CommandJoystick; import frc.robot.subsystems.Indexer; @@ -15,6 +16,7 @@ public class RobotContainer { // Controller private final CommandJoystick joystick = new CommandJoystick(0); + /** The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { configureBindings(); @@ -22,6 +24,11 @@ public RobotContainer() { private void configureBindings() { // TODO: Bind indexForSeconds(1.5) to joystick button 1 + joystick.button(1).onTrue(indexer.indexForSeconds(1.5)); + + + //joystick.button(1).onTrue(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..0faf005 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 @@ -4,22 +4,26 @@ package frc.robot.subsystems; +import edu.wpi.first.wpilibj2.command.Commands; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import edu.wpi.first.wpilibj2.command.Command; public class Indexer extends SubsystemBase { // TODO: Add indexing state variable here - + boolean indexing = false; /** Creates a new Indexer subsystem. */ 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,11 +33,22 @@ public void stopIndexing() { */ public boolean isIndexing() { // TODO: Return indexing state - return false; + return indexing; } // TODO: Implement indexForSeconds() command factory - + + public Command indexForSeconds(double seconds) { + + return Commands.runOnce(this::startIndexing, this) + + .andThen(Commands.waitSeconds(1.5)) + .andThen(Commands.runOnce(this::stopIndexing, this)); + + + + } + @Override public void periodic() { // This method will always be called once per scheduler run