TimedRobot

class wpilib.TimedRobot(period: wpimath.units.seconds = 0.02)

Bases: IterativeRobotBase

TimedRobot implements the IterativeRobotBase robot program framework.

The TimedRobot class is intended to be subclassed by a user creating a robot program.

Periodic() functions from the base class are called on an interval by a Notifier instance.

Constructor for TimedRobot.

Parameters:

period – The period of the robot loop function.

addPeriodic(callback: collections.abc.Callable[[], None], period: wpimath.units.seconds, offset: wpimath.units.seconds = 0.0) → None

Add a callback to run at a specific period with a starting time offset.

This is scheduled on TimedRobot’s Notifier, so TimedRobot and the callback run synchronously. Interactions between them are thread-safe.

Parameters:
  • callback – The callback to run.

  • period – The period at which to run the callback.

  • offset – The offset from the common starting time. This is useful for scheduling a callback in a different timeslot relative to TimedRobot.

endCompetition() → None

Ends the main loop in StartCompetition().

getLoopStartTime() → int

Return the system clock time in microseconds for the start of the current periodic loop. This is in the same time base as Timer.GetFPGATimestamp(), but is stable through a loop. It is updated at the beginning of every periodic callback (including the normal periodic loop).

Returns:

Robot running time in microseconds, as of the start of the current periodic function.

kDefaultPeriod = 20.0
startCompetition() → None

Provide an alternate “main loop” via StartCompetition().