ViSP  2.9.0
vpRobot.cpp
1 /****************************************************************************
2  *
3  * $Id: vpRobot.cpp 4632 2014-02-03 17:06:40Z 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 
79 {
80  stateRobot = robot.stateRobot;
81  frameRobot = robot.frameRobot;
84  nDof = robot.nDof;
85  eJe = robot.eJe;
86  eJeAvailable = robot.eJeAvailable;
87  fJe= robot.fJe;
88  fJeAvailable = robot.fJeAvailable;
90  qmin = new double [nDof];
91  qmax = new double [nDof];
92  for (int i = 0; i< nDof; i++) {
93  qmin[i] = robot.qmin[i];
94  qmax[i] = robot.qmax[i];
95  }
96  verbose_ = robot.verbose_;
97 
98  return (*this);
99 }
152 vpRobot::saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose)
153 {
154  unsigned int size = v_in.size();
155  if (size != v_max.size())
156  throw vpRobotException (vpRobotException::dimensionError, "Velocity vectors should have the same dimension");
157 
158  double scale = 1; // global scale factor to saturate all the axis
159  for (unsigned int i = 0; i < size; i++)
160  {
161  double v_i = fabs(v_in[i]);
162  double v_max_i = fabs(v_max[i]);
163  if ( v_i > v_max_i ) // Test if we should saturate the axis
164  {
165  double scale_i = v_max_i/v_i;
166  if (scale_i < scale)
167  scale = scale_i;
168 
169  if (verbose)
170  std::cout << "Excess velocity " << v_in[i] << " axis nr. " << i << std::endl;
171  }
172  }
173 
174  vpColVector v_sat(size);
175  v_sat = v_in * scale;
176 
177  return v_sat;
178 }
179 
180 
181 /* -------------------------------------------------------------------------- */
182 /* -------------------------------------------------------------------------- */
183 /* -------------------------------------------------------------------------- */
184 
191 {
192  stateRobot = newState ;
193  return newState ;
194 }
195 
198 {
199  frameRobot = newFrame ;
200  return newFrame ;
201 }
202 
208 {
209  vpColVector r;
210  this ->getPosition (frame, r);
211 
212  return r;
213 }
214 
215 /* ------------------------------------------------------------------------- */
216 /* --- VELOCITY CONTROL ---------------------------------------------------- */
217 /* ------------------------------------------------------------------------- */
218 
226 void
228 {
229  this ->maxTranslationVelocity = v_max;
230  return;
231 }
232 
238 double
240 {
241  return this ->maxTranslationVelocity;
242 }
250 void
252 {
253  this ->maxRotationVelocity = w_max;
254  return;
255 }
256 
263 double
265 {
266  return this ->maxRotationVelocity;
267 }
268 
Error that can be emited by the vpRobot class and its derivates.
void setMaxTranslationVelocity(const double maxVt)
Definition: vpRobot.cpp:227
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:239
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:152
vpControlFrameType
Definition: vpRobot.h:78
double getMaxRotationVelocity(void) const
Definition: vpRobot.cpp:264
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition: vpRobot.cpp:190
unsigned int size() const
Definition: vpColVector.h:199
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:251
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:78
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:197
int fJeAvailable
is the robot Jacobian expressed in the robot reference frame available
Definition: vpRobot.h:109
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
Definition: vpRobot.h:107