17#include "wpi/units/time.hpp"
115 void AddPeriodic(std::function<
void()> callback, wpi::units::second_t period,
116 wpi::units::second_t offset = 0_s);
121 wpi::units::second_t
GetPeriod()
const {
return m_period; }
141 std::function<void()> func;
142 std::chrono::microseconds period;
143 std::chrono::microseconds expirationTime;
153 Callback(std::function<
void()> func, std::chrono::microseconds startTime,
154 std::chrono::microseconds period,
155 std::chrono::microseconds offset);
157 bool operator>(
const Callback& rhs)
const {
158 return expirationTime > rhs.expirationTime;
163 bool m_running =
true;
166 std::chrono::microseconds m_startTime;
167 int64_t m_loopStartTimeUs = 0;
168 wpi::units::second_t m_period;
172 std::greater<Callback>>
175 void PrintLoopOverrunMessage();
Top-level interface for opmode classes.
Definition OpMode.hpp:16
void LoopFunc()
Loop function.
~PeriodicOpMode() override
virtual void End()
Called a single time when the robot transitions from enabled to disabled, or just before the destruct...
Definition PeriodicOpMode.hpp:90
PeriodicOpMode(wpi::units::second_t period=kDefaultPeriod)
Constructor.
virtual void Start()
Called a single time when the robot transitions from disabled to enabled.
Definition PeriodicOpMode.hpp:80
void AddPeriodic(std::function< void()> callback, wpi::units::second_t period, wpi::units::second_t offset=0_s)
Add a callback to run at a specific period with a starting time offset.
int64_t GetLoopStartTime() const
Return the system clock time in microseconds for the start of the current periodic loop.
Definition PeriodicOpMode.hpp:101
virtual void Periodic()=0
Called periodically while the robot is enabled.
static constexpr auto kDefaultPeriod
Default loop period.
Definition PeriodicOpMode.hpp:56
void DisabledPeriodic() override
Called periodically while the opmode is selected on the DS (robot is disabled).
Definition PeriodicOpMode.hpp:74
void OpModeStop() final
This function is called asynchronously when the robot is disabled, to request the opmode return from ...
void PrintWatchdogEpochs()
Prints list of epochs added so far and their times.
wpi::units::second_t GetPeriod() const
Gets time period between calls to Periodic() functions.
Definition PeriodicOpMode.hpp:121
void OpModeRun(int64_t opModeId) final
This function is called when the opmode starts (robot is enabled).
A class that's a wrapper around a watchdog timer.
Definition Watchdog.hpp:25
A move-only C++ wrapper around a HAL handle.
Definition Types.hpp:16
This class is the same as std::priority_queue with two changes:
Definition priority_queue.hpp:26
Definition CvSource.hpp:15