WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::RobotBase Class Referenceabstract

Implement a Robot Program framework. More...

#include <wpi/framework/RobotBase.hpp>

Inheritance diagram for wpi::RobotBase:
wpi::IterativeRobotBase wpi::OpModeRobotBase wpi::TimedRobot wpi::OpModeRobot< Derived > wpi::TimesliceRobot

Public Member Functions

virtual void StartCompetition ()=0
 Start the main robot code.
virtual void EndCompetition ()=0
 Ends the main loop in StartCompetition().
 RobotBase ()
 Constructor for a generic robot program.
virtual ~RobotBase ()=default

Static Public Member Functions

static bool IsEnabled ()
 Determine if the Robot is currently enabled.
static bool IsDisabled ()
 Determine if the Robot is currently disabled.
static bool IsAutonomous ()
 Determine if the robot is currently in Autonomous mode.
static bool IsAutonomousEnabled ()
 Determine if the robot is currently in Autonomous mode and enabled.
static bool IsTeleop ()
 Determine if the robot is currently in Operator Control mode.
static bool IsTeleopEnabled ()
 Determine if the robot is current in Operator Control mode and enabled.
static bool IsTest ()
 Determine if the robot is currently in Test mode.
static bool IsTestEnabled ()
 Determine if the robot is current in Test mode and enabled.
static int64_t GetOpModeId ()
 Gets the currently selected operating mode of the driver station.
static std::string GetOpMode ()
 Gets the currently selected operating mode of the driver station.
static std::thread::id GetThreadId ()
 Returns the main thread ID.
static RuntimeType GetRuntimeType ()
 Get the current runtime type.
static constexpr bool IsReal ()
 Get if the robot is real.
static constexpr bool IsSimulation ()
 Get if the robot is a simulation.

Protected Member Functions

 RobotBase (RobotBase &&)=default
RobotBaseoperator= (RobotBase &&)=default

Protected Attributes

NT_Listener connListenerHandle

Static Protected Attributes

static std::thread::id m_threadId

Detailed Description

Implement a Robot Program framework.

The RobotBase class is intended to be subclassed to create a robot program. The user must implement StartCompetition() which will be called once and is not expected to exit. The user must also implement EndCompetition(), which signals to the code in StartCompetition() that it should exit.

It is not recommended to subclass this class directly - instead subclass IterativeRobotBase or TimedRobot.

Constructor & Destructor Documentation

◆ RobotBase() [1/2]

wpi::RobotBase::RobotBase ( )

Constructor for a generic robot program.

User code can be placed in the constructor that runs before the Autonomous or Operator Control period starts. The constructor will run to completion before Autonomous is entered.

This must be used to ensure that the communications code starts. In the future it would be nice to put this code into it's own task that loads on boot so ensure that it runs.

◆ ~RobotBase()

virtual wpi::RobotBase::~RobotBase ( )
virtualdefault

◆ RobotBase() [2/2]

wpi::RobotBase::RobotBase ( RobotBase && )
protecteddefault

Member Function Documentation

◆ EndCompetition()

virtual void wpi::RobotBase::EndCompetition ( )
pure virtual

Ends the main loop in StartCompetition().

Implemented in wpi::OpModeRobotBase, and wpi::TimedRobot.

◆ GetOpMode()

std::string wpi::RobotBase::GetOpMode ( )
static

Gets the currently selected operating mode of the driver station.

Note this does not mean the robot is enabled; use IsEnabled() for that.

Returns
Operating mode string; may return a string not in the list of options, so callers should be prepared to handle that case

◆ GetOpModeId()

int64_t wpi::RobotBase::GetOpModeId ( )
static

Gets the currently selected operating mode of the driver station.

Note this does not mean the robot is enabled; use IsEnabled() for that.

Returns
the unique ID provided by the DriverStation::AddOpMode() function; may return 0 or a unique ID not added, so callers should be prepared to handle that case

◆ GetRuntimeType()

RuntimeType wpi::RobotBase::GetRuntimeType ( )
static

Get the current runtime type.

Returns
Current runtime type.

◆ GetThreadId()

std::thread::id wpi::RobotBase::GetThreadId ( )
static

Returns the main thread ID.

Returns
The main thread ID.

◆ IsAutonomous()

bool wpi::RobotBase::IsAutonomous ( )
static

Determine if the robot is currently in Autonomous mode.

Returns
True if the robot is currently operating Autonomously as determined by the Driver Station.

◆ IsAutonomousEnabled()

bool wpi::RobotBase::IsAutonomousEnabled ( )
static

Determine if the robot is currently in Autonomous mode and enabled.

Returns
True if the robot us currently operating Autonomously while enabled as determined by the Driver Station.

◆ IsDisabled()

bool wpi::RobotBase::IsDisabled ( )
static

Determine if the Robot is currently disabled.

Returns
True if the Robot is currently disabled by the Driver Station.

◆ IsEnabled()

bool wpi::RobotBase::IsEnabled ( )
static

Determine if the Robot is currently enabled.

Returns
True if the Robot is currently enabled by the Driver Station.

◆ IsReal()

constexpr bool wpi::RobotBase::IsReal ( )
inlinestaticconstexpr

Get if the robot is real.

Returns
If the robot is running in the real world.

◆ IsSimulation()

constexpr bool wpi::RobotBase::IsSimulation ( )
inlinestaticconstexpr

Get if the robot is a simulation.

Returns
If the robot is running in simulation.

◆ IsTeleop()

bool wpi::RobotBase::IsTeleop ( )
static

Determine if the robot is currently in Operator Control mode.

Returns
True if the robot is currently operating in Tele-Op mode as determined by the Driver Station.

◆ IsTeleopEnabled()

bool wpi::RobotBase::IsTeleopEnabled ( )
static

Determine if the robot is current in Operator Control mode and enabled.

Returns
True if the robot is currently operating in Tele-Op mode while enabled as determined by the Driver Station.

◆ IsTest()

bool wpi::RobotBase::IsTest ( )
static

Determine if the robot is currently in Test mode.

Returns
True if the robot is currently running in Test mode as determined by the Driver Station.

◆ IsTestEnabled()

bool wpi::RobotBase::IsTestEnabled ( )
static

Determine if the robot is current in Test mode and enabled.

Returns
True if the robot is currently operating in Test mode while enabled as determined by the Driver Station.

◆ operator=()

RobotBase & wpi::RobotBase::operator= ( RobotBase && )
protecteddefault

◆ StartCompetition()

virtual void wpi::RobotBase::StartCompetition ( )
pure virtual

Start the main robot code.

This function will be called once and should not exit until signalled by EndCompetition()

Implemented in wpi::OpModeRobotBase, and wpi::TimedRobot.

Member Data Documentation

◆ connListenerHandle

NT_Listener wpi::RobotBase::connListenerHandle
protected

◆ m_threadId

std::thread::id wpi::RobotBase::m_threadId
staticprotected

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