19#include "wpi/units/time.hpp"
36template <
typename T,
typename R>
47template <
typename T,
typename R>
144 void AddPeriodic(std::function<
void()> callback, wpi::units::second_t period);
157 return m_callbacks.GetLoopStartTime();
174 std::string_view
name, std::string_view group,
175 std::string_view description,
191 std::string_view
name, std::string_view group = {},
192 std::string_view description = {});
231 wpi::units::second_t m_period;
232 std::chrono::microseconds m_startTime;
233 Alert m_loopOverrunAlert;
237 int64_t m_lastModeId = -1;
238 bool m_calledDriverStationConnected =
false;
239 bool m_lastEnabledState =
false;
240 std::shared_ptr<OpMode> m_currentOpMode;
241 std::vector<wpi::internal::PeriodicPriorityQueue::Callback>
242 m_activeOpModeCallbacks;
243 std::optional<wpi::internal::PeriodicPriorityQueue::Callback>
262template <
typename Derived>
291 template <ConstructibleOpMode<Derived> T>
293 std::string_view description,
298 [
this] {
return std::make_unique<T>(*
static_cast<Derived*
>(
this)); },
299 mode,
name, group, description, textColor, backgroundColor);
302 description, textColor, backgroundColor);
318 template <ConstructibleOpMode<Derived> T>
320 std::string_view group = {},
321 std::string_view description = {}) {
322 if constexpr (detail::OneArgOpMode<T, Derived>) {
324 [
this] {
return std::make_unique<T>(*
static_cast<Derived*
>(
this)); },
325 mode,
name, group, description);
326 }
else if constexpr (detail::NoArgOpMode<T>) {
This file defines the DenseMap class.
@ name
Definition base.h:690
Persistent alert to be sent to the driver station.
Definition Alert.hpp:36
void PublishOpModes()
Publishes the operating mode options to the driver station.
void EndCompetition() override
Ends the main loop in StartCompetition().
virtual void SimulationInit()
Function called once during robot initialization in simulation.
Definition OpModeRobot.hpp:110
virtual void NonePeriodic()
Function called periodically anytime when no opmode is selected, including when the Driver Station is...
Definition OpModeRobot.hpp:136
void ClearOpModes()
Clears all operating mode options and publishes an empty list to the driver station.
OpModeRobotBase(OpModeRobotBase &&)=delete
virtual void DisabledExit()
Function called once when the robot exits disabled state.
Definition OpModeRobot.hpp:130
void LoopFunc()
Main robot loop function.
virtual void DisabledInit()
Function called once when the robot becomes disabled.
Definition OpModeRobot.hpp:120
void RemoveOpMode(RobotMode mode, std::string_view name)
Removes an operating mode option.
virtual void RobotPeriodic()
Function called periodically every loop, regardless of enabled state or OpMode selection.
Definition OpModeRobot.hpp:105
static constexpr auto DEFAULT_PERIOD
Default loop period.
Definition OpModeRobot.hpp:66
virtual void SimulationPeriodic()
Function called periodically in simulation.
Definition OpModeRobot.hpp:115
OpModeRobotBase & operator=(OpModeRobotBase &&)=delete
OpModeRobotBase()
Constructor for an OpModeRobot with a default loop time of 0.02 seconds.
void AddOpModeFactory(OpModeFactory factory, RobotMode mode, std::string_view name, std::string_view group, std::string_view description, const wpi::util::Color &textColor, const wpi::util::Color &backgroundColor)
Adds an operating mode option using a factory function that creates the opmode.
void AddOpModeFactory(OpModeFactory factory, RobotMode mode, std::string_view name, std::string_view group={}, std::string_view description={})
Adds an operating mode option using a factory function that creates the opmode.
OpModeRobotBase(wpi::units::second_t period)
Constructor.
std::function< std::unique_ptr< OpMode >()> OpModeFactory
Definition OpModeRobot.hpp:63
void AddPeriodic(std::function< void()> callback, wpi::units::second_t period)
Add a callback to run at a specific period.
virtual void DriverStationConnected()
Code that needs to know the DS state should go here.
Definition OpModeRobot.hpp:99
void StartCompetition() override
Provide an alternate "main loop" via StartCompetition().
wpi::units::microsecond_t GetLoopStartTime() const
Return the system clock time in microseconds for the start of the current periodic loop.
Definition OpModeRobot.hpp:156
virtual void DisabledPeriodic()
Function called periodically while the robot is disabled.
Definition OpModeRobot.hpp:125
OpModeRobot()
Constructor for an OpModeRobot with a default loop time of 0.02 seconds.
Definition OpModeRobot.hpp:275
OpModeRobot(wpi::units::second_t period)
Constructor.
Definition OpModeRobot.hpp:270
void AddOpMode(RobotMode mode, std::string_view name, std::string_view group, std::string_view description, const wpi::util::Color &textColor, const wpi::util::Color &backgroundColor)
Adds an operating mode option.
Definition OpModeRobot.hpp:292
void AddOpMode(RobotMode mode, std::string_view name, std::string_view group={}, std::string_view description={})
Adds an operating mode option.
Definition OpModeRobot.hpp:319
RobotBase()
Constructor for a generic robot program.
A class that's a wrapper around a watchdog timer.
Definition Watchdog.hpp:25
A priority queue for scheduling periodic callbacks based on their next execution time.
Definition PeriodicPriorityQueue.hpp:30
Represents colors that can be used with Addressable LEDs.
Definition Color.hpp:42
Definition DenseMap.hpp:728
Concept indicating a class is derived from OpMode and has either a no-argument constructor or a const...
Definition OpModeRobot.hpp:48
Definition OpModeRobot.hpp:35
Definition OpModeRobot.hpp:37
Definition OpModeRobot.hpp:33
HAL_Handle HAL_NotifierHandle
Definition Types.h:37
Converts a string literal into a format string that will be parsed at compile time and converted into...
Definition printf.h:50
RobotMode
The overall robot mode (not including enabled state).
Definition DriverStationTypes.hpp:15
Definition raw_os_ostream.hpp:19
::std::mutex mutex
Definition mutex.hpp:17
Definition CvSource.hpp:15