1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description: Class which enables to project an image in the 3D space
32  * and get the view of a virtual camera.
33  *
34  * Authors:
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
39 #ifndef _vpVirtuose_h_
40 #define _vpVirtuose_h_
41 
42 #include <ostream>
43 #include <visp3/core/vpConfig.h>
44 #include <visp3/core/vpException.h>
45 #include <visp3/core/vpPoseVector.h>
46 
47 #ifdef VISP_HAVE_VIRTUOSE
48 
49 #include <VirtuoseAPI.h>
50 
51 /*!
52   \file vpVirtuose.h
53   \brief Wrapper over Haption Virtuose SDK to control haptic devices.
54 */
55 /*!
56   \class vpVirtuose
57   \ingroup group_robot_haptic
58 
59   This class was tested with Haption (http://www.haption.com) Virtuose 6D
60 haptic device.
61 
62   The class vpVirtuose allows to work with the original Virtuose API inside
63 ViSP. The Virtuose API supports the following devices:
64   - Virtuose 6D35-45
65   - Virtuose 3D35-40
66   - Virtuose 3D10-20
67   - Virtuose Desktop
68   - Virtuose Inca
69 
70   Not all Virtuose API function are implemented in the class.
71   Original Virtuose API functions need to be called with a VirtContext object,
72 provided by the function getHandler().
73 
74   The Virtuose library implements different control modes that could be set
75 using setCommandType(). The choice of the control mode depends on the
76 application. The following is the description of the main control modes as
77 described in the Virtuose API documentation.
78 
79   1. Force/position control (impedance mode): the application sends forces and
80 torques to the device and reads the position and speed of the end-effector
81 frame.
82   2. Position/force control (admittance mode): this advanced control mode
83 allows direct coupling with virtual objects; in that case, the application
84 sends the position and speed of the center of the object to the device, and
85 reads the forces and torques to be applied to the object for dynamic
86 integration. Stiffness and damping are calculated by the embedded software,
87 knowing the mass and inertia of the object, in order to ensure control
88   stability.
89   3. Position/force with virtual guides: this is the same as above, with
90 addition of virtual guides (e.g. fixed translation, fixed rotation, etc.).
91 
92   The Virtuose library defines the following reference frames:
93   1. The environment frame, corresponding to the origin of the virtual scene;
94 it is specified by the software application independently of the Virtuose API.
95   2. The observation frame, corresponding generally to the position of the
96 camera; it is defined with respect to environment frame. This frame location
97 could be set using setObservationFrame().
98   3. The base frame, representing the center of the haptic device; it is
99 defined with respect to the observation frame. This frame location could be
100 set using setBaseFrame().
101   4. The tool frame corresponds to the base of the tool fixed at the end of
102 the haptic device, and is defined with respect to the environment frame.
103   5. The end-effector (avatar) frame corresponds to the position of the user
104 hand on the device, taking into account the geometry of the tool, and is
105 defined with respect to tool frame.
106 
107   The position of the following frames can be defined only once using the API:
108   base frame (with respect to the observation frame) thanks to setBaseFrame()
109 and end-effector frame (with respect to the tool frame).
110 
111   The position of the observation frame (with respect to the environment
112 frame) can be modified dynamically using setObservationFrame().
113 
114   The position of the tool frame (with respect to the environment frame)
115 cannot be modified.
116 
117   All values used in the Virtuose API are expressed in physical units using
118 metric conventions:
119   - Durations in seconds (s)
120   - Dimensions in meters (m)
121   - Angles in radians (rad)
122   - Linear velocities in meters per second (m.s -1 )
123   - Angular velocities in radians per second (rad.s -1 )
124   - Forces in Newtons (N)
125   - Torques in Newton-meters (N.m)
126   - Masses in kilogrammes (kg)
127   - Inertia components in kg.m2
128 
129   The following sample code shows how to connect to the haptic device to get
130 its current joint position:
131 \code
132 #include <visp3/robot/vpVirtuose.h>
133 
134 int main()
135 {
136   vpVirtuose virtuose;
137   virtuose.init();
138   vpColVector q = virtuose.getArticularPosition();
139   std::cout << "Joint position: " << q.t() << std::endl;
140 }
141   \endcode
142  */
143 class VISP_EXPORT vpVirtuose
144 {
145 public:
146   vpVirtuose();
147   virtual ~vpVirtuose();
148 
149   void addForce(vpColVector &force);
150   void close();
151   void enableForceFeedback(int enable);
152 
153   vpColVector getArticularPosition() const;
154   vpColVector getArticularVelocity() const;
155   vpPoseVector getAvatarPosition() const;
156   vpPoseVector getBaseFrame() const;
157   VirtCommandType getCommandType() const;
158   bool getDeadMan() const;
159   bool getEmergencyStop() const;
160   unsigned int getJointsNumber() const;
161   vpColVector getForce() const;
162   VirtContext getHandler();
163   vpPoseVector getObservationFrame() const;
164   vpPoseVector getPhysicalPosition() const;
165   vpColVector getPhysicalVelocity() const;
166   vpPoseVector getPosition() const;
167   bool getPower() const;
168   vpColVector getVelocity() const;
169 
170   void init();
171 
172   void setArticularForce(const vpColVector &articularForce);
173   void setArticularPosition(const vpColVector &articularPosition);
174   void setArticularVelocity(const vpColVector &articularVelocity);
175   void setBaseFrame(const vpPoseVector &position);
176   void setCommandType(const VirtCommandType &type);
177   void setForce(const vpColVector &force);
178   void setForceFactor(const float &forceFactor);
179   void setIndexingMode(const VirtIndexingType &type);
180   void setIpAddressAndPort(const std::string &ip, int port);
181 
182   void setObservationFrame(const vpPoseVector &position);
183   void setPeriodicFunction(VirtPeriodicFunction CallBackVirt);
184   void setPosition(vpPoseVector &position);
185   void setPowerOff();
186   void setPowerOn();
187   void setSaturation(const float &forceLimit, const float &torqueLimit);
188   void setTimeStep(const float &timeStep);
189   void setVelocity(vpColVector &velocity);
190   void setVelocityFactor(const float &velocityFactor);
191   /*!
192    * Enable/disable verbose mode.
193    * \param mode : true to enable, false to disable verbose.
194    */
setVerbose(bool mode)195   void setVerbose(bool mode) { m_verbose = mode; }
196 
197   void startPeriodicFunction();
198   void stopPeriodicFunction();
199 
200 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
201   /*!
202     @name Deprecated functions
203   */
204   //@{
205   /*!
206    * \deprecated You should rather use setIpAddressAndPort() that is more explicit.
207    *
208    * Set haptic device ip address and port. Default value is
209    * "localhost#5000".
210    *
211    * \sa setIpAddressAndPort()
212    */
setIpAddress(const std::string & ip_port)213   vp_deprecated inline void setIpAddress(const std::string &ip_port) { m_ip_port = ip_port; }
214   //@}
215 #endif
216 
217 protected:
218   VirtContext m_virtContext;
219   std::string m_ip_port;
220   bool m_verbose;
221   int m_apiMajorVersion;
222   int m_apiMinorVersion;
223   int m_ctrlMajorVersion;
224   int m_ctrlMinorVersion;
225   VirtCommandType m_typeCommand;
226   VirtIndexingType m_indexType;
227   bool m_is_init;
228   float m_period;
229   unsigned int m_njoints;
230 };
231 
232 #endif
233 #endif
234