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

Top-level interface for opmode classes. More...

#include <wpi/opmode/OpMode.hpp>

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

Public Member Functions

virtual ~OpMode ()=default
 The object is destroyed when the opmode is no longer selected on the DS or after an enabled run ends.
virtual void DisabledPeriodic ()
 This function is called periodically while the opmode is selected on the DS (robot is disabled).
virtual void Start ()
 Called once when this opmode transitions to enabled.
virtual void Periodic ()
 This function is called periodically while the opmode is enabled.
virtual void End ()
 This function is called when the robot disables or switches opmodes while this opmode is enabled.
virtual std::vector< wpi::internal::PeriodicPriorityQueue::CallbackGetCallbacks ()
 Returns a vector of custom periodic callbacks to be executed while the opmode is enabled.

Detailed Description

Top-level interface for opmode classes.

Users should generally extend one of the abstract implementations of this interface (e.g. PeriodicOpMode) rather than directly implementing this interface.

Lifecycle:

  • constructed when opmode selected on driver station
  • DisabledPeriodic() called periodically as long as DS is disabled
  • when DS transitions from disabled to enabled, Start() is called once
  • while DS is enabled, Periodic() is called periodically and additional periodic callbacks added via GetCallbacks() are called periodically
  • when DS transitions from enabled to disabled, or a different opmode is selected while enabled, End() is called, followed by Close(); the object is not reused
  • if a different opmode is selected while disabled, only Close() is called; the object is not reused

Constructor & Destructor Documentation

◆ ~OpMode()

virtual wpi::OpMode::~OpMode ( )
virtualdefault

The object is destroyed when the opmode is no longer selected on the DS or after an enabled run ends.

The object will not be reused after the destructor is called.

Member Function Documentation

◆ DisabledPeriodic()

virtual void wpi::OpMode::DisabledPeriodic ( )
inlinevirtual

This function is called periodically while the opmode is selected on the DS (robot is disabled).

Code that should only run once when the opmode is selected should go in the opmode constructor.

Reimplemented in wpi::PeriodicOpMode.

◆ End()

virtual void wpi::OpMode::End ( )
inlinevirtual

This function is called when the robot disables or switches opmodes while this opmode is enabled.

Implementations should stop blocking work promptly.

Reimplemented in wpi::PeriodicOpMode.

◆ GetCallbacks()

virtual std::vector< wpi::internal::PeriodicPriorityQueue::Callback > wpi::OpMode::GetCallbacks ( )
inlinevirtual

Returns a vector of custom periodic callbacks to be executed while the opmode is enabled.

This method allows opmodes to register arbitrary periodic callbacks with custom execution intervals. The callbacks are executed by the robot framework at their scheduled times, in addition to the primary Periodic() callback.

Returns
A vector of custom callbacks to execute, or an empty vector if no custom callbacks are needed. The default implementation returns an empty vector.

Reimplemented in wpi::PeriodicOpMode.

◆ Periodic()

virtual void wpi::OpMode::Periodic ( )
inlinevirtual

This function is called periodically while the opmode is enabled.

Reimplemented in wpi::PeriodicOpMode.

◆ Start()

virtual void wpi::OpMode::Start ( )
inlinevirtual

Called once when this opmode transitions to enabled.

Reimplemented in wpi::PeriodicOpMode.


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