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
2 changes: 1 addition & 1 deletion tasks/lesson2-indexer-task/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 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 All @@ -20,10 +25,10 @@
"axisCount": 3,
"buttonCount": 4,
"buttonKeys": [
90,
88,
67,
86
49,
50,
51,
52
],
"povConfig": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -15,13 +16,19 @@ 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();
}

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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
Expand Down