Skip to main content

What is Command-Based Programming?

In robotics, command-based programming refers both to a general programming paradigm and, in our case, to the set of tools provided by CommandKit that make it easier to use. Command-based programming is a design pattern for organizing robot code. While it’s not the only option, it’s widely used because it helps make code cleaner, more modular, and easier to reuse across seasons. This paradigm is also an example of declarative programming. Instead of writing step-by-step logic that runs every loop, you describe what the robot should do under certain conditions. For example, you might say: “Run this action whenever a condition is true.”

With Command-Based

// Java
new RunnableCommand(() -> {
  telemetry.addData("Hello", "World");
  telemetry.update();
}, condition::isMet);

Without Command-Based

Without commands, you would need to manually check conditions and manage control flow inside your loop:
// Java
if (condition.isMet()) {
  telemetry.addData("Hello", "World");
  telemetry.update();
} else {
  telemetry.addData("Goodbye", "World");
  telemetry.update();
}
This approach works, but it makes the code more repetitive and harder to maintain as your robot logic grows.