Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpRobotTemplate.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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:
32  * Defines a robot just to show which function you must implement.
33  *
34 *****************************************************************************/
35 
36 #include <visp3/core/vpConfig.h>
37 
38 #include <visp3/robot/vpRobotException.h>
39 
45 #include <visp3/core/vpHomogeneousMatrix.h>
46 #include <visp3/robot/vpRobotTemplate.h>
47 
53 {
54  // If you want to control the robot in Cartesian in a tool frame, set the corresponding transformation in m_eMc
55  // that is set to identity by default in the constructor.
56 
59 
60  // Set here the robot degrees of freedom number
61  nDof = 6; // If your arm has 6 dof
62 }
63 
68 
72 vpRobotTemplate::~vpRobotTemplate() { std::cout << "Not implemented ! " << std::endl; }
73 
74 /*
75 
76  At least one of these function has to be implemented to control the robot with a
77  Cartesian velocity:
78  - get_eJe()
79  - get_fJe()
80 
81 */
82 
89 {
90  (void)eJe_;
91  std::cout << "Not implemented ! " << std::endl;
92 }
93 
100 {
101  (void)fJe_;
102  std::cout << "Not implemented ! " << std::endl;
103 }
104 
105 /*
106 
107  At least one of these function has to be implemented to control the robot:
108  - setCartVelocity()
109  - setJointVelocity()
110 
111 */
112 
123 {
124  if (v.size() != 6) {
126  "Cannot send a velocity twist vector in tool frame that is not 6-dim (%d)", v.size()));
127  }
128 
129  vpColVector v_e; // This is the velocity that the robot is able to apply in the end-effector frame
130  switch (frame) {
131  case vpRobot::TOOL_FRAME: {
132  // We have to transform the requested velocity in the end-effector frame.
133  // Knowing that the constant transformation between the tool frame and the end-effector frame obtained
134  // by extrinsic calibration is set in m_eMc we can compute the velocity twist matrix eVc that transform
135  // a velocity twist from tool (or camera) frame into end-effector frame
137  v_e = eVc * v;
138  break;
139  }
140 
143  v_e = v;
144  break;
145  }
147  case vpRobot::MIXT_FRAME:
148  // Out of the scope
149  break;
150  }
151 
152  // Implement your stuff here to send the end-effector velocity twist v_e
153  // - If the SDK allows to send cartesian velocities in the end-effector, it's done. Just wrap data in v_e
154  // - If the SDK allows to send cartesian velocities in the reference (or base) frame you have to implement
155  // the robot Jacobian in set_fJe() and call:
156  // vpColVector v = get_fJe().inverse() * v_e;
157  // At this point you have to wrap data in v that is the 6-dim velocity to apply to the robot
158  // - If the SDK allows to send only joint velocities you have to implement the robot Jacobian in set_eJe()
159  // and call:
160  // vpColVector qdot = get_eJe().inverse() * v_e;
161  // setJointVelocity(qdot);
162  // - If the SDK allows to send only a cartesian position trajectory of the end-effector position in the base frame
163  // called fMe (for fix frame to end-effector homogeneous transformation) you can transform the cartesian
164  // velocity in the end-effector into a displacement eMe using the exponetial map:
165  // double delta_t = 0.010; // in sec
166  // vpHomogenesousMatrix eMe = vpExponentialMap::direct(v_e, delta_t);
167  // vpHomogenesousMatrix fMe = getPosition(vpRobot::REFERENCE_FRAME);
168  // the new position to reach is than given by fMe * eMe
169  // vpColVector fpe(vpPoseVector(fMe * eMe));
170  // setPosition(vpRobot::REFERENCE_FRAME, fpe);
171 
172  std::cout << "Not implemented ! " << std::endl;
173  std::cout << "To implement me you need : " << std::endl;
174  std::cout << "\t to known the robot jacobian expressed in ";
175  std::cout << "the end-effector frame (eJe) " << std::endl;
176  std::cout << "\t the frame transformation between tool or camera frame ";
177  std::cout << "and end-effector frame (cMe)" << std::endl;
178 }
179 
185 {
186  (void)qdot;
187 
188  // Implement your stuff here to send the joint velocities qdot
189 
190  std::cout << "Not implemented ! " << std::endl;
191 }
192 
203 {
206  "Cannot send a velocity to the robot. "
207  "Call setRobotState(vpRobot::STATE_VELOCITY_CONTROL) once before "
208  "entering your control loop.");
209  }
210 
211  vpColVector vel_sat(6);
212 
213  // Velocity saturation
214  switch (frame) {
215  // Saturation in cartesian space
216  case vpRobot::TOOL_FRAME:
219  case vpRobot::MIXT_FRAME: {
220  if (vel.size() != 6) {
222  "Cannot apply a Cartesian velocity that is not a 6-dim vector (%d)", vel.size()));
223  }
224  vpColVector vel_max(6);
225 
226  for (unsigned int i = 0; i < 3; i++)
227  vel_max[i] = getMaxTranslationVelocity();
228  for (unsigned int i = 3; i < 6; i++)
229  vel_max[i] = getMaxRotationVelocity();
230 
231  vel_sat = vpRobot::saturateVelocities(vel, vel_max, true);
232 
233  setCartVelocity(frame, vel_sat);
234  break;
235  }
236  // Saturation in joint space
237  case vpRobot::JOINT_STATE: {
238  if (vel.size() != static_cast<size_t>(nDof)) {
239  throw(vpException(vpException::dimensionError, "Cannot apply a joint velocity that is not a %-dim vector (%d)",
240  nDof, vel.size()));
241  }
242  vpColVector vel_max(vel.size());
243 
244  // Since the robot has only rotation axis all the joint max velocities are set to getMaxRotationVelocity()
245  vel_max = getMaxRotationVelocity();
246 
247  vel_sat = vpRobot::saturateVelocities(vel, vel_max, true);
248 
249  setJointVelocity(vel_sat);
250  }
251  }
252 }
253 
254 /*
255 
256  THESE FUNCTIONS ARE NOT MANDATORY BUT ARE USUALLY USEFUL
257 
258 */
259 
266 {
267  (void)q;
268  std::cout << "Not implemented ! " << std::endl;
269 }
270 
278 {
279  if (frame == JOINT_STATE) {
280  getJointPosition(q);
281  }
282  else {
283  std::cout << "Not implemented ! " << std::endl;
284  }
285 }
286 
294 {
295  (void)frame;
296  (void)q;
297  std::cout << "Not implemented ! " << std::endl;
298 }
299 
307 {
308  (void)frame;
309  (void)q;
310  std::cout << "Not implemented ! " << std::endl;
311 }
312 END_VISP_NAMESPACE
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:349
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
error that can be emitted by ViSP classes.
Definition: vpException.h:60
@ dimensionError
Bad dimension.
Definition: vpException.h:71
@ fatalError
Fatal error.
Definition: vpException.h:72
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
Error that can be emitted by the vpRobot class and its derivatives.
@ wrongStateError
Wrong robot state.
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
void getJointPosition(vpColVector &q)
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) VP_OVERRIDE
void get_fJe(vpMatrix &fJe_) VP_OVERRIDE
void setCartVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v)
vpHomogeneousMatrix m_eMc
Constant transformation between end-effector and tool (or camera) frame.
virtual ~vpRobotTemplate() VP_OVERRIDE
void init() VP_OVERRIDE
void get_eJe(vpMatrix &eJe_) VP_OVERRIDE
void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE
void setJointVelocity(const vpColVector &qdot)
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE
int nDof
number of degrees of freedom
Definition: vpRobot.h:104
virtual vpRobotStateType getRobotState(void) const
Definition: vpRobot.h:155
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition: vpRobot.cpp:164
vpControlFrameType
Definition: vpRobot.h:77
@ REFERENCE_FRAME
Definition: vpRobot.h:78
@ JOINT_STATE
Definition: vpRobot.h:82
@ TOOL_FRAME
Definition: vpRobot.h:86
@ MIXT_FRAME
Definition: vpRobot.h:88
@ END_EFFECTOR_FRAME
Definition: vpRobot.h:83
static const double maxRotationVelocityDefault
Definition: vpRobot.h:101
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
Definition: vpRobot.h:67
static const double maxTranslationVelocityDefault
Definition: vpRobot.h:99
double getMaxRotationVelocity(void) const
Definition: vpRobot.cpp:274
double maxTranslationVelocity
Definition: vpRobot.h:98
double getMaxTranslationVelocity(void) const
Definition: vpRobot.cpp:252
double maxRotationVelocity
Definition: vpRobot.h:100