Gray Matter LogoGray Matter Workshop

Command-Based Framework

Command-Based Framework - Core Programming Concepts

The Command-Based Framework organizes robot code into three key components: Triggers (inputs), Subsystems (hardware), and Commands (actions). This structure provides clean separation of concerns and reliable robot behavior.

Key Concept: Command-based programming is the format in which you will write your code.

Triggers

Use BooleanSuppliers (True or False)

Link inputs to commands (e.g., press button to drive forward, or use sensor to run Command automatically). All buttons/triggers on a game controller are considered "Triggers".

Subsystems

Hardware components and control logic

(e.g., Drivetrain, Arm, or Flywheel). Motors and sensors are instantiated. Methods to pull data from sensors within the subsystem are defined.

Commands

Use Runnables (void functions)

Encapsulate robot actions (e.g., DriveForwardCommand, ShootBallCommand).

The Big Picture: How It All Fits Together

How Command-Based Programming Works

Triggers

Controller buttons, sensors, or custom conditions

"When button A is pressed..."

Commands

Actions the robot performs

"...run the 'Raise Arm' command"

Subsystems

Robot mechanisms (arm, shooter, etc.)

"...which controls the Arm subsystem's motors"

Motors & Sensors

Physical robot hardware

"...to physically move the arm up"

Sensors provide feedback: Position, velocity, and status information flows back up to help Commands make decisions

Real Example: Raising an Arm

1. Trigger: Driver presses button A

2. Command: "RaiseArm" command starts running

3. Subsystem: Arm subsystem receives target position

4. Hardware: Motor spins, encoder measures position

5. Feedback: Encoder reports "target reached!" → Command ends

Progressive Implementation Path

Follow our step-by-step implementation guide to build a complete command-based robot system. Each pull request builds on the previous one, teaching core concepts progressively.

🚀 Implementation Sequence

1

Building Subsystems

Hardware instantiation, motor configuration, and basic control methods

2

Adding Commands

Command structure and creation methods

3

Triggers

User input binding and advanced command patterns

4

PID Control

Precise position control with feedback and tuning

5

Motion Magic

Smooth profiled motion with acceleration control

6

Useful Functions

Safety features, diagnostics, and utility functions

Official WPILib Command-Based Documentation

For comprehensive Command-Based Framework reference, advanced patterns, and complete API documentation:

WPILib Command-Based Programming Guide