WPILibC++  2019.3.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
frc::Joystick Class Reference

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

#include <Joystick.h>

Inheritance diagram for frc::Joystick:
frc::GenericHID frc::ErrorBase

Public Types

enum  AxisType {
  kXAxis, kYAxis, kZAxis, kTwistAxis,
  kThrottleAxis
}
 
enum  ButtonType { kTriggerButton, kTopButton }
 
- 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 (Joystick &&)=default
 
Joystickoperator= (Joystick &&)=default
 
void SetXChannel (int channel)
 Set the channel associated with the X axis. More...
 
void SetYChannel (int channel)
 Set the channel associated with the Y axis. More...
 
void SetZChannel (int channel)
 Set the channel associated with the Z axis. More...
 
void SetTwistChannel (int channel)
 Set the channel associated with the twist axis. More...
 
void SetThrottleChannel (int channel)
 Set the channel associated with the throttle axis. More...
 
void SetAxisChannel (AxisType axis, int channel)
 Set the channel associated with a specified axis. More...
 
int GetXChannel () const
 Get the channel currently associated with the X axis. More...
 
int GetYChannel () const
 Get the channel currently associated with the Y axis. More...
 
int GetZChannel () const
 Get the channel currently associated with the Z axis. More...
 
int GetTwistChannel () const
 Get the channel currently associated with the twist axis. More...
 
int GetThrottleChannel () const
 Get the channel currently associated with the throttle 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 () const
 Get the Z value of the current joystick. More...
 
double GetTwist () const
 Get the twist value of the current joystick. More...
 
double GetThrottle () const
 Get the throttle value of the current joystick. More...
 
double GetAxis (AxisType axis) const
 For the current joystick, return the axis determined by the argument. More...
 
bool GetTrigger () const
 Read the state of the trigger on the joystick. More...
 
bool GetTriggerPressed ()
 Whether the trigger was pressed since the last check. More...
 
bool GetTriggerReleased ()
 Whether the trigger was released since the last check. More...
 
bool GetTop () const
 Read the state of the top button on the joystick. More...
 
bool GetTopPressed ()
 Whether the top button was pressed since the last check. More...
 
bool GetTopReleased ()
 Whether the top button was released since the last check. More...
 
bool GetButton (ButtonType button) const
 Get buttons based on an enumerated type. More...
 
double GetMagnitude () const
 Get the magnitude of the direction vector formed by the joystick's current position relative to its origin. More...
 
double GetDirectionRadians () const
 Get the direction of the vector formed by the joystick and its origin in radians. More...
 
double GetDirectionDegrees () const
 Get the direction of the vector formed by the joystick and its origin in degrees. More...
 
- Public Member Functions inherited from frc::GenericHID
 GenericHID (int port)
 
 GenericHID (GenericHID &&)=default
 
GenericHIDoperator= (GenericHID &&)=default
 
bool GetRawButton (int button) const
 Get the button value (starting at button 1). More...
 
bool GetRawButtonPressed (int button)
 Whether the button was pressed since the last check. More...
 
bool GetRawButtonReleased (int button)
 Whether the button was released since the last check. More...
 
double GetRawAxis (int axis) const
 Get the value of the axis. More...
 
int GetPOV (int pov=0) const
 Get the angle in degrees of a POV on the HID. More...
 
int GetAxisCount () const
 Get the number of axes for the HID. More...
 
int GetPOVCount () const
 Get the number of POVs for the HID. More...
 
int GetButtonCount () const
 Get the number of buttons for 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...
 
int GetAxisType (int axis) const
 Get the axis type of a joystick axis. More...
 
int GetPort () const
 Get the port number 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 (ErrorBase &&)=default
 
ErrorBaseoperator= (ErrorBase &&)=default
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 Retrieve the current error. More...
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual void SetErrnoError (const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::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, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::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, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const wpi::Twine &errorMessage, Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
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, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (const wpi::Twine &errorMessage, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static const ErrorGetGlobalError ()
 Retrieve the current global error.
 

Static Public Attributes

static constexpr int kDefaultXChannel = 0
 
static constexpr int kDefaultYChannel = 1
 
static constexpr int kDefaultZChannel = 2
 
static constexpr int kDefaultTwistChannel = 2
 
static constexpr int kDefaultThrottleChannel = 3
 
static constexpr int kDefaultXAxis = 0
 
static constexpr int kDefaultYAxis = 1
 
static constexpr int kDefaultZAxis = 2
 
static constexpr int kDefaultTwistAxis = 2
 
static constexpr int kDefaultThrottleAxis = 3
 

Additional Inherited Members

- Protected Attributes inherited from frc::ErrorBase
Error m_error
 

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

frc::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).

Member Function Documentation

double frc::Joystick::GetAxis ( AxisType  axis) const

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.
bool frc::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.
double frc::Joystick::GetDirectionDegrees ( ) const

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

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

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

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

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 frc::Joystick::GetThrottle ( ) const

Get the throttle value of the current joystick.

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

int frc::Joystick::GetThrottleChannel ( ) const

Get the channel currently associated with the throttle axis.

Returns
The channel for the axis.
bool frc::Joystick::GetTop ( ) const

Read the state of the top button on the joystick.

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

Returns
The state of the top button.
bool frc::Joystick::GetTopPressed ( )

Whether the top button was pressed since the last check.

Returns
Whether the button was pressed since the last check.
bool frc::Joystick::GetTopReleased ( )

Whether the top button was released since the last check.

Returns
Whether the button was released since the last check.
bool frc::Joystick::GetTrigger ( ) const

Read the state of the trigger on the joystick.

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

Returns
The state of the trigger.
bool frc::Joystick::GetTriggerPressed ( )

Whether the trigger was pressed since the last check.

Returns
Whether the button was pressed since the last check.
bool frc::Joystick::GetTriggerReleased ( )

Whether the trigger was released since the last check.

Returns
Whether the button was released since the last check.
double frc::Joystick::GetTwist ( ) const

Get the twist value of the current joystick.

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

int frc::Joystick::GetTwistChannel ( ) const

Get the channel currently associated with the twist axis.

Returns
The channel for the axis.
double frc::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.

int frc::Joystick::GetXChannel ( ) const

Get the channel currently associated with the X axis.

Returns
The channel for the axis.
double frc::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.

int frc::Joystick::GetYChannel ( ) const

Get the channel currently associated with the Y axis.

Returns
The channel for the axis.
double frc::Joystick::GetZ ( ) const

Get the Z value of the current joystick.

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

int frc::Joystick::GetZChannel ( ) const

Get the channel currently associated with the Z axis.

Returns
The channel for the axis.
void frc::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.
void frc::Joystick::SetThrottleChannel ( int  channel)

Set the channel associated with the throttle axis.

Parameters
axisThe axis to set the channel for.
channelThe channel to set the axis to.
void frc::Joystick::SetTwistChannel ( int  channel)

Set the channel associated with the twist axis.

Parameters
axisThe axis to set the channel for.
channelThe channel to set the axis to.
void frc::Joystick::SetXChannel ( int  channel)

Set the channel associated with the X axis.

Parameters
channelThe channel to set the axis to.
void frc::Joystick::SetYChannel ( int  channel)

Set the channel associated with the Y axis.

Parameters
axisThe axis to set the channel for.
channelThe channel to set the axis to.
void frc::Joystick::SetZChannel ( int  channel)

Set the channel associated with the Z 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 file: