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..b976dde 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 @@ -21,7 +21,10 @@ public RobotContainer() { } private void configureBindings() { - // TODO: Bind indexForSeconds(1.5) to joystick button 1 + // Bind indexForSeconds(1.5) to joystick button 1 + 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..771c00c 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,21 +5,25 @@ package frc.robot.subsystems; 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 +public class Indexer extends SubsystemBase { + // Add indexing state variable here + private boolean indexing = false; /** Creates a new Indexer subsystem. */ public Indexer() {} /** Starts the indexing process. */ public void startIndexing() { - // TODO: Set indexing state to true + // Set indexing state to true + indexing = true; } /** Stops the indexing process. */ public void stopIndexing() { - // TODO: Set indexing state to false + // Set indexing state to false + indexing = false; } /** @@ -28,11 +32,16 @@ public void stopIndexing() { * @return true if indexing, false otherwise */ public boolean isIndexing() { - // TODO: Return indexing state - return false; + // Return indexing state + return indexing; } - // TODO: Implement indexForSeconds() command factory + // Implement indexForSeconds() command factory + public Command indexForSeconds(double seconds) { + return run(this::startIndexing) + .withTimeout(seconds) + .andThen(this::stopIndexing); + } @Override public void periodic() {