WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
frc::DriverStation Class Reference

Provide access to the network communication data to / from the Driver Station. More...

#include <DriverStation.h>

Inheritance diagram for frc::DriverStation:
frc::SensorBase frc::RobotStateInterface frc::ErrorBase

Public Types

enum  Alliance { kRed, kBlue, kInvalid }
 

Public Member Functions

double GetStickAxis (int stick, int axis)
 Get the value of the axis on a joystick. More...
 
int GetStickPOV (int stick, int pov)
 Get the state of a POV on the joystick. More...
 
int GetStickButtons (int stick) const
 The state of the buttons on the joystick. More...
 
bool GetStickButton (int stick, int button)
 The state of one joystick button. More...
 
int GetStickAxisCount (int stick) const
 Returns the number of axes on a given joystick port. More...
 
int GetStickPOVCount (int stick) const
 Returns the number of POVs on a given joystick port. More...
 
int GetStickButtonCount (int stick) const
 Returns the number of buttons on a given joystick port. More...
 
bool GetJoystickIsXbox (int stick) const
 Returns a boolean indicating if the controller is an xbox controller. More...
 
int GetJoystickType (int stick) const
 Returns the type of joystick at a given port. More...
 
std::string GetJoystickName (int stick) const
 Returns the name of the joystick at the given port. More...
 
int GetJoystickAxisType (int stick, int axis) const
 Returns the types of Axes on a given joystick port. More...
 
bool IsEnabled () const override
 Check if the DS has enabled the robot. More...
 
bool IsDisabled () const override
 Check if the robot is disabled. More...
 
bool IsAutonomous () const override
 Check if the DS is commanding autonomous mode. More...
 
bool IsOperatorControl () const override
 Check if the DS is commanding teleop mode. More...
 
bool IsTest () const override
 Check if the DS is commanding test mode. More...
 
bool IsDSAttached () const
 Check if the DS is attached. More...
 
bool IsNewControlData () const
 Has a new control packet from the driver station arrived since the last time this function was called? More...
 
bool IsFMSAttached () const
 Is the driver station attached to a Field Management System? More...
 
bool IsSysActive () const
 Check if the FPGA outputs are enabled. More...
 
bool IsBrownedOut () const
 Check if the system is browned out. More...
 
Alliance GetAlliance () const
 Return the alliance that the driver station says it is on. More...
 
int GetLocation () const
 Return the driver station location on the field. More...
 
void WaitForData ()
 Wait until a new packet comes from the driver station. More...
 
bool WaitForData (double timeout)
 Wait until a new packet comes from the driver station, or wait for a timeout. More...
 
double GetMatchTime () const
 Return the approximate match time. More...
 
double GetBatteryVoltage () const
 Read the battery voltage. More...
 
void InDisabled (bool entering)
 Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only. More...
 
void InAutonomous (bool entering)
 Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only. More...
 
void InOperatorControl (bool entering)
 Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only. More...
 
void InTest (bool entering)
 Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only. More...
 
- Public Member Functions inherited from frc::SensorBase
 SensorBase (const SensorBase &)=delete
 
SensorBaseoperator= (const SensorBase &)=delete
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (const ErrorBase &)=delete
 
ErrorBaseoperator= (const ErrorBase &)=delete
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (llvm::StringRef contextMessage, llvm::StringRef filename, llvm::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, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::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, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (llvm::StringRef errorMessage, Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 

Static Public Member Functions

static DriverStationGetInstance ()
 Return a pointer to the singleton DriverStation. More...
 
static void ReportError (llvm::StringRef error)
 Report an error to the DriverStation messages window. More...
 
static void ReportWarning (llvm::StringRef error)
 Report a warning to the DriverStation messages window. More...
 
static void ReportError (bool is_error, int code, llvm::StringRef error, llvm::StringRef location, llvm::StringRef stack)
 
- Static Public Member Functions inherited from frc::SensorBase
static int GetDefaultSolenoidModule ()
 
static bool CheckSolenoidModule (int moduleNumber)
 Check that the solenoid module number is valid. More...
 
static bool CheckDigitalChannel (int channel)
 Check that the digital channel number is valid. More...
 
static bool CheckRelayChannel (int channel)
 Check that the relay channel number is valid. More...
 
static bool CheckPWMChannel (int channel)
 Check that the digital channel number is valid. More...
 
static bool CheckAnalogInputChannel (int channel)
 Check that the analog input number is value. More...
 
static bool CheckAnalogOutputChannel (int channel)
 Check that the analog output number is valid. More...
 
static bool CheckSolenoidChannel (int channel)
 Verify that the solenoid channel number is within limits. More...
 
static bool CheckPDPChannel (int channel)
 Verify that the power distribution channel number is within limits. More...
 
- Static Public Member Functions inherited from frc::ErrorBase
static void SetGlobalError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (llvm::StringRef errorMessage, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber)
 
static ErrorGetGlobalError ()
 Retrieve the current global error.
 

Static Public Attributes

static const int kJoystickPorts = 6
 
- Static Public Attributes inherited from frc::SensorBase
static const int kDigitalChannels = HAL_GetNumDigitalChannels()
 
static const int kAnalogInputs = HAL_GetNumAnalogInputs()
 
static const int kAnalogOutputs
 
static const int kSolenoidChannels = HAL_GetNumSolenoidChannels()
 
static const int kSolenoidModules = HAL_GetNumPCMModules()
 
static const int kPwmChannels = HAL_GetNumPWMChannels()
 
static const int kRelayChannels = HAL_GetNumRelayHeaders()
 
static const int kPDPChannels = HAL_GetNumPDPChannels()
 

Protected Member Functions

void GetData ()
 Copy data from the DS task for the user. More...
 

Additional Inherited Members

- Protected Attributes inherited from frc::ErrorBase
Error m_error
 
- Static Protected Attributes inherited from frc::ErrorBase
static hal::priority_mutex _globalErrorMutex
 
static Error _globalError
 

Detailed Description

Provide access to the network communication data to / from the Driver Station.

Member Function Documentation

DriverStation::Alliance DriverStation::GetAlliance ( ) const

Return the alliance that the driver station says it is on.

This could return kRed or kBlue.

Returns
The Alliance enum (kRed, kBlue or kInvalid)
double DriverStation::GetBatteryVoltage ( ) const

Read the battery voltage.

Returns
The battery voltage in Volts.
void DriverStation::GetData ( )
protected

Copy data from the DS task for the user.

If no new data exists, it will just be returned, otherwise the data will be copied from the DS polling loop.

DriverStation & DriverStation::GetInstance ( )
static

Return a pointer to the singleton DriverStation.

Returns
Pointer to the DS instance
int DriverStation::GetJoystickAxisType ( int  stick,
int  axis 
) const

Returns the types of Axes on a given joystick port.

Parameters
stickThe joystick port number and the target axis
Returns
What type of axis the axis is reporting to be
bool DriverStation::GetJoystickIsXbox ( int  stick) const

Returns a boolean indicating if the controller is an xbox controller.

Parameters
stickThe joystick port number
Returns
A boolean that is true if the controller is an xbox controller.
std::string DriverStation::GetJoystickName ( int  stick) const

Returns the name of the joystick at the given port.

Parameters
stickThe joystick port number
Returns
The name of the joystick at the given port
int DriverStation::GetJoystickType ( int  stick) const

Returns the type of joystick at a given port.

Parameters
stickThe joystick port number
Returns
The HID type of joystick at the given port
int DriverStation::GetLocation ( ) const

Return the driver station location on the field.

This could return 1, 2, or 3.

Returns
The location of the driver station (1-3, 0 for invalid)
double DriverStation::GetMatchTime ( ) const

Return the approximate match time.

The FMS does not send an official match time to the robots, but does send an approximate match time. The value will count down the time remaining in the current period (auto or teleop).

Warning: This is not an official time (so it cannot be used to dispute ref calls or guarantee that a function will trigger before the match ends).

The Practice Match function of the DS approximates the behaviour seen on the field.

Returns
Time remaining in current match period (auto or teleop)
double DriverStation::GetStickAxis ( int  stick,
int  axis 
)

Get the value of the axis on a joystick.

This depends on the mapping of the joystick connected to the specified port.

Parameters
stickThe joystick to read.
axisThe analog axis value to read from the joystick.
Returns
The value of the axis on the joystick.
int DriverStation::GetStickAxisCount ( int  stick) const

Returns the number of axes on a given joystick port.

Parameters
stickThe joystick port number
Returns
The number of axes on the indicated joystick
bool DriverStation::GetStickButton ( int  stick,
int  button 
)

The state of one joystick button.

Button indexes begin at 1.

Parameters
stickThe joystick to read.
buttonThe button index, beginning at 1.
Returns
The state of the joystick button.
int DriverStation::GetStickButtonCount ( int  stick) const

Returns the number of buttons on a given joystick port.

Parameters
stickThe joystick port number
Returns
The number of buttons on the indicated joystick
int DriverStation::GetStickButtons ( int  stick) const

The state of the buttons on the joystick.

Parameters
stickThe joystick to read.
Returns
The state of the buttons on the joystick.
int DriverStation::GetStickPOV ( int  stick,
int  pov 
)

Get the state of a POV on the joystick.

Returns
the angle of the POV in degrees, or -1 if the POV is not pressed.
int DriverStation::GetStickPOVCount ( int  stick) const

Returns the number of POVs on a given joystick port.

Parameters
stickThe joystick port number
Returns
The number of POVs on the indicated joystick
void frc::DriverStation::InAutonomous ( bool  entering)
inline

Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.

Parameters
enteringIf true, starting autonomous code; if false, leaving autonomous code
void frc::DriverStation::InDisabled ( bool  entering)
inline

Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.

Parameters
enteringIf true, starting disabled code; if false, leaving disabled code
void frc::DriverStation::InOperatorControl ( bool  entering)
inline

Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.

Parameters
enteringIf true, starting teleop code; if false, leaving teleop code
void frc::DriverStation::InTest ( bool  entering)
inline

Only to be used to tell the Driver Station what code you claim to be executing for diagnostic purposes only.

Parameters
enteringIf true, starting test code; if false, leaving test code
bool DriverStation::IsAutonomous ( ) const
overridevirtual

Check if the DS is commanding autonomous mode.

Returns
True if the robot is being commanded to be in autonomous mode

Implements frc::RobotStateInterface.

bool DriverStation::IsBrownedOut ( ) const

Check if the system is browned out.

Returns
True if the system is browned out
bool DriverStation::IsDisabled ( ) const
overridevirtual

Check if the robot is disabled.

Returns
True if the robot is explicitly disabled or the DS is not connected

Implements frc::RobotStateInterface.

bool DriverStation::IsDSAttached ( ) const

Check if the DS is attached.

Returns
True if the DS is connected to the robot
bool DriverStation::IsEnabled ( ) const
overridevirtual

Check if the DS has enabled the robot.

Returns
True if the robot is enabled and the DS is connected

Implements frc::RobotStateInterface.

bool DriverStation::IsFMSAttached ( ) const

Is the driver station attached to a Field Management System?

Returns
True if the robot is competing on a field being controlled by a Field Management System
bool DriverStation::IsNewControlData ( ) const

Has a new control packet from the driver station arrived since the last time this function was called?

Warning: If you call this function from more than one place at the same time, you will not get the intended behavior.

Returns
True if the control data has been updated since the last call.
bool DriverStation::IsOperatorControl ( ) const
overridevirtual

Check if the DS is commanding teleop mode.

Returns
True if the robot is being commanded to be in teleop mode

Implements frc::RobotStateInterface.

bool DriverStation::IsSysActive ( ) const

Check if the FPGA outputs are enabled.

The outputs may be disabled if the robot is disabled or e-stopped, the watchdog has expired, or if the roboRIO browns out.

Returns
True if the FPGA outputs are enabled.
bool DriverStation::IsTest ( ) const
overridevirtual

Check if the DS is commanding test mode.

Returns
True if the robot is being commanded to be in test mode

Implements frc::RobotStateInterface.

void DriverStation::ReportError ( llvm::StringRef  error)
static

Report an error to the DriverStation messages window.

The error is also printed to the program console.

void DriverStation::ReportWarning ( llvm::StringRef  error)
static

Report a warning to the DriverStation messages window.

The warning is also printed to the program console.

void DriverStation::WaitForData ( )

Wait until a new packet comes from the driver station.

This blocks on a semaphore, so the waiting is efficient.

This is a good way to delay processing until there is new driver station data to act on.

bool DriverStation::WaitForData ( double  timeout)

Wait until a new packet comes from the driver station, or wait for a timeout.

If the timeout is less then or equal to 0, wait indefinitely.

Timeout is in milliseconds

This blocks on a semaphore, so the waiting is efficient.

This is a good way to delay processing until there is new driver station data to act on.

Parameters
timeoutTimeout time in seconds
Returns
true if new data, otherwise false

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