CDeltaDevices.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  \author Force Dimension - www.forcedimension.com
41  \version 3.1.1 $Rev: 1901 $
42 */
43 //==============================================================================
44 
45 //------------------------------------------------------------------------------
46 #ifndef CDeltaDevicesH
47 #define CDeltaDevicesH
48 //------------------------------------------------------------------------------
49 #if defined(C_ENABLE_DELTA_DEVICE_SUPPORT)
50 //------------------------------------------------------------------------------
52 //------------------------------------------------------------------------------
53 
54 //------------------------------------------------------------------------------
55 namespace chai3d {
56 //------------------------------------------------------------------------------
57 
58 //==============================================================================
65 //==============================================================================
66 
67 //------------------------------------------------------------------------------
68 #if defined(WIN32) | defined(WIN64)
69 //------------------------------------------------------------------------------
70 #ifndef DOXYGEN_SHOULD_SKIP_THIS
71 //------------------------------------------------------------------------------
72 
73 /* devices */
74 #define DHD_DEVICE_NONE 0
75 #define DHD_DEVICE_3DOF 31
76 #define DHD_DEVICE_6DOF 61
77 #define DHD_DEVICE_6DOF_500 62
78 #define DHD_DEVICE_DELTA3 63
79 #define DHD_DEVICE_DELTA6 64
80 #define DHD_DEVICE_OMEGA 32
81 #define DHD_DEVICE_OMEGA3 33
82 #define DHD_DEVICE_OMEGA33 34
83 #define DHD_DEVICE_OMEGA33_LEFT 36
84 #define DHD_DEVICE_OMEGA331 35
85 #define DHD_DEVICE_OMEGA331_LEFT 37
86 #define DHD_DEVICE_FALCON 60
87 #define DHD_DEVICE_CONTROLLER 81
88 #define DHD_DEVICE_CONTROLLER_HR 82
89 #define DHD_DEVICE_CUSTOM 91
90 #define DHD_DEVICE_SIGMA331 104
91 #define DHD_DEVICE_SIGMA331_LEFT 105
92 #define DHD_DEVICE_SIGMA33P 106
93 #define DHD_DEVICE_SIGMA33P_LEFT 107
94 #define DHD_DEVICE_SIGMA331S 108
95 #define DHD_DEVICE_SIGMA331S_LEFT 109
96 
97 /* status */
98 #define DHD_ON 1
99 #define DHD_OFF 0
100 
101 /* device count */
102 #define DHD_MAX_DEVICE 4
103 
104 /* TimeGuard return value */
105 #define DHD_TIMEGUARD 1
106 
107 /* status count */
108 #define DHD_MAX_STATUS 15
109 
110 /* status codes */
111 #define DHD_STATUS_POWER 0
112 #define DHD_STATUS_CONNECTED 1
113 #define DHD_STATUS_STARTED 2
114 #define DHD_STATUS_RESET 3
115 #define DHD_STATUS_IDLE 4
116 #define DHD_STATUS_FORCE 5
117 #define DHD_STATUS_BRAKE 6
118 #define DHD_STATUS_TORQUE 7
119 #define DHD_STATUS_WRIST_DETECTED 8
120 #define DHD_STATUS_ERROR 9
121 #define DHD_STATUS_GRAVITY 10
122 #define DHD_STATUS_TIMEGUARD 11
123 #define DHD_STATUS_ROTATOR_RESET 12
124 #define DHD_STATUS_REDUNDANCY 13
125 #define DHD_STATUS_FORCEOFFCAUSE 14
126 
127 /* velocity estimator computation mode */
128 #define DHD_VELOCITY_WINDOWING 0
129 #define DHD_VELOCITY_AVERAGING 1
130 
131 //------------------------------------------------------------------------------
132 #endif // DOXYGEN_SHOULD_SKIP_THIS
133 //------------------------------------------------------------------------------
134 #endif // WIN32
135 //------------------------------------------------------------------------------
136 
137 //------------------------------------------------------------------------------
139 typedef std::shared_ptr<cDeltaDevice> cDeltaDevicePtr;
140 //------------------------------------------------------------------------------
141 
142 //==============================================================================
155 //==============================================================================
157 {
158  //--------------------------------------------------------------------------
159  // CONSTRUCTOR & DESTRUCTOR:
160  //--------------------------------------------------------------------------
161 
162 public:
163 
165  cDeltaDevice(unsigned int a_deviceNumber = 0, bool a_external = false);
166 
168  virtual ~cDeltaDevice();
169 
171  static cDeltaDevicePtr create(unsigned int a_deviceNumber = 0, bool a_external = false) { return (std::make_shared<cDeltaDevice>(a_deviceNumber, a_external)); }
172 
173 
174  //--------------------------------------------------------------------------
175  // PUBLIC METHODS:
176  //--------------------------------------------------------------------------
177 
178 public:
179 
181  virtual bool open();
182 
184  virtual bool close();
185 
187  virtual bool calibrate(bool a_forceCalibration = false);
188 
190  virtual bool getPosition(cVector3d& a_position);
191 
193  virtual bool getLinearVelocity(cVector3d& a_linearVelocity);
194 
196  virtual bool getRotation(cMatrix3d& a_rotation);
197 
199  virtual bool getGripperAngleRad(double& a_angle);
200 
202  virtual bool getUserSwitches(unsigned int& a_userSwitches);
203 
205  virtual bool setForceAndTorqueAndGripperForce(const cVector3d& a_force, const cVector3d& a_torque, double a_gripperForce);
206 
207 
208  //--------------------------------------------------------------------------
209  // PUBLIC STATIC METHODS:
210  //--------------------------------------------------------------------------
211 
212 public:
213 
215  static unsigned int getNumDevices();
216 
217 
218  //--------------------------------------------------------------------------
219  // PROTECTED METHODS - DEVICE LIBRARY INITIALIZATION:
220  //--------------------------------------------------------------------------
221 
222 protected:
223 
225  static bool openLibraries();
226 
228  static bool closeLibraries();
229 
230 
231  //--------------------------------------------------------------------------
232  // PROTECTED MEMBERS - DEVICE LIBRARIES:
233  //--------------------------------------------------------------------------
234 
235 protected:
236 
239 
241  static unsigned int s_libraryCounter;
242 
243 
244  //--------------------------------------------------------------------------
245  // PUBLIC METHODS RESTRICTED TO FORCE DIMENSION DEVICES ONLY:
246  //--------------------------------------------------------------------------
247 
248 public:
249 
251  int getDeviceType() { return (m_deviceType); }
252 
254  bool enableForces(bool a_value);
255 
256 
257  //--------------------------------------------------------------------------
258  // PROTECTED MEMBERS
259  //--------------------------------------------------------------------------
260 
261 protected:
262 
265 
268 
271 
274 
277 
280 
283 
284  //--------------------------------------------------------------------------
285  #ifndef DOXYGEN_SHOULD_SKIP_THIS
286  //--------------------------------------------------------------------------
288  static bool s_dhdGetDeviceCount;
289  static bool s_dhdGetDeviceID;
290  static bool s_dhdGetSystemType;
291  static bool s_dhdOpenID;
292  static bool s_dhdClose;
293  static bool s_dhdReset;
294  static bool s_dhdGetButton;
295  static bool s_dhdGetButtonMask;
296  static bool s_dhdGetPosition;
297  static bool s_dhdGetLinearVelocity;
298  static bool s_dhdGetOrientationRad;
299  static bool s_dhdSetTorque;
300  static bool s_dhdGetOrientationFrame;
301  static bool s_dhdSetForce;
302  static bool s_dhdSetForceAndTorque;
303  static bool s_dhdSetForceAndGripperForce;
304  static bool s_dhdSetForceAndTorqueAndGripperForce;
305  static bool s_dhdGetGripperThumbPos;
306  static bool s_dhdGetGripperFingerPos;
307  static bool s_dhdGetGripperAngleRad;
308  static bool s_dhdEnableExpertMode;
309  static bool s_dhdDisableExpertMode;
310  static bool s_dhdEnableForce;
311  static bool s_dhdIsLeftHanded;
312  static bool s_dhdSetBaseAngleZDeg;
313  static bool s_dhdSetVelocityThreshold;
314  static bool s_dhdSetWatchdog;
315  static bool s_drdOpenID;
316  static bool s_drdClose;
317  static bool s_drdIsInitialized;
318  static bool s_drdAutoInit;
319  static bool s_drdStop;
320  static bool s_flagUsingSDK32;
321  //--------------------------------------------------------------------------
322  #endif // DOXYGEN_SHOULD_SKIP_THIS
323  //--------------------------------------------------------------------------
324 };
325 
326 //------------------------------------------------------------------------------
327 } // namespace chai3d
328 //------------------------------------------------------------------------------
329 
330 //------------------------------------------------------------------------------
331 #endif // C_ENABLE_DELTA_DEVICE_SUPPORT
332 //------------------------------------------------------------------------------
333 #endif
334 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:88
virtual bool calibrate(bool a_forceCalibration=false)
This method calibrates the haptic device.
Definition: CDeltaDevices.cpp:1125
int m_userSwitchCount[8]
Data structure for simulating a low-pass filter on user switches.
Definition: CDeltaDevices.h:270
This class implements an interface to all Force Dimension and Novint haptic devices.
Definition: CDeltaDevices.h:156
cDeltaDevice(unsigned int a_deviceNumber=0, bool a_external=false)
Constructor of cDeltaDevice.
Definition: CDeltaDevices.cpp:423
bool m_external
Was dhdOpen() called outside CHAI3D?
Definition: CDeltaDevices.h:282
const unsigned int C_MAX_DEVICES
Definition: CGenericDevice.h:65
This class implements a high precision clock.
Definition: CPrecisionClock.h:85
int getDeviceType()
This method returns the type of this haptic device.
Definition: CDeltaDevices.h:251
virtual bool getRotation(cMatrix3d &a_rotation)
This method returns the orientation frame of the haptic device.
Definition: CDeltaDevices.cpp:1250
bool enableForces(bool a_value)
This method enables or disables forces.
Definition: CDeltaDevices.cpp:1567
virtual bool getPosition(cVector3d &a_position)
This method returns the position of the haptic device.
Definition: CDeltaDevices.cpp:1172
virtual bool open()
This method opens a connection to the haptic device.
Definition: CDeltaDevices.cpp:536
int m_deviceType
Device type among the Force Dimension devices.
Definition: CDeltaDevices.h:267
static cDeltaDevicePtr create(unsigned int a_deviceNumber=0, bool a_external=false)
Shared cDeltaDevice allocator.
Definition: CDeltaDevices.h:171
static unsigned int getNumDevices()
This method returns the number of haptic devices available for this class of devices.
Definition: CDeltaDevices.cpp:388
virtual bool setForceAndTorqueAndGripperForce(const cVector3d &a_force, const cVector3d &a_torque, double a_gripperForce)
This method sends a force, torque, and gripper force to the haptic device.
Definition: CDeltaDevices.cpp:1414
Implements a base class for haptic devices.
static unsigned int s_libraryCounter
Number of instances for this class of devices currently using the libraries.
Definition: CDeltaDevices.h:241
This class implements a 3D matrix.
Definition: CMatrix3d.h:97
int m_userSwitchStatus[8]
Last state of user switch.
Definition: CDeltaDevices.h:273
This class implements a base class for haptic devices.
Definition: CGenericHapticDevice.h:274
std::shared_ptr< cDeltaDevice > cDeltaDevicePtr
Definition: CDeltaDevices.h:138
static bool openLibraries()
This method opens libraries for this class of devices.
Definition: CDeltaDevices.cpp:168
bool m_statusEnableForcesFirstTime
Have forces been enable yet since the connection to the device was opened?
Definition: CDeltaDevices.h:279
virtual bool getLinearVelocity(cVector3d &a_linearVelocity)
This method returns the linear velocity of the haptic device.
Definition: CDeltaDevices.cpp:1210
Definition: CAudioBuffer.cpp:56
virtual bool close()
This method closes the connection to the haptic device.
Definition: CDeltaDevices.cpp:1074
static bool closeLibraries()
This method closes libraries for this class of devices.
Definition: CDeltaDevices.cpp:354
virtual ~cDeltaDevice()
Destructor of cDeltaDevice.
Definition: CDeltaDevices.cpp:510
int m_deviceID
Device ID number among the Force Dimension devices connected to the computer.
Definition: CDeltaDevices.h:264
static bool s_allocationTable[C_MAX_DEVICES]
Allocation table for devices of this class. true means that the device has been allocated, false means free.
Definition: CDeltaDevices.h:238
virtual bool getUserSwitches(unsigned int &a_userSwitches)
This method returns the status of all user switches [true = ON / false = OFF].
Definition: CDeltaDevices.cpp:1511
cPrecisionClock m_userSwitchClock[8]
Time guard for user switch.
Definition: CDeltaDevices.h:276
virtual bool getGripperAngleRad(double &a_angle)
This method returns the gripper angle in radian [rad].
Definition: CDeltaDevices.cpp:1345