WPILibC++  2021.3.1
frc::TimedRobot Class Reference

TimedRobot implements the IterativeRobotBase robot program framework. More...

#include <frc/TimedRobot.h>

Inheritance diagram for frc::TimedRobot:
frc::IterativeRobotBase frc::ErrorBase frc::RobotBase

Public Member Functions

void StartCompetition () override
 Provide an alternate "main loop" via StartCompetition().
 
void EndCompetition () override
 Ends the main loop in StartCompetition().
 
units::second_t GetPeriod () const
 Get the time period between calls to Periodic() functions.
 
 TimedRobot (double period)
 Constructor for TimedRobot. More...
 
 TimedRobot (units::second_t period=kDefaultPeriod)
 Constructor for TimedRobot. More...
 
 TimedRobot (TimedRobot &&)=default
 
TimedRobotoperator= (TimedRobot &&)=default
 
void AddPeriodic (std::function< void()> callback, units::second_t period, units::second_t offset=0_s)
 Add a callback to run at a specific period with a starting time offset. More...
 
- Public Member Functions inherited from frc::IterativeRobotBase
virtual void RobotInit ()
 Robot-wide initialization code should go here. More...
 
virtual void SimulationInit ()
 Robot-wide simulation initialization code should go here. More...
 
virtual void DisabledInit ()
 Initialization code for disabled mode should go here. More...
 
virtual void AutonomousInit ()
 Initialization code for autonomous mode should go here. More...
 
virtual void TeleopInit ()
 Initialization code for teleop mode should go here. More...
 
virtual void TestInit ()
 Initialization code for test mode should go here. More...
 
virtual void RobotPeriodic ()
 Periodic code for all modes should go here. More...
 
virtual void SimulationPeriodic ()
 Periodic simulation code should go here. More...
 
virtual void DisabledPeriodic ()
 Periodic code for disabled mode should go here. More...
 
virtual void AutonomousPeriodic ()
 Periodic code for autonomous mode should go here. More...
 
virtual void TeleopPeriodic ()
 Periodic code for teleop mode should go here. More...
 
virtual void TestPeriodic ()
 Periodic code for test mode should go here. More...
 
void SetNetworkTablesFlushEnabled (bool enabled)
 Enables or disables flushing NetworkTables every loop iteration. More...
 
 IterativeRobotBase (double period)
 Constructor for IterativeRobotBase. More...
 
 IterativeRobotBase (units::second_t period)
 Constructor for IterativeRobotBase. More...
 
- Public Member Functions inherited from frc::RobotBase
bool IsEnabled () const
 Determine if the Robot is currently enabled. More...
 
bool IsDisabled () const
 Determine if the Robot is currently disabled. More...
 
bool IsAutonomous () const
 Determine if the robot is currently in Autonomous mode. More...
 
bool IsAutonomousEnabled () const
 Determine if the robot is currently in Autonomous mode and enabled. More...
 
bool IsOperatorControl () const
 Determine if the robot is currently in Operator Control mode. More...
 
bool IsOperatorControlEnabled () const
 Determine if the robot is current in Operator Control mode and enabled. More...
 
bool IsTest () const
 Determine if the robot is currently in Test mode. More...
 
bool IsNewDataAvailable () const
 Indicates if new data is available from the driver station. More...
 
 RobotBase ()
 Constructor for a generic robot program. More...
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (const ErrorBase &)=default
 
ErrorBaseoperator= (const ErrorBase &)=default
 
 ErrorBase (ErrorBase &&)=default
 
ErrorBaseoperator= (ErrorBase &&)=default
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 Retrieve the current error. More...
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual void SetErrnoError (const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const wpi::Twine &errorMessage, Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 
void ClearGlobalErrors ()
 Clear global errors.
 

Static Public Attributes

static constexpr units::second_t kDefaultPeriod = 20_ms
 

Additional Inherited Members

- Static Public Member Functions inherited from frc::RobotBase
static std::thread::id GetThreadId ()
 Gets the ID of the main robot thread.
 
static constexpr bool IsReal ()
 Get if the robot is real. More...
 
static constexpr bool IsSimulation ()
 Get if the robot is a simulation. More...
 
- Static Public Member Functions inherited from frc::ErrorBase
static void SetGlobalError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (const wpi::Twine &errorMessage, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static Error GetGlobalError ()
 Retrieve the last global error.
 
static std::vector< ErrorGetGlobalErrors ()
 Retrieve all global errors.
 
- Protected Member Functions inherited from frc::IterativeRobotBase
 IterativeRobotBase (IterativeRobotBase &&)=default
 
IterativeRobotBaseoperator= (IterativeRobotBase &&)=default
 
void LoopFunc ()
 
- Protected Member Functions inherited from frc::RobotBase
 RobotBase (RobotBase &&) noexcept
 
RobotBaseoperator= (RobotBase &&) noexcept
 
- Protected Attributes inherited from frc::IterativeRobotBase
units::second_t m_period
 
- Protected Attributes inherited from frc::RobotBase
DriverStationm_ds
 
- Protected Attributes inherited from frc::ErrorBase
Error m_error
 
- Static Protected Attributes inherited from frc::RobotBase
static std::thread::id m_threadId
 

Detailed Description

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 & Destructor Documentation

◆ TimedRobot() [1/2]

frc::TimedRobot::TimedRobot ( double  period)
explicit

Constructor for TimedRobot.

Deprecated:
use unit safe constructor instead. TimedRobot(units::second_t period = kDefaultPeriod)
Parameters
periodPeriod in seconds.

◆ TimedRobot() [2/2]

frc::TimedRobot::TimedRobot ( units::second_t  period = kDefaultPeriod)
explicit

Constructor for TimedRobot.

Parameters
periodPeriod.

Member Function Documentation

◆ AddPeriodic()

void frc::TimedRobot::AddPeriodic ( std::function< void()>  callback,
units::second_t  period,
units::second_t  offset = 0_s 
)

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
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.

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