WPILibC++  unspecified
frc::Joystick Class Reference

Handle input from standard Joysticks connected to the Driver Station. More...

#include <Joystick.h>

Inheritance diagram for frc::Joystick:
Collaboration diagram for frc::Joystick:

Public Types

enum  AxisType {
  kXAxis, kYAxis, kZAxis, kTwistAxis,
  kThrottleAxis, kNumAxisTypes
}
 
enum  ButtonType { kTriggerButton, kTopButton, kNumButtonTypes }
 
- Public Types inherited from frc::GenericHID
enum  RumbleType { kLeftRumble, kRightRumble }
 
enum  HIDType {
  kUnknown = -1, kXInputUnknown = 0, kXInputGamepad = 1, kXInputWheel = 2,
  kXInputArcadeStick = 3, kXInputFlightStick = 4, kXInputDancePad = 5, kXInputGuitar = 6,
  kXInputGuitar2 = 7, kXInputDrumKit = 8, kXInputGuitar3 = 11, kXInputArcadePad = 19,
  kHIDJoystick = 20, kHIDGamepad = 21, kHIDDriving = 22, kHIDFlight = 23,
  kHID1stPerson = 24
}
 
enum  JoystickHand { kLeftHand = 0, kRightHand = 1 }
 

Public Member Functions

 Joystick (int port)
 Construct an instance of a joystick. More...
 
 Joystick (int port, int numAxisTypes, int numButtonTypes)
 Version of the constructor to be called by sub-classes. More...
 
 Joystick (const Joystick &)=delete
 
Joystickoperator= (const Joystick &)=delete
 
int GetAxisChannel (AxisType axis) const
 Get the channel currently associated with the specified axis. More...
 
void SetAxisChannel (AxisType axis, int channel)
 Set the channel associated with a specified axis. More...
 
double GetX (JoystickHand hand=kRightHand) const override
 Get the X value of the joystick. More...
 
double GetY (JoystickHand hand=kRightHand) const override
 Get the Y value of the joystick. More...
 
double GetZ (JoystickHand hand=kRightHand) const override
 Get the Z value of the current joystick. More...
 
double GetTwist () const override
 Get the twist value of the current joystick. More...
 
double GetThrottle () const override
 Get the throttle value of the current joystick. More...
 
virtual double GetAxis (AxisType axis) const
 For the current joystick, return the axis determined by the argument. More...
 
bool GetTrigger (JoystickHand hand=kRightHand) const override
 Read the state of the trigger on the joystick. More...
 
bool GetTop (JoystickHand hand=kRightHand) const override
 Read the state of the top button on the joystick. More...
 
bool GetButton (ButtonType button) const
 Get buttons based on an enumerated type. More...
 
virtual double GetMagnitude () const
 Get the magnitude of the direction vector formed by the joystick's current position relative to its origin. More...
 
virtual double GetDirectionRadians () const
 Get the direction of the vector formed by the joystick and its origin in radians. More...
 
virtual double GetDirectionDegrees () const
 Get the direction of the vector formed by the joystick and its origin in degrees. More...
 
int GetAxisType (int axis) const
 Get the axis type of a joystick axis. More...
 
int GetAxisCount () const
 Get the number of axis for a joystick. More...
 
int GetButtonCount () const
 Get the number of buttons for a joystick. More...
 
- Public Member Functions inherited from frc::JoystickBase
 JoystickBase (int port)
 
- Public Member Functions inherited from frc::GenericHID
 GenericHID (int port)
 
virtual double GetRawAxis (int axis) const
 Get the value of the axis. More...
 
bool GetRawButton (int button) const
 Get the button value (starting at button 1) More...
 
int GetPOV (int pov=0) const
 Get the angle in degrees of a POV on the HID. More...
 
int GetPOVCount () const
 Get the number of POVs for the HID. More...
 
int GetPort () const
 Get the port number of the HID. More...
 
GenericHID::HIDType GetType () const
 Get the type of the HID. More...
 
std::string GetName () const
 Get the name of the HID. More...
 
void SetOutput (int outputNumber, bool value)
 Set a single HID output value for the HID. More...
 
void SetOutputs (int value)
 Set all output values for the HID. More...
 
void SetRumble (RumbleType type, double value)
 Set the rumble output for the HID. More...
 
- 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 JoystickGetStickForPort (int port)
 
- 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 kDefaultXAxis = 0
 
static const int kDefaultYAxis = 1
 
static const int kDefaultZAxis = 2
 
static const int kDefaultTwistAxis = 2
 
static const int kDefaultThrottleAxis = 3
 
static const int kDefaultTriggerButton = 1
 
static const int kDefaultTopButton = 2
 

Additional Inherited Members

- Protected Attributes inherited from frc::ErrorBase
Error m_error
 
- Static Protected Attributes inherited from frc::ErrorBase
static std::mutex _globalErrorMutex
 
static Error _globalError
 

Detailed Description

Handle input from standard Joysticks connected to the Driver Station.

This class handles standard input that comes from the Driver Station. Each time a value is requested the most recent value is returned. There is a single class instance for each joystick and the mapping of ports to hardware buttons depends on the code in the Driver Station.

Constructor & Destructor Documentation

Joystick::Joystick ( int  port)
explicit

Construct an instance of a joystick.

The joystick index is the USB port on the Driver Station.

Parameters
portThe port on the Driver Station that the joystick is plugged into (0-5).
Joystick::Joystick ( int  port,
int  numAxisTypes,
int  numButtonTypes 
)

Version of the constructor to be called by sub-classes.

This constructor allows the subclass to configure the number of constants for axes and buttons.

Parameters
portThe port on the Driver Station that the joystick is plugged into.
numAxisTypesThe number of axis types in the enum.
numButtonTypesThe number of button types in the enum.

Member Function Documentation

double Joystick::GetAxis ( AxisType  axis) const
virtual

For the current joystick, return the axis determined by the argument.

This is for cases where the joystick axis is returned programatically, otherwise one of the previous functions would be preferable (for example GetX()).

Parameters
axisThe axis to read.
Returns
The value of the axis.
int Joystick::GetAxisChannel ( AxisType  axis) const

Get the channel currently associated with the specified axis.

Parameters
axisThe axis to look up the channel for.
Returns
The channel fr the axis.
int Joystick::GetAxisCount ( ) const

Get the number of axis for a joystick.

Returns
the number of axis for the current joystick
int Joystick::GetAxisType ( int  axis) const

Get the axis type of a joystick axis.

Returns
the axis type of a joystick axis.
bool Joystick::GetButton ( ButtonType  button) const

Get buttons based on an enumerated type.

The button type will be looked up in the list of buttons and then read.

Parameters
buttonThe type of button to read.
Returns
The state of the button.
int Joystick::GetButtonCount ( ) const

Get the number of buttons for a joystick.

Returns
the number of buttons on the current joystick
double Joystick::GetDirectionDegrees ( ) const
virtual

Get the direction of the vector formed by the joystick and its origin in degrees.

uses std::acos(-1) to represent Pi due to absence of readily accessible Pi constant in C++

Returns
The direction of the vector in degrees
double Joystick::GetDirectionRadians ( ) const
virtual

Get the direction of the vector formed by the joystick and its origin in radians.

Returns
The direction of the vector in radians
double Joystick::GetMagnitude ( ) const
virtual

Get the magnitude of the direction vector formed by the joystick's current position relative to its origin.

Returns
The magnitude of the direction vector
double Joystick::GetThrottle ( ) const
overridevirtual

Get the throttle value of the current joystick.

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

Implements frc::JoystickBase.

bool Joystick::GetTop ( JoystickHand  hand = kRightHand) const
overridevirtual

Read the state of the top button on the joystick.

Look up which button has been assigned to the top and read its state.

Parameters
handThis parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.
Returns
The state of the top button.

Implements frc::JoystickBase.

bool Joystick::GetTrigger ( JoystickHand  hand = kRightHand) const
overridevirtual

Read the state of the trigger on the joystick.

Look up which button has been assigned to the trigger and read its state.

Parameters
handThis parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.
Returns
The state of the trigger.

Implements frc::JoystickBase.

double Joystick::GetTwist ( ) const
overridevirtual

Get the twist value of the current joystick.

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

Implements frc::JoystickBase.

double Joystick::GetX ( JoystickHand  hand = kRightHand) const
overridevirtual

Get the X value of the joystick.

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

Parameters
handThis parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.

Implements frc::GenericHID.

double Joystick::GetY ( JoystickHand  hand = kRightHand) const
overridevirtual

Get the Y value of the joystick.

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

Parameters
handThis parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.

Implements frc::GenericHID.

double Joystick::GetZ ( JoystickHand  hand = kRightHand) const
overridevirtual

Get the Z value of the current joystick.

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

Implements frc::JoystickBase.

void Joystick::SetAxisChannel ( AxisType  axis,
int  channel 
)

Set the channel associated with a specified axis.

Parameters
axisThe axis to set the channel for.
channelThe channel to set the axis to.

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