ViSP  2.6.2
vpRobot.cpp
1 /****************************************************************************
2  *
3  * $Id: vpRobot.cpp 3695 2012-05-03 07:20:19Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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  stateRobot = vpRobot::STATE_STOP ;
60 }
61 
114 vpRobot::saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose)
115 {
116  unsigned int size = v_in.size();
117  if (size != v_max.size())
118  throw vpRobotException (vpRobotException::dimensionError, "Velocity vectors should have the same dimension");
119 
120  double scale = 1; // global scale factor to saturate all the axis
121  for (unsigned int i = 0; i < size; i++)
122  {
123  double v_i = fabs(v_in[i]);
124  double v_max_i = fabs(v_max[i]);
125  if ( v_i > v_max_i ) // Test if we should saturate the axis
126  {
127  double scale_i = v_max_i/v_i;
128  if (scale_i < scale)
129  scale = scale_i;
130 
131  if (verbose)
132  std::cout << "Excess velocity " << v_in[i] << " axis nr. " << i << std::endl;
133  }
134  }
135 
136  vpColVector v_sat(size);
137  v_sat = v_in * scale;
138 
139  return v_sat;
140 }
141 
142 
143 /* -------------------------------------------------------------------------- */
144 /* -------------------------------------------------------------------------- */
145 /* -------------------------------------------------------------------------- */
146 
153 {
154  stateRobot = newState ;
155  return newState ;
156 }
157 
160 {
161  frameRobot = newFrame ;
162  return newFrame ;
163 }
164 
177 {
178  vpColVector r;
179  this ->getPosition (repere, r);
180 
181  return r;
182 }
183 
184 /* ------------------------------------------------------------------------- */
185 /* --- VELOCITY CONTROL ---------------------------------------------------- */
186 /* ------------------------------------------------------------------------- */
187 
195 void
197 {
198  this ->maxTranslationVelocity = maxVt;
199  return;
200 }
201 
207 double
209 {
210  return this ->maxTranslationVelocity;
211 }
219 void
221 {
222  this ->maxRotationVelocity = maxVr;
223  return;
224 }
225 
232 double
234 {
235  return this ->maxRotationVelocity;
236 }
237 
Error that can be emited by the vpRobot class and its derivates.
void setMaxTranslationVelocity(const double maxVt)
Definition: vpRobot.cpp:196
double getMaxTranslationVelocity(void) const
Definition: vpRobot.cpp:208
vpRobot(void)
Definition: vpRobot.cpp:54
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition: vpRobot.cpp:114
vpControlFrameType
Definition: vpRobot.h:83
double getMaxRotationVelocity(void) const
Definition: vpRobot.cpp:233
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition: vpRobot.cpp:152
unsigned int size() const
Definition: vpColVector.h:198
static const double maxTranslationVelocityDefault
Definition: vpRobot.h:106
vpRobotStateType
Definition: vpRobot.h:66
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:108
void setMaxRotationVelocity(const double maxVr)
Definition: vpRobot.cpp:220
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:159