Scheduling Functions at Custom Frequencies¶
addPeriodic() method allows one to run custom methods at a rate faster than the default
TimedRobot periodic update rate (20 ms). Previously, teams had to make a
Notifier to run feedback controllers more often than the
TimedRobot loop period of 20 ms (running
TimedRobot more often than this is not advised). Now, users can run feedback controllers more often than the main robot loop, but synchronously with the
TimedRobot periodic functions, eliminating potential thread safety issues.
addPeriodic() (Java) /
AddPeriodic() (C++) method takes in a lambda (the function to run), along with the requested period and an optional offset from the common starting time. The optional third argument is useful for scheduling a function in a different timeslot relative to the other
TimedRobot periodic methods.
The units for the period and offset are seconds in Java. In C++, the units library can be used to specify a period and offset in any time unit.
teleopPeriodic() method in this example runs every 20 ms, and the controller update is run every 10ms with an offset of 10ms from when
teleopPeriodic() runs so that their timeslots don’t conflict.