CSixenseDevices.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \version 3.2.0 $Rev: 1869 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CSixenseDevicesH
46 #define CSixenseDevicesH
47 //------------------------------------------------------------------------------
48 #if defined(C_ENABLE_SIXENSE_DEVICE_SUPPORT)
49 //------------------------------------------------------------------------------
51 //------------------------------------------------------------------------------
52 
53 //------------------------------------------------------------------------------
54 namespace chai3d {
55 //------------------------------------------------------------------------------
56 
57 //==============================================================================
64 //==============================================================================
65 
66 //------------------------------------------------------------------------------
67 #ifndef DOXYGEN_SHOULD_SKIP_THIS
68 //------------------------------------------------------------------------------
69 
70 #define SIXENSE_BUTTON_BUMPER (0x01<<7)
71 #define SIXENSE_BUTTON_JOYSTICK (0x01<<8)
72 #define SIXENSE_BUTTON_1 (0x01<<5)
73 #define SIXENSE_BUTTON_2 (0x01<<6)
74 #define SIXENSE_BUTTON_3 (0x01<<3)
75 #define SIXENSE_BUTTON_4 (0x01<<4)
76 #define SIXENSE_BUTTON_START (0x01<<0)
77 #define SIXENSE_SUCCESS 0
78 #define SIXENSE_FAILURE -1
79 #define SIXENSE_MAX_CONTROLLERS 4
80 
81  typedef struct _sixenseControllerData
82  {
83  float pos[3];
84  float rot_mat[3][3];
85  float joystick_x;
86  float joystick_y;
87  float trigger;
88  unsigned int buttons;
89  unsigned char sequence_number;
90  float rot_quat[4];
91  unsigned short firmware_revision;
92  unsigned short hardware_revision;
93  unsigned short packet_type;
94  unsigned short magnetic_frequency;
95  int enabled;
96  int controller_index;
97  unsigned char is_docked;
98  unsigned char which_hand;
99  unsigned char hemi_tracking_enabled;
100  } sixenseControllerData;
101 
102  typedef struct _sixenseAllControllerData
103  {
104  sixenseControllerData controllers[4];
105  } sixenseAllControllerData;
106 
107 //------------------------------------------------------------------------------
108 #endif // DOXYGEN_SHOULD_SKIP_THIS
109 //------------------------------------------------------------------------------
110 
111 
112 //------------------------------------------------------------------------------
114 typedef std::shared_ptr<cSixenseDevice> cSixenseDevicePtr;
115 //------------------------------------------------------------------------------
116 
117 //==============================================================================
130 //==============================================================================
132 {
133  //--------------------------------------------------------------------------
134  // CONSTRUCTOR & DESTRUCTOR:
135  //--------------------------------------------------------------------------
136 
137 public:
138 
140  cSixenseDevice(unsigned int a_deviceNumber = 0);
141 
143  virtual ~cSixenseDevice();
144 
146  static cSixenseDevicePtr create(unsigned int a_deviceNumber = 0) { return (std::make_shared<cSixenseDevice>(a_deviceNumber)); }
147 
148 
149  //--------------------------------------------------------------------------
150  // PUBLIC METHODS:
151  //--------------------------------------------------------------------------
152 
153  public:
154 
156  virtual bool open();
157 
159  virtual bool close();
160 
162  virtual bool calibrate(bool a_forceCalibration = false);
163 
165  virtual bool getPosition(cVector3d& a_position);
166 
168  virtual bool getRotation(cMatrix3d& a_rotation);
169 
171  virtual bool getGripperAngleRad(double& a_angle);
172 
174  virtual bool getUserSwitches(unsigned int& a_userSwitches);
175 
176 
177  //--------------------------------------------------------------------------
178  // PUBLIC STATIC METHODS:
179  //--------------------------------------------------------------------------
180 
181 public:
182 
184  static unsigned int getNumDevices();
185 
186 
187  //--------------------------------------------------------------------------
188  // PROTECTED METHODS - DEVICE LIBRARY INITIALIZATION:
189  //--------------------------------------------------------------------------
190 
191 protected:
192 
194  static bool openLibraries();
195 
197  static bool closeLibraries();
198 
199 
200  //--------------------------------------------------------------------------
201  // PROTECTED MEMBERS - DEVICE LIBRARIES:
202  //--------------------------------------------------------------------------
203 
204 protected:
205 
207  static bool s_allocationTable[C_MAX_DEVICES];
208 
210  static unsigned int s_libraryCounter;
211 
212 
213  //--------------------------------------------------------------------------
214  // PROTECTED MEMBERS - INTERNAL:
215  //--------------------------------------------------------------------------
216 
217 protected:
218 
221 
223  static sixenseAllControllerData m_data;
224 
225 
226  //--------------------------------------------------------------------------
227  // PROTECTED METHODS - INTERNAL:
228  //--------------------------------------------------------------------------
229 
230 protected:
231 
233  bool updateData();
234 };
235 
236 //------------------------------------------------------------------------------
237 } // namespace chai3ds
238 //------------------------------------------------------------------------------
239 
240 //------------------------------------------------------------------------------
241 #endif //_DISABLE_SIXENSE_DEVICE_SUPPORT
242 //------------------------------------------------------------------------------
243 #endif
244 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:88
static cPrecisionClock m_timeguard
Time guard for data acquisition.
Definition: CSixenseDevices.h:220
const unsigned int C_MAX_DEVICES
Definition: CGenericDevice.h:65
This class implements a high precision clock.
Definition: CPrecisionClock.h:85
static cSixenseDevicePtr create(unsigned int a_deviceNumber=0)
Shared cPhantomDevice allocator.
Definition: CSixenseDevices.h:146
Implements a base class for haptic devices.
This class implements a 3D matrix.
Definition: CMatrix3d.h:97
This class implements a base class for haptic devices.
Definition: CGenericHapticDevice.h:280
static sixenseAllControllerData m_data
Data acquired from the controller.
Definition: CSixenseDevices.h:223
Definition: CAudioBuffer.cpp:56
std::shared_ptr< cSixenseDevice > cSixenseDevicePtr
Definition: CSixenseDevices.h:113
This class implements an interface to the Sixense Razor Hydra magnetic tracker interface.
Definition: CSixenseDevices.h:131
static unsigned int s_libraryCounter
Number of instances for this class of devices currently using the libraries.
Definition: CSixenseDevices.h:210