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.2.0 $Rev: 2098 $
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 
95 /* status */
96 #define DHD_ON 1
97 #define DHD_OFF 0
98 
99 /* device count */
100 #define DHD_MAX_DEVICE 4
101 
102 /* TimeGuard return value */
103 #define DHD_TIMEGUARD 1
104 
105 /* status count */
106 #define DHD_MAX_STATUS 16
107 
108 /* status codes */
109 #define DHD_STATUS_POWER 0
110 #define DHD_STATUS_CONNECTED 1
111 #define DHD_STATUS_STARTED 2
112 #define DHD_STATUS_RESET 3
113 #define DHD_STATUS_IDLE 4
114 #define DHD_STATUS_FORCE 5
115 #define DHD_STATUS_BRAKE 6
116 #define DHD_STATUS_TORQUE 7
117 #define DHD_STATUS_WRIST_DETECTED 8
118 #define DHD_STATUS_ERROR 9
119 #define DHD_STATUS_GRAVITY 10
120 #define DHD_STATUS_TIMEGUARD 11
121 #define DHD_STATUS_ROTATOR_RESET 12
122 #define DHD_STATUS_REDUNDANCY 13
123 #define DHD_STATUS_FORCEOFFCAUSE 14
124 #define DHD_STATUS_LOCKS 15
125 
126 /* velocity estimator computation mode */
127 #define DHD_VELOCITY_WINDOWING 0
128 #define DHD_VELOCITY_AVERAGING 1
129 
130 /* encoder count */
131 #define DHD_MAX_DOF 8
132 
133 //------------------------------------------------------------------------------
134 #endif // DOXYGEN_SHOULD_SKIP_THIS
135 //------------------------------------------------------------------------------
136 #endif // WIN32
137 //------------------------------------------------------------------------------
138 
139 //------------------------------------------------------------------------------
141 typedef std::shared_ptr<cDeltaDevice> cDeltaDevicePtr;
142 //------------------------------------------------------------------------------
143 
144 //==============================================================================
157 //==============================================================================
159 {
160  //--------------------------------------------------------------------------
161  // CONSTRUCTOR & DESTRUCTOR:
162  //--------------------------------------------------------------------------
163 
164 public:
165 
167  cDeltaDevice(unsigned int a_deviceNumber = 0, bool a_external = false);
168 
170  virtual ~cDeltaDevice();
171 
173  static cDeltaDevicePtr create(unsigned int a_deviceNumber = 0, bool a_external = false) { return (std::make_shared<cDeltaDevice>(a_deviceNumber, a_external)); }
174 
175 
176  //--------------------------------------------------------------------------
177  // PUBLIC METHODS:
178  //--------------------------------------------------------------------------
179 
180 public:
181 
183  virtual bool open();
184 
186  virtual bool close();
187 
189  virtual bool calibrate(bool a_forceCalibration = false);
190 
192  virtual bool getPosition(cVector3d& a_position);
193 
195  virtual bool getLinearVelocity(cVector3d& a_linearVelocity);
196 
198  virtual bool getRotation(cMatrix3d& a_rotation);
199 
201  virtual bool getJointAnglesRad(double a_jointAnglesRad[C_MAX_DOF]);
202 
204  virtual bool getGripperAngleRad(double& a_angle);
205 
207  virtual bool getUserSwitches(unsigned int& a_userSwitches);
208 
210  virtual bool setForceAndTorqueAndGripperForce(const cVector3d& a_force, const cVector3d& a_torque, double a_gripperForce);
211 
212 
213  //--------------------------------------------------------------------------
214  // PUBLIC STATIC METHODS:
215  //--------------------------------------------------------------------------
216 
217 public:
218 
220  static unsigned int getNumDevices();
221 
222 
223  //--------------------------------------------------------------------------
224  // PROTECTED METHODS - DEVICE LIBRARY INITIALIZATION:
225  //--------------------------------------------------------------------------
226 
227 protected:
228 
230  static bool openLibraries();
231 
233  static bool closeLibraries();
234 
235 
236  //--------------------------------------------------------------------------
237  // PROTECTED MEMBERS - DEVICE LIBRARIES:
238  //--------------------------------------------------------------------------
239 
240 protected:
241 
244 
246  static unsigned int s_libraryCounter;
247 
248 
249  //--------------------------------------------------------------------------
250  // PUBLIC METHODS RESTRICTED TO FORCE DIMENSION DEVICES ONLY:
251  //--------------------------------------------------------------------------
252 
253 public:
254 
256  int getDeviceType() { return (m_deviceType); }
257 
259  bool enableForces(bool a_value);
260 
262  bool setDeviceAngleDeg(double a_angleDeg);
263 
265  bool setVibration(double a_freq, double a_amplitude, int a_type = 0);
266 
267 
268  //--------------------------------------------------------------------------
269  // PROTECTED MEMBERS
270  //--------------------------------------------------------------------------
271 
272 protected:
273 
276 
279 
282 
285 
288 
291 
294 
297 
298  //--------------------------------------------------------------------------
299  #ifndef DOXYGEN_SHOULD_SKIP_THIS
300  //--------------------------------------------------------------------------
302  static bool s_dhdGetDeviceCount;
303  static bool s_dhdGetDeviceID;
304  static bool s_dhdGetSystemType;
305  static bool s_dhdOpenID;
306  static bool s_dhdClose;
307  static bool s_dhdReset;
308  static bool s_dhdGetButton;
309  static bool s_dhdGetButtonMask;
310  static bool s_dhdGetPosition;
311  static bool s_dhdGetLinearVelocity;
312  static bool s_dhdGetOrientationRad;
313  static bool s_dhdSetTorque;
314  static bool s_dhdGetOrientationFrame;
315  static bool s_dhdSetForce;
316  static bool s_dhdSetForceAndTorque;
317  static bool s_dhdSetForceAndGripperForce;
318  static bool s_dhdSetForceAndTorqueAndGripperForce;
319  static bool s_dhdGetGripperThumbPos;
320  static bool s_dhdGetGripperFingerPos;
321  static bool s_dhdGetGripperAngleRad;
322  static bool s_dhdEnableExpertMode;
323  static bool s_dhdDisableExpertMode;
324  static bool s_dhdEnableForce;
325  static bool s_dhdIsLeftHanded;
326  static bool s_dhdSetBaseAngleZDeg;
327  static bool s_dhdSetVelocityThreshold;
328  static bool s_dhdSetWatchdog;
329  static bool s_drdOpenID;
330  static bool s_drdClose;
331  static bool s_drdIsInitialized;
332  static bool s_drdAutoInit;
333  static bool s_drdStop;
334  static bool s_flagUsingSDK32;
335  static bool s_dhdSetDeviceAngleDeg;
336  static bool s_dhdGetJointAngles;
337  static bool s_dhdSetVibration;
338 
339  //--------------------------------------------------------------------------
340  #endif // DOXYGEN_SHOULD_SKIP_THIS
341  //--------------------------------------------------------------------------
342 };
343 
344 //------------------------------------------------------------------------------
345 } // namespace chai3d
346 //------------------------------------------------------------------------------
347 
348 //------------------------------------------------------------------------------
349 #endif // C_ENABLE_DELTA_DEVICE_SUPPORT
350 //------------------------------------------------------------------------------
351 #endif
352 //------------------------------------------------------------------------------
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:1230
int m_userSwitchCount[8]
Data structure for simulating a low-pass filter on user switches.
Definition: CDeltaDevices.h:281
This class implements an interface to all Force Dimension and Novint haptic devices.
Definition: CDeltaDevices.h:158
const int C_MAX_DOF
Maximum number of joint of a haptic device.
Definition: CGenericHapticDevice.h:78
cDeltaDevice(unsigned int a_deviceNumber=0, bool a_external=false)
Constructor of cDeltaDevice.
Definition: CDeltaDevices.cpp:445
bool m_external
Was dhdOpen() called outside CHAI3D?
Definition: CDeltaDevices.h:293
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:256
virtual bool getRotation(cMatrix3d &a_rotation)
This method returns the orientation frame of the haptic device.
Definition: CDeltaDevices.cpp:1357
bool enableForces(bool a_value)
This method enables or disables forces.
Definition: CDeltaDevices.cpp:1711
bool setDeviceAngleDeg(double a_angleDeg)
This method orients the device around the y-axis.
Definition: CDeltaDevices.cpp:1765
virtual bool getPosition(cVector3d &a_position)
This method returns the position of the haptic device.
Definition: CDeltaDevices.cpp:1277
virtual bool open()
This method opens a connection to the haptic device.
Definition: CDeltaDevices.cpp:558
int m_deviceType
Device type among the Force Dimension devices.
Definition: CDeltaDevices.h:278
static cDeltaDevicePtr create(unsigned int a_deviceNumber=0, bool a_external=false)
Shared cDeltaDevice allocator.
Definition: CDeltaDevices.h:173
static unsigned int getNumDevices()
This method returns the number of haptic devices available for this class of devices.
Definition: CDeltaDevices.cpp:410
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:1558
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:246
This class implements a 3D matrix.
Definition: CMatrix3d.h:97
int m_userSwitchStatus[8]
Last state of user switch.
Definition: CDeltaDevices.h:284
This class implements a base class for haptic devices.
Definition: CGenericHapticDevice.h:280
virtual bool getJointAnglesRad(double a_jointAnglesRad[C_MAX_DOF])
This method returns the joint angles of the haptic device.
Definition: CDeltaDevices.cpp:1453
std::shared_ptr< cDeltaDevice > cDeltaDevicePtr
Definition: CDeltaDevices.h:140
bool setVibration(double a_freq, double a_amplitude, int a_type=0)
This method assign a vibration to the devices that support this feature.
Definition: CDeltaDevices.cpp:1800
static bool openLibraries()
This method opens libraries for this class of devices.
Definition: CDeltaDevices.cpp:177
bool m_statusEnableForcesFirstTime
Have forces been enable yet since the connection to the device was opened?
Definition: CDeltaDevices.h:290
virtual bool getLinearVelocity(cVector3d &a_linearVelocity)
This method returns the linear velocity of the haptic device.
Definition: CDeltaDevices.cpp:1317
Definition: CAudioBuffer.cpp:56
virtual bool close()
This method closes the connection to the haptic device.
Definition: CDeltaDevices.cpp:1179
static bool closeLibraries()
This method closes libraries for this class of devices.
Definition: CDeltaDevices.cpp:376
virtual ~cDeltaDevice()
Destructor of cDeltaDevice.
Definition: CDeltaDevices.cpp:532
cVector3d m_posWorkspaceOffset
Translational workspace offset.
Definition: CDeltaDevices.h:296
int m_deviceID
Device ID number among the Force Dimension devices connected to the computer.
Definition: CDeltaDevices.h:275
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:243
virtual bool getUserSwitches(unsigned int &a_userSwitches)
This method returns the status of all user switches [true = ON / false = OFF].
Definition: CDeltaDevices.cpp:1655
cPrecisionClock m_userSwitchClock[8]
Time guard for user switch.
Definition: CDeltaDevices.h:287
virtual bool getGripperAngleRad(double &a_angle)
This method returns the gripper angle in radian [rad].
Definition: CDeltaDevices.cpp:1489