Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tasks/lesson2-indexer-task/simgui-ds.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"Keyboard 0 Settings": {
"window": {
"visible": true
}
},
"keyboardJoysticks": [
{
"axisConfig": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public class RobotContainer {
public RobotContainer() {
configureBindings();
}

private void configureBindings() {
// TODO: Bind indexForSeconds(1.5) to joystick button 1
joystick.button(1).onTrue(indexer.indexForSeconds(1.5));
}

public Command getAutonomousCommand() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@
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

public boolean indexing; // Index State Variable
/** Creates a new Indexer subsystem. */
public Indexer() {}

/** Starts the indexing process. */
public void startIndexing() {
// TODO: Set indexing state to true
indexing = true; // Set indexing to True
}

/** Stops the indexing process. */
public void stopIndexing() {
// TODO: Set indexing state to false
indexing = false; // Set indexing to False
}

/**
Expand All @@ -28,11 +30,20 @@ public void stopIndexing() {
* @return true if indexing, false otherwise
*/
public boolean isIndexing() {
// TODO: Return indexing state
return false;
return indexing; // Return Value of Indexing
}

// TODO: Implement indexForSeconds() command factory
/**
* Returns a command that start indexing, waits for seconds, then stops indexing.
*
* @param seconds
* @return Command Object
*/
public Command indexForSeconds(double seconds) {
return Commands.runOnce(() -> startIndexing()) // Return Value of indexForSeconds
.andThen(Commands.waitSeconds(seconds))
.andThen(() -> stopIndexing());
}

@Override
public void periodic() {
Expand Down