Visual Servoing Platform  version 3.2.1 under development (2019-10-23) under development (2019-10-23)
vpRobotCamera.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 http://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 the simplest robot : a free flying camera.
33  *
34  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
44 #include <visp3/robot/vpRobotCamera.h>
45 
46 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
47 
48 #include <visp3/core/vpDebug.h>
49 #include <visp3/core/vpExponentialMap.h>
50 #include <visp3/core/vpHomogeneousMatrix.h>
51 #include <visp3/robot/vpRobotException.h>
52 
72 vpRobotCamera::vpRobotCamera() : cMw_() { init(); }
73 
81 void vpRobotCamera::init()
82 {
83  nDof = 6;
84  eJe.eye(6, 6);
85  eJeAvailable = true;
86  fJeAvailable = false;
88  qmin = NULL;
89  qmax = NULL;
90 
91  setMaxTranslationVelocity(1.); // vx, vy and vz max set to 1 m/s
92  setMaxRotationVelocity(vpMath::rad(90)); // wx, wy and wz max set to 90 deg/s
93 }
94 
100 
112 {
114  cVe = cVe_;
115 }
116 
124 void vpRobotCamera::get_eJe(vpMatrix &eJe_) { eJe_ = this->eJe; }
125 
149 {
150  switch (frame) {
152  case vpRobot::CAMERA_FRAME: {
155  }
156 
157  vpColVector v_max(6);
158 
159  for (unsigned int i = 0; i < 3; i++)
160  v_max[i] = getMaxTranslationVelocity();
161  for (unsigned int i = 3; i < 6; i++)
162  v_max[i] = getMaxRotationVelocity();
163 
164  vpColVector v_sat = vpRobot::saturateVelocities(v, v_max, true);
165 
166  this->cMw_ = vpExponentialMap::direct(v_sat, delta_t_).inverse() * this->cMw_;
167  break;
168  }
170  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the reference frame:"
171  "functionality not implemented");
172  break;
173  case vpRobot::MIXT_FRAME:
174  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the mixt frame:"
175  "functionality not implemented");
176 
177  break;
179  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the end-effector frame:"
180  "functionality not implemented");
181  break;
182  }
183 }
184 
189 void vpRobotCamera::getPosition(vpHomogeneousMatrix &cMw) const { cMw = this->cMw_; }
190 
191 /*
192  Get the current position of the robot.
193 
194  \param frame : Control frame type in which to get the position, either :
195  - in the camera cartesien frame,
196  - joint (articular) coordinates of each axes
197  - in a reference or fixed cartesien frame attached to the robot base
198  - in a mixt cartesien frame (translation in reference frame, and rotation in
199  camera frame)
200 
201  \param position : Measured position of the robot:
202  - in camera cartesien frame, a 6 dimension vector, set to 0.
203 
204  - in articular, a 6 dimension vector corresponding to the articular
205  position of each dof, first the 3 translations, then the 3
206  articular rotation positions represented by a vpRxyzVector.
207 
208  - in reference frame, a 6 dimension vector, the first 3 values correspond to
209  the translation tx, ty, tz in meters (like a vpTranslationVector), and the
210  last 3 values to the rx, ry, rz rotation (like a vpRxyzVector).
211 */
213 {
214  q.resize(6);
215 
216  switch (frame) {
218  q = 0;
219  break;
220 
223  // Convert wMc_ to a position
224  // From fMc extract the pose
225  vpRotationMatrix cRw;
226  this->cMw_.extract(cRw);
227  vpRxyzVector rxyz;
228  rxyz.buildFrom(cRw);
229 
230  for (unsigned int i = 0; i < 3; i++) {
231  q[i] = this->cMw_[i][3]; // translation x,y,z
232  q[i + 3] = rxyz[i]; // Euler rotation x,y,z
233  }
234 
235  break;
236  }
237  case vpRobot::MIXT_FRAME:
238  std::cout << "MIXT_FRAME is not implemented in vpSimulatorCamera::getPosition()" << std::endl;
239  break;
241  std::cout << "END_EFFECTOR_FRAME is not implemented in vpSimulatorCamera::getPosition()" << std::endl;
242  break;
243  }
244 }
245 
251 {
254  }
255 
256  this->cMw_ = cMw;
257 }
258 
259 #elif !defined(VISP_BUILD_SHARED_LIBS)
260 // Work arround to avoid warning: libvisp_robot.a(vpRobotCamera.cpp.o) has no
261 // symbols
262 void dummy_vpRobotCamera(){};
263 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:164
vpRxyzVector buildFrom(const vpRotationMatrix &R)
Error that can be emited by the vpRobot class and its derivates.
void setMaxTranslationVelocity(const double maxVt)
Definition: vpRobot.cpp:239
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setPosition(const vpHomogeneousMatrix &cMw)
double * qmax
Definition: vpRobot.h:114
double getMaxTranslationVelocity(void) const
Definition: vpRobot.cpp:251
void getPosition(vpHomogeneousMatrix &cMw) const
Initialize the position controller.
Definition: vpRobot.h:67
vpHomogeneousMatrix inverse() const
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition: vpRobot.cpp:163
vpControlFrameType
Definition: vpRobot.h:75
double getMaxRotationVelocity(void) const
Definition: vpRobot.cpp:273
void extract(vpRotationMatrix &R) const
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition: vpRobot.cpp:201
Implementation of a rotation matrix and operations on such kind of matrices.
int eJeAvailable
is the robot Jacobian expressed in the end-effector frame available
Definition: vpRobot.h:106
Initialize the velocity controller.
Definition: vpRobot.h:66
virtual vpRobotStateType getRobotState(void) const
Definition: vpRobot.h:144
virtual ~vpRobotCamera()
int areJointLimitsAvailable
Definition: vpRobot.h:112
void get_cVe(vpVelocityTwistMatrix &cVe) const
static double rad(double deg)
Definition: vpMath.h:108
void setMaxRotationVelocity(const double maxVr)
Definition: vpRobot.cpp:260
int nDof
number of degrees of freedom
Definition: vpRobot.h:102
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
Definition: vpRobot.h:104
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
void get_eJe(vpMatrix &eJe)
static vpHomogeneousMatrix direct(const vpColVector &v)
double * qmin
Definition: vpRobot.h:113
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:183
int fJeAvailable
is the robot Jacobian expressed in the robot reference frame available
Definition: vpRobot.h:110
vpHomogeneousMatrix cMw_
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v)
void eye()
Definition: vpMatrix.cpp:492
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:310