Main MRPT website > C++ reference
MRPT logo
CJoystick.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CJOYSTICK_H
29 #define CJOYSTICK_H
30 
31 #include <mrpt/config.h>
32 #include <mrpt/utils/utils_defs.h>
34 
35 /*---------------------------------------------------------------
36  Class
37  ---------------------------------------------------------------*/
38 namespace mrpt
39 {
40  namespace hwdrivers
41  {
42  /** Access to joysticks and gamepads (read buttons and position), and request number of joysticks in the system.
43  * \ingroup mrpt_hwdrivers_grp
44  */
46  {
47  private:
48  /** The axis limits:
49  */
50  int m_x_min,m_x_max,m_y_min,m_y_max,m_z_min,m_z_max;
51 
52 
53  #if defined(MRPT_OS_LINUX)
54  int m_joy_fd; //!< File FD for the joystick, or -1 if not open (Linux only)
55  int m_joy_index; //!< The index of the joystick open in m_joy_fd (Linux only)
56  /** Using an event system we only have deltas, need to keep the whole joystick state (Linux only) */
57  vector_bool m_joystate_btns;
58  /** Using an event system we only have deltas, need to keep the whole joystick state (Linux only) */
59  vector_int m_joystate_axes;
60  #endif
61 
62  public:
63  /** Constructor
64  */
65  CJoystick();
66 
67  /** Destructor
68  */
69  virtual ~CJoystick();
70 
71  /** Returns the number of Joysticks in the computer.
72  */
73  static int getJoysticksCount();
74 
75  /** Gets joystick information.
76  *
77  * This method will try first to open the joystick, so you can safely call it while the joystick is plugged and removed arbitrarly.
78  *
79  * \param nJoy The 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.
80  * \param x The x axis position, range [-1,1]
81  * \param y The y axis position, range [-1,1]
82  * \param z The z axis position, range [-1,1]
83  * \param buttons Each element will hold true if buttons are pressed. The size of the vector will be set automatically to the number of buttons.
84  * \param raw_x_pos If it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder.
85  * \param raw_y_pos If it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder.
86  * \param raw_z_pos If it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder.
87  *
88  * \return Returns true if successfull, false on error, for example, if joystick is not present.
89  *
90  * \sa setLimits
91  */
92  bool getJoystickPosition(
93  int nJoy,
94  float &x,
95  float &y,
96  float &z,
97  std::vector<bool> &buttons,
98  int *raw_x_pos=NULL,
99  int *raw_y_pos=NULL,
100  int *raw_z_pos=NULL );
101 
102  /** Set the axis limit values, for computing a [-1,1] position index easily (Only required to calibrate analog joystick).
103  * It seems that these values must been calibrated for each joystick model.
104  *
105  * \sa getJoystickPosition
106  */
107  #ifdef MRPT_OS_WINDOWS
108  void setLimits( int x_min = 0,int x_max = 0xFFFF, int y_min=0,int y_max = 0xFFFF,int z_min=0,int z_max = 0xFFFF );
109  #else
110  void setLimits( int x_min = -32767,int x_max = 32767, int y_min=-32767,int y_max = 32767,int z_min=-32767,int z_max = 32767);
111  #endif
112  }; // End of class def.
113 
114  } // End of namespace
115 } // End of namespace
116 
117 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013