CHAI3D  3.0.0
CDeltaDevices.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2015, 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.0.0 $Rev: 1780 $
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 setForce(const cVector3d& a_force);
203 
205  virtual bool setForceAndTorque(const cVector3d& a_force, const cVector3d& a_torque);
206 
208  virtual bool setForceAndTorqueAndGripperForce(const cVector3d& a_force, const cVector3d& a_torque, double a_gripperForce);
209 
211  virtual bool getUserSwitches(unsigned int& a_userSwitches);
212 
213 
214  //--------------------------------------------------------------------------
215  // PUBLIC STATIC METHODS:
216  //--------------------------------------------------------------------------
217 
218 public:
219 
221  static unsigned int getNumDevices();
222 
223 
224  //--------------------------------------------------------------------------
225  // PROTECTED METHODS - DEVICE LIBRARY INITIALIZATION:
226  //--------------------------------------------------------------------------
227 
228 protected:
229 
231  static bool openLibraries();
232 
234  static bool closeLibraries();
235 
236 
237  //--------------------------------------------------------------------------
238  // PROTECTED MEMBERS - DEVICE LIBRARIES:
239  //--------------------------------------------------------------------------
240 
241 protected:
242 
245 
247  static unsigned int s_libraryCounter;
248 
249 
250  //--------------------------------------------------------------------------
251  // PUBLIC METHODS RESTRICTED TO FORCE DIMENSION DEVICES ONLY:
252  //--------------------------------------------------------------------------
253 
254 public:
255 
257  int getDeviceType() { return (m_deviceType); }
258 
260  bool enableForces(bool a_value);
261 
262 
263  //--------------------------------------------------------------------------
264  // PROTECTED MEMBERS
265  //--------------------------------------------------------------------------
266 
267 protected:
268 
271 
274 
277 
280 
283 
286 
289 
290  //--------------------------------------------------------------------------
291  #ifndef DOXYGEN_SHOULD_SKIP_THIS
292  //--------------------------------------------------------------------------
294  static bool s_dhdGetDeviceCount;
295  static bool s_dhdGetDeviceID;
296  static bool s_dhdGetSystemType;
297  static bool s_dhdOpenID;
298  static bool s_dhdClose;
299  static bool s_dhdReset;
300  static bool s_dhdGetButton;
301  static bool s_dhdGetButtonMask;
302  static bool s_dhdGetPosition;
303  static bool s_dhdGetLinearVelocity;
304  static bool s_dhdGetOrientationRad;
305  static bool s_dhdSetTorque;
306  static bool s_dhdGetOrientationFrame;
307  static bool s_dhdSetForce;
308  static bool s_dhdSetForceAndTorque;
309  static bool s_dhdSetForceAndGripperForce;
310  static bool s_dhdSetForceAndTorqueAndGripperForce;
311  static bool s_dhdGetGripperThumbPos;
312  static bool s_dhdGetGripperFingerPos;
313  static bool s_dhdGetGripperAngleRad;
314  static bool s_dhdEnableExpertMode;
315  static bool s_dhdDisableExpertMode;
316  static bool s_dhdEnableForce;
317  static bool s_dhdIsLeftHanded;
318  static bool s_dhdSetBaseAngleZDeg;
319  static bool s_dhdSetVelocityThreshold;
320  static bool s_dhdSetWatchdog;
321  static bool s_drdOpenID;
322  static bool s_drdClose;
323  static bool s_drdIsInitialized;
324  static bool s_drdAutoInit;
325  static bool s_drdStop;
326  //--------------------------------------------------------------------------
327  #endif // DOXYGEN_SHOULD_SKIP_THIS
328  //--------------------------------------------------------------------------
329 };
330 
331 //------------------------------------------------------------------------------
332 } // namespace chai3d
333 //------------------------------------------------------------------------------
334 
335 //------------------------------------------------------------------------------
336 #endif // C_ENABLE_DELTA_DEVICE_SUPPORT
337 //------------------------------------------------------------------------------
338 #endif
339 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:85
virtual bool calibrate(bool a_forceCalibration=false)
This method calibrates the haptic device.
Definition: CDeltaDevices.cpp:1114
int m_userSwitchCount[8]
Data structure for simulating a low-pass filter on user switches.
Definition: CDeltaDevices.h:276
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:415
bool m_external
Was dhdOpen() called outside CHAI3D?
Definition: CDeltaDevices.h:288
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:257
virtual bool setForceAndTorque(const cVector3d &a_force, const cVector3d &a_torque)
This method sends a force and torque to the haptic device.
Definition: CDeltaDevices.cpp:1437
virtual bool getRotation(cMatrix3d &a_rotation)
This method returns the orientation frame of the haptic device.
Definition: CDeltaDevices.cpp:1239
bool enableForces(bool a_value)
This method enables or disables forces.
Definition: CDeltaDevices.cpp:1619
virtual bool getPosition(cVector3d &a_position)
This method returns the position of the haptic device.
Definition: CDeltaDevices.cpp:1161
virtual bool open()
This method opens a connection to the haptic device.
Definition: CDeltaDevices.cpp:528
int m_deviceType
Device type among the Force Dimension devices.
Definition: CDeltaDevices.h:273
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:380
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:1480
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:247
This class implements a 3D matrix.
Definition: CMatrix3d.h:97
int m_userSwitchStatus[8]
Last state of user switch.
Definition: CDeltaDevices.h:279
virtual bool setForce(const cVector3d &a_force)
This method sends a force to the haptic device.
Definition: CDeltaDevices.cpp:1400
This class implements a base class for haptic devices.
Definition: CGenericHapticDevice.h:273
std::shared_ptr< cDeltaDevice > cDeltaDevicePtr
Definition: CDeltaDevices.h:138
static bool openLibraries()
This method opens libraries for this class of devices.
Definition: CDeltaDevices.cpp:165
bool m_statusEnableForcesFirstTime
Have forces been enable yet since the connection to the device was opened?
Definition: CDeltaDevices.h:285
virtual bool getLinearVelocity(cVector3d &a_linearVelocity)
This method returns the linear velocity of the haptic device.
Definition: CDeltaDevices.cpp:1199
Definition: CAudioBuffer.cpp:56
virtual bool close()
This method closes the connection to the haptic device.
Definition: CDeltaDevices.cpp:1063
static bool closeLibraries()
This method closes libraries for this class of devices.
Definition: CDeltaDevices.cpp:349
virtual ~cDeltaDevice()
Destructor of cDeltaDevice.
Definition: CDeltaDevices.cpp:502
int m_deviceID
Device ID number among the Force Dimension devices connected to the computer.
Definition: CDeltaDevices.h:270
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:244
virtual bool getUserSwitches(unsigned int &a_userSwitches)
This method returns the status of all user switches [true = ON / false = OFF].
Definition: CDeltaDevices.cpp:1574
cPrecisionClock m_userSwitchClock[8]
Time guard for user switch.
Definition: CDeltaDevices.h:282
virtual bool getGripperAngleRad(double &a_angle)
This method returns the gripper angle in radian [rad].
Definition: CDeltaDevices.cpp:1334

CHAI3D 3.0.0 documentation
Please address any questions to support@chai3d.org
(C) 2003-2015 - CHAI3D
All Rights Reserved.