WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::Joystick Class Reference

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

#include <wpi/driverstation/Joystick.hpp>

Inheritance diagram for wpi::Joystick:
wpi::GenericHID

Public Types

enum  AxisType {
  kXAxis , kYAxis , kZAxis , kTwistAxis ,
  kThrottleAxis
}
 Represents an analog axis on a joystick. More...
enum  ButtonType { kTriggerButton , kTopButton }
 Represents a digital button on a joystick. More...
Public Types inherited from wpi::GenericHID
enum  RumbleType { kLeftRumble , kRightRumble , kLeftTriggerRumble , kRightTriggerRumble }
 Represents a rumble output on the Joystick. More...
enum  SupportedOutputs {
  kNone = 0x0 , kMonoLed = 0x1 , kRgbLed = 0x2 , kPlayerLed = 0x4 ,
  kRumble = 0x8 , kTriggerRumble = 0x10
}
 Represents the various outputs that a HID may support. More...
enum  HIDType {
  kUnknown = 0 , kStandard , kXbox360 , kXboxOne ,
  kPS3 , kPS4 , kPS5 , kSwitchPro ,
  kSwitchJoyconLeft , kSwitchJoyconRight , kSwitchJoyconPair
}
 USB HID interface type. More...

Public Member Functions

 Joystick (int port)
 Construct an instance of a joystick.
 ~Joystick () override=default
 Joystick (Joystick &&)=default
Joystickoperator= (Joystick &&)=default
void SetXChannel (int channel)
 Set the channel associated with the X axis.
void SetYChannel (int channel)
 Set the channel associated with the Y axis.
void SetZChannel (int channel)
 Set the channel associated with the Z axis.
void SetTwistChannel (int channel)
 Set the channel associated with the twist axis.
void SetThrottleChannel (int channel)
 Set the channel associated with the throttle axis.
int GetXChannel () const
 Get the channel currently associated with the X axis.
int GetYChannel () const
 Get the channel currently associated with the Y axis.
int GetZChannel () const
 Get the channel currently associated with the Z axis.
int GetTwistChannel () const
 Get the channel currently associated with the twist axis.
int GetThrottleChannel () const
 Get the channel currently associated with the throttle axis.
double GetX () const
 Get the X value of the current joystick.
double GetY () const
 Get the Y value of the current joystick.
double GetZ () const
 Get the Z value of the current joystick.
double GetTwist () const
 Get the twist value of the current joystick.
double GetThrottle () const
 Get the throttle value of the current joystick.
bool GetTrigger () const
 Read the state of the trigger on the joystick.
bool GetTriggerPressed ()
 Whether the trigger was pressed since the last check.
bool GetTriggerReleased ()
 Whether the trigger was released since the last check.
BooleanEvent Trigger (EventLoop *loop) const
 Constructs an event instance around the trigger button's digital signal.
bool GetTop () const
 Read the state of the top button on the joystick.
bool GetTopPressed ()
 Whether the top button was pressed since the last check.
bool GetTopReleased ()
 Whether the top button was released since the last check.
BooleanEvent Top (EventLoop *loop) const
 Constructs an event instance around the top button's digital signal.
double GetMagnitude () const
 Get the magnitude of the vector formed by the joystick's current position relative to its origin.
wpi::units::radian_t GetDirection () const
 Get the direction of the vector formed by the joystick and its origin.
Public Member Functions inherited from wpi::GenericHID
 GenericHID (int port)
virtual ~GenericHID ()=default
 GenericHID (GenericHID &&)=default
GenericHIDoperator= (GenericHID &&)=default
bool GetRawButton (int button) const
 Get the button value (starting at button 1).
bool GetRawButtonPressed (int button)
 Whether the button was pressed since the last check.
bool GetRawButtonReleased (int button)
 Whether the button was released since the last check.
BooleanEvent Button (int button, EventLoop *loop) const
 Constructs an event instance around this button's digital signal.
double GetRawAxis (int axis) const
 Get the value of the axis.
DriverStation::POVDirection GetPOV (int pov=0) const
 Get the angle of a POV on the HID.
BooleanEvent POV (DriverStation::POVDirection angle, EventLoop *loop) const
 Constructs a BooleanEvent instance based around this angle of a POV on the HID.
BooleanEvent POV (int pov, DriverStation::POVDirection angle, EventLoop *loop) const
 Constructs a BooleanEvent instance based around this angle of a POV on the HID.
BooleanEvent POVUp (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the up direction of the default (index 0) POV on the HID.
BooleanEvent POVUpRight (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the up right direction of the default (index 0) POV on the HID.
BooleanEvent POVRight (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the right direction of the default (index 0) POV on the HID.
BooleanEvent POVDownRight (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the down right direction of the default (index 0) POV on the HID.
BooleanEvent POVDown (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the down direction of the default (index 0) POV on the HID.
BooleanEvent POVDownLeft (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the down left direction of the default (index 0) POV on the HID.
BooleanEvent POVLeft (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the left direction of the default (index 0) POV on the HID.
BooleanEvent POVUpLeft (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the up left direction of the default (index 0) POV on the HID.
BooleanEvent POVCenter (EventLoop *loop) const
 Constructs a BooleanEvent instance based around the center (not pressed) of the default (index 0) POV on the HID.
BooleanEvent AxisLessThan (int axis, double threshold, EventLoop *loop) const
 Constructs an event instance that is true when the axis value is less than threshold.
BooleanEvent AxisGreaterThan (int axis, double threshold, EventLoop *loop) const
 Constructs an event instance that is true when the axis value is greater than threshold.
int GetAxesMaximumIndex () const
int GetAxesAvailable () const
 Get the number of axes for the HID.
int GetPOVsMaximumIndex () const
int GetPOVsAvailable () const
 Get the number of POVs for the HID.
int GetButtonsMaximumIndex () const
uint64_t GetButtonsAvailable () const
 Get the number of buttons for the HID.
bool IsConnected () const
 Get if the HID is connected.
GenericHID::HIDType GetGamepadType () const
 Get the type of the HID.
GenericHID::SupportedOutputs GetSupportedOutputs () const
 Get the supported outputs of the HID.
std::string GetName () const
 Get the name of the HID.
int GetPort () const
 Get the port number of the HID.
void SetLeds (int r, int g, int b)
 Set leds on the controller.
void SetRumble (RumbleType type, double value)
 Set the rumble output for the HID.
bool GetTouchpadFingerAvailable (int touchpad, int finger) const
 Check if a touchpad finger is available.
DriverStation::TouchpadFinger GetTouchpadFinger (int touchpad, int finger) const
 Get the touchpad finger data.

Static Public Attributes

static constexpr int kDefaultXChannel = 0
 Default X axis channel.
static constexpr int kDefaultYChannel = 1
 Default Y axis channel.
static constexpr int kDefaultZChannel = 2
 Default Z axis channel.
static constexpr int kDefaultTwistChannel = 2
 Default twist axis channel.
static constexpr int kDefaultThrottleChannel = 3
 Default throttle axis channel.

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.

Member Enumeration Documentation

◆ AxisType

Represents an analog axis on a joystick.

Enumerator
kXAxis 

X axis.

kYAxis 

Y axis.

kZAxis 

Z axis.

kTwistAxis 

Twist axis.

kThrottleAxis 

Throttle axis.

◆ ButtonType

Represents a digital button on a joystick.

Enumerator
kTriggerButton 

kTrigger.

kTopButton 

kTop.

Constructor & Destructor Documentation

◆ Joystick() [1/2]

wpi::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()

wpi::Joystick::~Joystick ( )
overridedefault

◆ Joystick() [2/2]

wpi::Joystick::Joystick ( Joystick && )
default

Member Function Documentation

◆ GetDirection()

wpi::units::radian_t wpi::Joystick::GetDirection ( ) const

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

0 is forward and clockwise is positive. (Straight right is π/2 radians or 90 degrees.)

Returns
The direction of the vector.

◆ GetMagnitude()

double wpi::Joystick::GetMagnitude ( ) const

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

Returns
The magnitude of the direction vector

◆ GetThrottle()

double wpi::Joystick::GetThrottle ( ) const

Get the throttle value of the current joystick.

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

◆ GetThrottleChannel()

int wpi::Joystick::GetThrottleChannel ( ) const

Get the channel currently associated with the throttle axis.

Returns
The channel for the axis.

◆ GetTop()

bool wpi::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.

◆ GetTopPressed()

bool wpi::Joystick::GetTopPressed ( )

Whether the top button was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetTopReleased()

bool wpi::Joystick::GetTopReleased ( )

Whether the top button was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetTrigger()

bool wpi::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.

◆ GetTriggerPressed()

bool wpi::Joystick::GetTriggerPressed ( )

Whether the trigger was pressed since the last check.

Returns
Whether the button was pressed since the last check.

◆ GetTriggerReleased()

bool wpi::Joystick::GetTriggerReleased ( )

Whether the trigger was released since the last check.

Returns
Whether the button was released since the last check.

◆ GetTwist()

double wpi::Joystick::GetTwist ( ) const

Get the twist value of the current joystick.

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

◆ GetTwistChannel()

int wpi::Joystick::GetTwistChannel ( ) const

Get the channel currently associated with the twist axis.

Returns
The channel for the axis.

◆ GetX()

double wpi::Joystick::GetX ( ) const

Get the X value of the current joystick.

This depends on the mapping of the joystick connected to the current port. On most joysticks, positive is to the right.

◆ GetXChannel()

int wpi::Joystick::GetXChannel ( ) const

Get the channel currently associated with the X axis.

Returns
The channel for the axis.

◆ GetY()

double wpi::Joystick::GetY ( ) const

Get the Y value of the current joystick.

This depends on the mapping of the joystick connected to the current port. On most joysticks, positive is to the back.

◆ GetYChannel()

int wpi::Joystick::GetYChannel ( ) const

Get the channel currently associated with the Y axis.

Returns
The channel for the axis.

◆ GetZ()

double wpi::Joystick::GetZ ( ) const

Get the Z value of the current joystick.

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

◆ GetZChannel()

int wpi::Joystick::GetZChannel ( ) const

Get the channel currently associated with the Z axis.

Returns
The channel for the axis.

◆ operator=()

Joystick & wpi::Joystick::operator= ( Joystick && )
default

◆ SetThrottleChannel()

void wpi::Joystick::SetThrottleChannel ( int channel)

Set the channel associated with the throttle axis.

Parameters
channelThe channel to set the axis to.

◆ SetTwistChannel()

void wpi::Joystick::SetTwistChannel ( int channel)

Set the channel associated with the twist axis.

Parameters
channelThe channel to set the axis to.

◆ SetXChannel()

void wpi::Joystick::SetXChannel ( int channel)

Set the channel associated with the X axis.

Parameters
channelThe channel to set the axis to.

◆ SetYChannel()

void wpi::Joystick::SetYChannel ( int channel)

Set the channel associated with the Y axis.

Parameters
channelThe channel to set the axis to.

◆ SetZChannel()

void wpi::Joystick::SetZChannel ( int channel)

Set the channel associated with the Z axis.

Parameters
channelThe channel to set the axis to.

◆ Top()

BooleanEvent wpi::Joystick::Top ( EventLoop * loop) const

Constructs an event instance around the top button's digital signal.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance representing the top button's digital signal attached to the given loop.

◆ Trigger()

BooleanEvent wpi::Joystick::Trigger ( EventLoop * loop) const

Constructs an event instance around the trigger button's digital signal.

Parameters
loopthe event loop instance to attach the event to.
Returns
an event instance representing the trigger button's digital signal attached to the given loop.

Member Data Documentation

◆ kDefaultThrottleChannel

int wpi::Joystick::kDefaultThrottleChannel = 3
staticconstexpr

Default throttle axis channel.

◆ kDefaultTwistChannel

int wpi::Joystick::kDefaultTwistChannel = 2
staticconstexpr

Default twist axis channel.

◆ kDefaultXChannel

int wpi::Joystick::kDefaultXChannel = 0
staticconstexpr

Default X axis channel.

◆ kDefaultYChannel

int wpi::Joystick::kDefaultYChannel = 1
staticconstexpr

Default Y axis channel.

◆ kDefaultZChannel

int wpi::Joystick::kDefaultZChannel = 2
staticconstexpr

Default Z axis channel.


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