ViSP  2.8.0
vpRobot.cpp
1 /****************************************************************************
2  *
3  * $Id: vpRobot.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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  maxTranslationVelocity (maxTranslationVelocityDefault),
57  maxRotationVelocity (maxRotationVelocityDefault)
58 {
59  frameRobot = vpRobot::CAMERA_FRAME;
60  stateRobot = vpRobot::STATE_STOP ;
61  verbose_ = true;
62 }
63 
116 vpRobot::saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose)
117 {
118  unsigned int size = v_in.size();
119  if (size != v_max.size())
120  throw vpRobotException (vpRobotException::dimensionError, "Velocity vectors should have the same dimension");
121 
122  double scale = 1; // global scale factor to saturate all the axis
123  for (unsigned int i = 0; i < size; i++)
124  {
125  double v_i = fabs(v_in[i]);
126  double v_max_i = fabs(v_max[i]);
127  if ( v_i > v_max_i ) // Test if we should saturate the axis
128  {
129  double scale_i = v_max_i/v_i;
130  if (scale_i < scale)
131  scale = scale_i;
132 
133  if (verbose)
134  std::cout << "Excess velocity " << v_in[i] << " axis nr. " << i << std::endl;
135  }
136  }
137 
138  vpColVector v_sat(size);
139  v_sat = v_in * scale;
140 
141  return v_sat;
142 }
143 
144 
145 /* -------------------------------------------------------------------------- */
146 /* -------------------------------------------------------------------------- */
147 /* -------------------------------------------------------------------------- */
148 
155 {
156  stateRobot = newState ;
157  return newState ;
158 }
159 
162 {
163  frameRobot = newFrame ;
164  return newFrame ;
165 }
166 
172 {
173  vpColVector r;
174  this ->getPosition (frame, r);
175 
176  return r;
177 }
178 
179 /* ------------------------------------------------------------------------- */
180 /* --- VELOCITY CONTROL ---------------------------------------------------- */
181 /* ------------------------------------------------------------------------- */
182 
190 void
192 {
193  this ->maxTranslationVelocity = v_max;
194  return;
195 }
196 
202 double
204 {
205  return this ->maxTranslationVelocity;
206 }
214 void
216 {
217  this ->maxRotationVelocity = w_max;
218  return;
219 }
220 
227 double
229 {
230  return this ->maxRotationVelocity;
231 }
232 
Error that can be emited by the vpRobot class and its derivates.
void setMaxTranslationVelocity(const double maxVt)
Definition: vpRobot.cpp:191
double getMaxTranslationVelocity(void) const
Definition: vpRobot.cpp:203
vpRobot(void)
Definition: vpRobot.cpp:54
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition: vpRobot.cpp:116
vpControlFrameType
Definition: vpRobot.h:78
double getMaxRotationVelocity(void) const
Definition: vpRobot.cpp:228
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition: vpRobot.cpp:154
unsigned int size() const
Definition: vpColVector.h:199
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
void setMaxRotationVelocity(const double maxVr)
Definition: vpRobot.cpp:215
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
vpControlFrameType setRobotFrame(vpRobot::vpControlFrameType newFrame)
Definition: vpRobot.cpp:161