RobotContainer

RobotContainer is a class that combines the subsystems, commands, and triggers of the robot. It's basically the brain of the robot.


ConfigureBindings()

ConfigureBindings() is where you'll declare most of your triggers. More info on triggers is down below.

Triggers

Triggers are a powerful feature in WPILIB's command-based framework that lets you bind commands to various events. For example, we can use them to run commands when a button is pressed or when a sensor detects an event.

Some examples of things we can use triggers for are:

  • Getting inputs

  • Checking sensors

  • Checking state changes

However, on this page, we'll focus primarily on using triggers for moving the robot through the controller. When doing this, we don't create brand-new Trigger objects—we use the built-in ones fromExternal Controllers.

All of these triggers can be found here.

Triggers have three built-in methods that we use to run commands depending on specific criteria. The most common ones are:

  • OnTrue(Command c)

  • OnFalse(Command c)

  • WhileTrue(Command c)

  • WhileFalse(Command c)

As you can tell, all four of these methods take in a command as a parameter. All four of them also run whatever's in their parameters, but depending on their name, they run at completely different times. (for example: WhileTrue() runs its command while a condition is true)

If you want an example of how to use them, look back at configureBindings() at the second trigger statement. As it stands, while the B button is held down, it will constantly schedule this example method command.

If I change it to onTrue(), the trigger will only schedule the command when the B button is pressed down for the first time.

By mastering triggers, you can create responsive, sophisticated robot behaviors that react intelligently to both operator inputs and changing field conditions, all while maintaining readable and maintainable code.

Last updated