Skip to main content

Module 2 — Command-Based Foundations

Objective: structure the robot with subsystems, commands, and bindings.

Prereqs: Module 1 project created.

Steps

  • Create subsystems (drive, intake, shooter) with safe methods.
  • Set default commands for drive; bind buttons to actions in RobotContainer.
  • Add at least one autonomous command.
  • Ensure commands declare requirements to avoid resource conflicts.
  • Use RunCommand/InstantCommand for simple actions; command groups for sequences.

Deliverables

  • Drive subsystem with default arcade/tank command, plus a button-bound action.
  • One autonomous routine (even a simple drive-forward) to validate structure.

Code example (button binding)

public RobotContainer() {
drive.setDefaultCommand(new RunCommand(
() -> drive.arcadeDrive(driver.getLeftY(), driver.getRightX()), drive));
driver.a().whileTrue(new InstantCommand(intake::run, intake))
.onFalse(new InstantCommand(intake::stop, intake));
}

Resources

  • Command-based: docs.wpilib.org/en/stable/docs/software/commandbased/index.html
  • Examples: github.com/wpilibsuite/allwpilib/tree/main/wpilibjExamples

Spec notes / data to log

  • Controllers: map axes/buttons; note deadbands and sign conventions.
  • Commands: requirements declared; default drive command set.
  • Data: log joystick inputs vs drive outputs to verify scaling/signs.

Instructions (numbered)

  1. Define subsystems (drive/intake/shooter) with safe methods (stop on end).
  2. Set default drive command (arcade/tank) using RunCommand.
  3. Bind buttons in RobotContainer to actions; ensure each command declares requirements.
  4. Create at least one autonomous command/group; test in Sim GUI.
  5. Commit vendordeps and code; run unit sim to verify bindings.

Example

  • Default drive RunCommand using Xbox leftY/rightX; A button runs intake; simple auto drives forward 2 m then stops.

Best practices

  • Use SubsystemBase + Command patterns consistently.
  • Keep commands short and single-purpose; compose with groups.
  • Declare requirements to prevent resource conflicts.

Common mistakes

  • Missing requirements → unexpected interrupts.
  • Long blocking code in commands.
  • No default command on drive → robot won't respond in teleop.

Checklist

  • Subsystems implemented
  • Default drive command set
  • Buttons bound and tested
  • Autonomous command/group added
  • Requirements declared on commands
  • Sim GUI test passed

Recommended tools

  • WPILib templates, Sim GUI, controller for testing, git for versioning.

Sample log (template)

  • Date:
  • Subsystems added:
  • Buttons/commands tested:
  • Auto test result:
  • Issues/fixes:

Photos/diagrams

  • [Placeholder: diagram of controller bindings → commands → subsystems]