ViSP  2.10.0
vpRobot.cpp
1 /****************************************************************************
2  *
3  * $Id: vpRobot.cpp 5238 2015-01-30 13:52:25Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Generic virtual robot.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
42 #include <visp/vpRobot.h>
43 #include <visp/vpRobotException.h>
44 #include <visp/vpDebug.h>
45 
46 
48 const double vpRobot::maxRotationVelocityDefault = 0.7;
49 
50 /* ------------------------------------------------------------------------- */
51 /* --- CONSTRUCTEUR -------------------------------------------------------- */
52 /* ------------------------------------------------------------------------- */
53 
55  :
56  stateRobot(vpRobot::STATE_STOP), frameRobot(vpRobot::CAMERA_FRAME),
57  maxTranslationVelocity (maxTranslationVelocityDefault),
58  maxRotationVelocity (maxRotationVelocityDefault),
59  nDof(0),
60  eJe(), eJeAvailable(false), fJe(), fJeAvailable(false), areJointLimitsAvailable(false),
61  qmin(NULL), qmax(NULL), verbose_(true)
62 {
63 }
64 
65 vpRobot::vpRobot (const vpRobot &robot)
66  :
67  stateRobot(vpRobot::STATE_STOP), frameRobot(vpRobot::CAMERA_FRAME),
68  maxTranslationVelocity (maxTranslationVelocityDefault),
69  maxRotationVelocity (maxRotationVelocityDefault),
70  nDof(0),
71  eJe(), eJeAvailable(false), fJe(), fJeAvailable(false), areJointLimitsAvailable(false),
72  qmin(NULL), qmax(NULL), verbose_(true)
73 {
74  *this = robot;
75 }
76 
81 {
82  if (qmin != NULL) {
83  delete [] qmin;
84  qmin = NULL;
85  }
86  if (qmax != NULL) {
87  delete [] qmax;
88  qmax = NULL;
89  }
90 }
91 
94 {
95  stateRobot = robot.stateRobot;
96  frameRobot = robot.frameRobot;
99  nDof = robot.nDof;
100  eJe = robot.eJe;
101  eJeAvailable = robot.eJeAvailable;
102  fJe= robot.fJe;
103  fJeAvailable = robot.fJeAvailable;
105  qmin = new double [nDof];
106  qmax = new double [nDof];
107  for (int i = 0; i< nDof; i++) {
108  qmin[i] = robot.qmin[i];
109  qmax[i] = robot.qmax[i];
110  }
111  verbose_ = robot.verbose_;
112 
113  return (*this);
114 }
167 vpRobot::saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose)
168 {
169  unsigned int size = v_in.size();
170  if (size != v_max.size())
171  throw vpRobotException (vpRobotException::dimensionError, "Velocity vectors should have the same dimension");
172 
173  double scale = 1; // global scale factor to saturate all the axis
174  for (unsigned int i = 0; i < size; i++)
175  {
176  double v_i = fabs(v_in[i]);
177  double v_max_i = fabs(v_max[i]);
178  if ( v_i > v_max_i ) // Test if we should saturate the axis
179  {
180  double scale_i = v_max_i/v_i;
181  if (scale_i < scale)
182  scale = scale_i;
183 
184  if (verbose)
185  std::cout << "Excess velocity " << v_in[i] << " axis nr. " << i << std::endl;
186  }
187  }
188 
189  vpColVector v_sat(size);
190  v_sat = v_in * scale;
191 
192  return v_sat;
193 }
194 
195 
196 /* -------------------------------------------------------------------------- */
197 /* -------------------------------------------------------------------------- */
198 /* -------------------------------------------------------------------------- */
199 
206 {
207  stateRobot = newState ;
208  return newState ;
209 }
210 
213 {
214  frameRobot = newFrame ;
215  return newFrame ;
216 }
217 
223 {
224  vpColVector r;
225  this ->getPosition (frame, r);
226 
227  return r;
228 }
229 
230 /* ------------------------------------------------------------------------- */
231 /* --- VELOCITY CONTROL ---------------------------------------------------- */
232 /* ------------------------------------------------------------------------- */
233 
241 void
243 {
244  this ->maxTranslationVelocity = v_max;
245  return;
246 }
247 
253 double
255 {
256  return this ->maxTranslationVelocity;
257 }
265 void
267 {
268  this ->maxRotationVelocity = w_max;
269  return;
270 }
271 
278 double
280 {
281  return this ->maxRotationVelocity;
282 }
283 
Error that can be emited by the vpRobot class and its derivates.
void setMaxTranslationVelocity(const double maxVt)
Definition: vpRobot.cpp:242
double maxTranslationVelocity
Definition: vpRobot.h:95
double * qmax
Definition: vpRobot.h:113
double maxRotationVelocity
Definition: vpRobot.h:97
double getMaxTranslationVelocity(void) const
Definition: vpRobot.cpp:254
vpRobot(void)
Definition: vpRobot.cpp:54
class that defines a generic virtual robot
Definition: vpRobot.h:60
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition: vpRobot.cpp:167
vpControlFrameType
Definition: vpRobot.h:78
double getMaxRotationVelocity(void) const
Definition: vpRobot.cpp:279
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition: vpRobot.cpp:205
unsigned int size() const
Definition: vpColVector.h:204
int eJeAvailable
is the robot Jacobian expressed in the end-effector frame available
Definition: vpRobot.h:105
static const double maxTranslationVelocityDefault
Definition: vpRobot.h:96
vpRobotStateType
Definition: vpRobot.h:66
bool verbose_
Definition: vpRobot.h:115
virtual void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q)=0
Get the robot position (frame has to be specified).
static const double maxRotationVelocityDefault
Definition: vpRobot.h:98
int areJointLimitsAvailable
Definition: vpRobot.h:111
void setMaxRotationVelocity(const double maxVr)
Definition: vpRobot.cpp:266
int nDof
number of degrees of freedom
Definition: vpRobot.h:101
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
Definition: vpRobot.h:103
vpRobot & operator=(const vpRobot &robot)
Definition: vpRobot.cpp:93
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
double * qmin
Definition: vpRobot.h:112
vpControlFrameType setRobotFrame(vpRobot::vpControlFrameType newFrame)
Definition: vpRobot.cpp:212
int fJeAvailable
is the robot Jacobian expressed in the robot reference frame available
Definition: vpRobot.h:109
virtual ~vpRobot()
Definition: vpRobot.cpp:80
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
Definition: vpRobot.h:107