What runs first?

In Command-based WPILIB what runs first? Stuff in the Robot.java teleopPeriodic() function or stuff in a subsystem’s periodic() function? Or is it async?

When in doubt, check the source…

Mode-specific periodic methods run before robotPeriodic. These will run regardless of whether or not you use commands.

WPILib recommends invoking the command scheduler by running CommandScheduler.getInstance().run() in your robotPeriodic method. The scheduling algorithm is documented as well.

1 Like