WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Joystick Class Reference

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

#include <Joystick.h>

Inheritance diagram for Joystick:
GenericHID ErrorBase

Public Types

enum  AxisType {
  kXAxis, kYAxis, kZAxis, kTwistAxis,
  kThrottleAxis, kNumAxisTypes
}
 
enum  ButtonType { kTriggerButton, kTopButton, kNumButtonTypes }
 
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
}
 
- Public Types inherited from GenericHID
enum  JoystickHand { kLeftHand = 0, kRightHand = 1 }
 

Public Member Functions

 Joystick (uint32_t port)
 Construct an instance of a joystick. More...
 
 Joystick (uint32_t port, uint32_t numAxisTypes, uint32_t numButtonTypes)
 Version of the constructor to be called by sub-classes. More...
 
 Joystick (const Joystick &)=delete
 
Joystickoperator= (const Joystick &)=delete
 
uint32_t GetAxisChannel (AxisType axis) const
 Get the channel currently associated with the specified axis. More...
 
void SetAxisChannel (AxisType axis, uint32_t channel)
 Set the channel associated with a specified axis. More...
 
virtual float GetX (JoystickHand hand=kRightHand) const override
 Get the X value of the joystick. More...
 
virtual float GetY (JoystickHand hand=kRightHand) const override
 Get the Y value of the joystick. More...
 
virtual float GetZ () const override
 Get the Z value of the current joystick. More...
 
virtual float GetTwist () const override
 Get the twist value of the current joystick. More...
 
virtual float GetThrottle () const override
 Get the throttle value of the current joystick. More...
 
virtual float GetAxis (AxisType axis) const
 For the current joystick, return the axis determined by the argument. More...
 
float GetRawAxis (uint32_t axis) const override
 Get the value of the axis. More...
 
virtual bool GetTrigger (JoystickHand hand=kRightHand) const override
 Read the state of the trigger on the joystick. More...
 
virtual bool GetTop (JoystickHand hand=kRightHand) const override
 Read the state of the top button on the joystick. More...
 
virtual bool GetBumper (JoystickHand hand=kRightHand) const override
 This is not supported for the Joystick. More...
 
virtual bool GetRawButton (uint32_t button) const override
 Get the button value (starting at button 1) More...
 
virtual int GetPOV (uint32_t pov=0) const override
 Get the state of a POV on the joystick. More...
 
bool GetButton (ButtonType button) const
 Get buttons based on an enumerated type. More...
 
virtual float GetMagnitude () const
 Get the magnitude of the direction vector formed by the joystick's current position relative to its origin. More...
 
virtual float GetDirectionRadians () const
 Get the direction of the vector formed by the joystick and its origin in radians. More...
 
virtual float GetDirectionDegrees () const
 Get the direction of the vector formed by the joystick and its origin in degrees. More...
 
bool GetIsXbox () const
 Get the value of isXbox for the joystick. More...
 
Joystick::HIDType GetType () const
 Get the HID type of the controller. More...
 
std::string GetName () const
 Get the name of the joystick. More...
 
int GetAxisType (uint8_t axis) const
 
int GetAxisCount () const
 Get the number of axis for a joystick. More...
 
int GetButtonCount () const
 Get the number of axis for a joystick. More...
 
int GetPOVCount () const
 Get the number of axis for a joystick. More...
 
void SetRumble (RumbleType type, float value)
 Set the rumble output for the joystick. More...
 
void SetOutput (uint8_t outputNumber, bool value)
 Set a single HID output value for the joystick. More...
 
void SetOutputs (uint32_t value)
 Set all HID output values for the joystick. More...
 
- Public Member Functions inherited from 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, uint32_t 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, uint32_t 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, uint32_t 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, uint32_t 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 (uint32_t port)
 
- Static Public Member Functions inherited from ErrorBase
static void SetGlobalError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber)
 
static void SetGlobalWPIError (llvm::StringRef errorMessage, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber)
 
static ErrorGetGlobalError ()
 Retrieve the current global error.
 

Static Public Attributes

static const uint32_t kDefaultXAxis = 0
 
static const uint32_t kDefaultYAxis = 1
 
static const uint32_t kDefaultZAxis = 2
 
static const uint32_t kDefaultTwistAxis = 2
 
static const uint32_t kDefaultThrottleAxis = 3
 
static const uint32_t kDefaultTriggerButton = 1
 
static const uint32_t kDefaultTopButton = 2
 

Additional Inherited Members

- Protected Attributes inherited from ErrorBase
Error m_error
 
- Static Protected Attributes inherited from ErrorBase
static priority_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 ( uint32_t  port)
explicit

Construct an instance of a joystick.

The joystick index is the usb port on the drivers station.

Parameters
portThe port on the driver station that the joystick is plugged into (0-5).
Joystick::Joystick ( uint32_t  port,
uint32_t  numAxisTypes,
uint32_t  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

float 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.
uint32_t 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
bool Joystick::GetBumper ( JoystickHand  hand = kRightHand) const
overridevirtual

This is not supported for the Joystick.

This method is only here to complete the GenericHID interface.

Implements GenericHID.

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 axis for a joystick.

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

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

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

Returns
The direction of the vector in degrees
float 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
bool Joystick::GetIsXbox ( ) const

Get the value of isXbox for the joystick.

Returns
A boolean that is true if the joystick is an xbox controller.
float 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
std::string Joystick::GetName ( ) const

Get the name of the joystick.

Returns
the name of the controller.
int Joystick::GetPOV ( uint32_t  pov = 0) const
overridevirtual

Get the state of a POV on the joystick.

Parameters
povThe index of the POV to read (starting at 0)
Returns
the angle of the POV in degrees, or -1 if the POV is not pressed.

Implements GenericHID.

int Joystick::GetPOVCount ( ) const

Get the number of axis for a joystick.

Returns
then umber of POVs for the current joystick
float Joystick::GetRawAxis ( uint32_t  axis) const
overridevirtual

Get the value of the axis.

Parameters
axisThe axis to read, starting at 0.
Returns
The value of the axis.

Implements GenericHID.

bool Joystick::GetRawButton ( uint32_t  button) const
overridevirtual

Get the button value (starting at button 1)

The buttons are returned in a single 16 bit value with one bit representing the state of each button. The appropriate button is returned as a boolean value.

Parameters
buttonThe button number to be read (starting at 1)
Returns
The state of the button.

Implements GenericHID.

float 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 GenericHID.

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 GenericHID.

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 GenericHID.

float 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 GenericHID.

Joystick::HIDType Joystick::GetType ( ) const

Get the HID type of the controller.

Returns
the HID type of the controller.
float 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 GenericHID.

float 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 GenericHID.

float Joystick::GetZ ( ) const
overridevirtual

Get the Z value of the current joystick.

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

Implements GenericHID.

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

Set the channel associated with a specified axis.

Parameters
axisThe axis to set the channel for.
channelThe channel to set the axis to.
void Joystick::SetOutput ( uint8_t  outputNumber,
bool  value 
)

Set a single HID output value for the joystick.

Parameters
outputNumberThe index of the output to set (1-32)
valueThe value to set the output to
void Joystick::SetOutputs ( uint32_t  value)

Set all HID output values for the joystick.

Parameters
valueThe 32 bit output value (1 bit for each output)
void Joystick::SetRumble ( RumbleType  type,
float  value 
)

Set the rumble output for the joystick.

The DS currently supports 2 rumble values, left rumble and right rumble

Parameters
typeWhich rumble value to set
valueThe normalized value (0 to 1) to set the rumble to

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