Classes | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
mvsim::Joystick Class Reference

#include <Joystick.h>

Classes

struct  State
 

Public Member Functions

bool getJoystickPosition (int nJoy, State &output)
 
 Joystick ()
 
void setLimits (const std::vector< int > &minPerAxis, const std::vector< int > &maxPerAxis)
 
virtual ~Joystick ()
 

Static Public Member Functions

static int getJoysticksCount ()
 

Private Attributes

std::vector< int > m_maxPerAxis
 
std::vector< int > m_minPerAxis
 

Detailed Description

Access to joysticks and gamepads (read buttons and position), and request number of joysticks in the system.

Note
New in MRPT 2.13.0: the API changed to support an arbitrary number of input axes.

Definition at line 39 of file Joystick.h.

Constructor & Destructor Documentation

◆ Joystick()

Joystick::Joystick ( )
default

Constructor

◆ ~Joystick()

Joystick::~Joystick ( )
virtual

Destructor

Definition at line 63 of file Joystick.cpp.

Member Function Documentation

◆ getJoystickPosition()

bool Joystick::getJoystickPosition ( int  nJoy,
State output 
)

Gets joystick information.

This method will try first to open the joystick, so you can safely call it while the joystick is plugged and removed arbitrarly.

Parameters
nJoyThe index of the joystick to query: The first one is 0, the second 1, etc... See CJoystick::getJoysticksCount to discover the number of joysticks in the system.
xThe x axis position, range [-1,1]
yThe y axis position, range [-1,1]
zThe z axis position, range [-1,1]
buttonsEach element will hold true if buttons are pressed. The size of the vector will be set automatically to the number of buttons.
raw_x_posIf it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder.
raw_y_posIf it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder.
raw_z_posIf it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder.
Returns
Returns true if successfull, false on error, for example, if joystick is not present.
See also
setLimits

Definition at line 112 of file Joystick.cpp.

◆ getJoysticksCount()

int Joystick::getJoysticksCount ( )
static

Returns the number of Joysticks in the computer.

Definition at line 79 of file Joystick.cpp.

◆ setLimits()

void Joystick::setLimits ( const std::vector< int > &  minPerAxis,
const std::vector< int > &  maxPerAxis 
)

Set the axis limit values, for computing a [-1,1] position index easily Only required to calibrate analog joystick. It seems that these values must been calibrated for each joystick model.

Default values:

  • Windows: [0, 0xFFFF]
  • Linux: [-32767,32767]
See also
getJoystickPosition

Definition at line 230 of file Joystick.cpp.

Member Data Documentation

◆ m_maxPerAxis

std::vector<int> mvsim::Joystick::m_maxPerAxis
private

Definition at line 43 of file Joystick.h.

◆ m_minPerAxis

std::vector<int> mvsim::Joystick::m_minPerAxis
private

The axis limits for normalization.

Definition at line 43 of file Joystick.h.


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


mvsim
Author(s):
autogenerated on Wed May 28 2025 02:13:09