WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
wpi::PeriodicOpMode Class Reference

An opmode structure for periodic operation. More...

#include <wpi/opmode/PeriodicOpMode.hpp>

Inheritance diagram for wpi::PeriodicOpMode:
wpi::OpMode

Public Member Functions

 ~PeriodicOpMode () override=default
void DisabledPeriodic () override
 Called periodically while the opmode is selected on the DS (robot is disabled).
void Start () override
 Called a single time when the robot transitions from disabled to enabled.
void Periodic () override
 Called periodically while the robot is enabled.
void End () override
 Called a single time when the robot transitions from enabled to disabled, or just before Close() is called if a different opmode is selected while the robot is enabled.
std::vector< wpi::internal::PeriodicPriorityQueue::CallbackGetCallbacks () override
 Returns the set of additional periodic callbacks registered via AddPeriodic().
void AddPeriodic (std::function< void()> callback, wpi::units::second_t period)
 Add a callback to run at a specific period.
void AddPeriodic (std::function< void()> callback, wpi::units::second_t period, wpi::units::second_t offset)
 Add a callback to run at a specific period with a starting time offset.
Public Member Functions inherited from wpi::OpMode
virtual ~OpMode ()=default
 The object is destroyed when the opmode is no longer selected on the DS or after an enabled run ends.

Protected Member Functions

 PeriodicOpMode ()
 Constructor.

Detailed Description

An opmode structure for periodic operation.

This base class implements a loop that runs one or more functions periodically (on a set time interval aka loop period). The primary periodic callback function is the abstract Periodic() function. Additional periodic callbacks with different intervals can be added using the AddPeriodic() set of functions.

Lifecycle:

  • Constructed when opmode selected on driver station
  • DisabledPeriodic() called periodically as long as DS is disabled. Note this is not called on a set time interval (it does not use the same time interval as Periodic())
  • When DS transitions from disabled to enabled, Start() is called once
  • While DS is enabled, Periodic() is called periodically on the time interval set by the robot framework, and additional periodic callbacks added via AddPeriodic() are called periodically on their set time intervals
  • When DS transitions from enabled to disabled, or a different opmode is selected on the driver station when the DS is enabled, End() is called, followed by Close(); the object is not reused
  • If a different opmode is selected on the driver station when the DS is disabled, only Close() is called; the object is not reused

Constructor & Destructor Documentation

◆ PeriodicOpMode()

wpi::PeriodicOpMode::PeriodicOpMode ( )
protected

Constructor.

◆ ~PeriodicOpMode()

wpi::PeriodicOpMode::~PeriodicOpMode ( )
overridedefault

Member Function Documentation

◆ AddPeriodic() [1/2]

void wpi::PeriodicOpMode::AddPeriodic ( std::function< void()> callback,
wpi::units::second_t period )
inline

Add a callback to run at a specific period.

This is scheduled on the same Notifier as Periodic(), so Periodic() and the callback run synchronously. Interactions between them are thread-safe.

Parameters
callbackThe callback to run.
periodThe period at which to run the callback.

◆ AddPeriodic() [2/2]

void wpi::PeriodicOpMode::AddPeriodic ( std::function< void()> callback,
wpi::units::second_t period,
wpi::units::second_t offset )

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

This is scheduled on the same Notifier as Periodic(), so Periodic() and the callback run synchronously. Interactions between them are thread-safe.

Parameters
callbackThe callback to run.
periodThe period at which to run the callback.
offsetThe offset from the common starting time. This is useful for scheduling a callback in a different timeslot relative to TimedRobot.

◆ DisabledPeriodic()

void wpi::PeriodicOpMode::DisabledPeriodic ( )
inlineoverridevirtual

Called periodically while the opmode is selected on the DS (robot is disabled).

Reimplemented from wpi::OpMode.

◆ End()

void wpi::PeriodicOpMode::End ( )
inlineoverridevirtual

Called a single time when the robot transitions from enabled to disabled, or just before Close() is called if a different opmode is selected while the robot is enabled.

Reimplemented from wpi::OpMode.

◆ GetCallbacks()

std::vector< wpi::internal::PeriodicPriorityQueue::Callback > wpi::PeriodicOpMode::GetCallbacks ( )
inlineoverridevirtual

Returns the set of additional periodic callbacks registered via AddPeriodic().

These are executed by the robot framework while the opmode is enabled, in addition to the primary Periodic() callback.

Returns
The vector of additional periodic callbacks.

Reimplemented from wpi::OpMode.

◆ Periodic()

void wpi::PeriodicOpMode::Periodic ( )
inlineoverridevirtual

Called periodically while the robot is enabled.

The framework calls this at OpModeRobot's configured loop period.

Reimplemented from wpi::OpMode.

◆ Start()

void wpi::PeriodicOpMode::Start ( )
inlineoverridevirtual

Called a single time when the robot transitions from disabled to enabled.

This is called prior to Periodic() being called.

Reimplemented from wpi::OpMode.


The documentation for this class was generated from the following file: