Visual Servoing Platform  version 3.1.0
vpSimulatorCamera.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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/core/vpDebug.h>
45 #include <visp3/core/vpExponentialMap.h>
46 #include <visp3/core/vpHomogeneousMatrix.h>
47 #include <visp3/robot/vpRobotException.h>
48 #include <visp3/robot/vpSimulatorCamera.h>
49 
56 
64 void vpSimulatorCamera::init()
65 {
66  nDof = 6;
67  eJe.eye(6, 6);
68  eJeAvailable = true;
69  fJeAvailable = false;
71  qmin = NULL;
72  qmax = NULL;
73 
74  setMaxTranslationVelocity(1.); // vx, vy and vz max set to 1 m/s
75  setMaxRotationVelocity(vpMath::rad(90)); // wx, wy and wz max set to 90 deg/s
76 }
77 
83 
95 {
97  cVe = cVe_;
98 }
99 
108 void vpSimulatorCamera::get_eJe(vpMatrix &eJe_) { eJe_ = this->eJe; }
109 
114 void vpSimulatorCamera::getPosition(vpHomogeneousMatrix &wMc) const { wMc = this->wMc_; }
120 
121 /*
122  Get the current position of the camera.
123 
124  \param frame : Control frame type in which to get the position, either :
125  - in the camera cartesien frame,
126  - joint (articular) coordinates of each axes
127  - in a reference or fixed cartesien frame attached to the robot base
128  - in a mixt cartesien frame (translation in reference frame, and rotation in
129  camera frame)
130 
131  \param position : Measured position of the robot:
132  - in camera cartesien frame, a 6 dimension vector, set to 0.
133 
134  - in articular, a 6 dimension vector corresponding to the articular
135  position of each dof, first the 3 translations, then the 3
136  articular rotation positions represented by a vpRxyzVector.
137 
138  - in reference frame, a 6 dimension vector, the first 3 values correspond to
139  the translation tx, ty, tz in meters (like a vpTranslationVector), and the
140  last 3 values to the rx, ry, rz rotation (like a vpRxyzVector).
141 */
143 {
144  q.resize(6);
145 
146  switch (frame) {
148  q = 0;
149  break;
150 
153  // Convert wMc_ to a position
154  // From fMc extract the pose
155  vpRotationMatrix wRc;
156  this->wMc_.extract(wRc);
157  vpRxyzVector rxyz;
158  rxyz.buildFrom(wRc);
159 
160  for (unsigned int i = 0; i < 3; i++) {
161  q[i] = this->wMc_[i][3]; // translation x,y,z
162  q[i + 3] = rxyz[i]; // Euler rotation x,y,z
163  }
164 
165  break;
166  }
167  case vpRobot::MIXT_FRAME:
168  std::cout << "MIXT_FRAME is not implemented in vpSimulatorCamera::getPosition()" << std::endl;
169  }
170 }
171 
195 {
198  }
199 
200  switch (frame) {
202  case vpRobot::CAMERA_FRAME: {
203  vpColVector v_max(6);
204 
205  for (unsigned int i = 0; i < 3; i++)
206  v_max[i] = getMaxTranslationVelocity();
207  for (unsigned int i = 3; i < 6; i++)
208  v_max[i] = getMaxRotationVelocity();
209 
210  vpColVector v_sat = vpRobot::saturateVelocities(v, v_max, true);
211 
213  setRobotFrame(frame);
214  break;
215  }
217  vpERROR_TRACE("Cannot set a velocity in the reference frame: "
218  "functionality not implemented");
219  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the reference frame:"
220  "functionality not implemented");
221  break;
222  case vpRobot::MIXT_FRAME:
223  vpERROR_TRACE("Cannot set a velocity in the mixt frame: "
224  "functionality not implemented");
225  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the mixt frame:"
226  "functionality not implemented");
227 
228  break;
229  }
230 }
231 
238 {
241  }
242 
243  this->wMc_ = wMc;
244 }
void setPosition(const vpHomogeneousMatrix &wMc)
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
vpRxyzVector buildFrom(const vpRotationMatrix &R)
Error that can be emited by the vpRobot class and its derivates.
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
void setMaxTranslationVelocity(const double maxVt)
Definition: vpRobot.cpp:239
Implementation of an homogeneous matrix and operations on such kind of matrices.
double * qmax
Definition: vpRobot.h:109
#define vpERROR_TRACE
Definition: vpDebug.h:393
double getMaxTranslationVelocity(void) const
Definition: vpRobot.cpp:251
Initialize the position controller.
Definition: vpRobot.h:68
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition: vpRobot.cpp:163
vpControlFrameType
Definition: vpRobot.h:75
vpHomogeneousMatrix getPosition() const
double getMaxRotationVelocity(void) const
Definition: vpRobot.cpp:273
void extract(vpRotationMatrix &R) const
vpHomogeneousMatrix wMc_
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:101
Initialize the velocity controller.
Definition: vpRobot.h:67
virtual vpRobotStateType getRobotState(void) const
Definition: vpRobot.h:139
int areJointLimitsAvailable
Definition: vpRobot.h:107
static double rad(double deg)
Definition: vpMath.h:102
void setMaxRotationVelocity(const double maxVr)
Definition: vpRobot.cpp:260
int nDof
number of degrees of freedom
Definition: vpRobot.h:97
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
Definition: vpRobot.h:99
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
static vpHomogeneousMatrix direct(const vpColVector &v)
double * qmin
Definition: vpRobot.h:108
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:156
vpControlFrameType setRobotFrame(vpRobot::vpControlFrameType newFrame)
Definition: vpRobot.cpp:207
int fJeAvailable
is the robot Jacobian expressed in the robot reference frame available
Definition: vpRobot.h:105
void get_eJe(vpMatrix &eJe)
void get_cVe(vpVelocityTwistMatrix &cVe) const
void eye()
Definition: vpMatrix.cpp:360
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:241