Visual Servoing Platform  version 3.4.0
vpSimulatorCamera.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/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  break;
171  std::cout << "END_EFFECTOR_FRAME is not implemented in vpSimulatorCamera::getPosition()" << std::endl;
172  break;
173  }
174 }
175 
199 {
202  }
203 
204  switch (frame) {
206  case vpRobot::CAMERA_FRAME: {
207  vpColVector v_max(6);
208 
209  for (unsigned int i = 0; i < 3; i++)
210  v_max[i] = getMaxTranslationVelocity();
211  for (unsigned int i = 3; i < 6; i++)
212  v_max[i] = getMaxRotationVelocity();
213 
214  vpColVector v_sat = vpRobot::saturateVelocities(v, v_max, true);
215 
217  setRobotFrame(frame);
218  break;
219  }
221  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the reference frame:"
222  "functionality not implemented");
223  break;
224  case vpRobot::MIXT_FRAME:
225  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the mixt frame:"
226  "functionality not implemented");
227 
228  break;
230  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the end-effector frame:"
231  "functionality not implemented");
232 
233  break;
234  }
235 }
236 
243 {
246  }
247 
248  this->wMc_ = wMc;
249 }
void setPosition(const vpHomogeneousMatrix &wMc)
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:153
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)
Implementation of an homogeneous matrix and operations on such kind of matrices.
double * qmax
Definition: vpRobot.h:114
double getMaxTranslationVelocity(void) const
Definition: vpRobot.cpp:251
Initialize the position controller.
Definition: vpRobot.h:67
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition: vpRobot.cpp:163
vpControlFrameType
Definition: vpRobot.h:75
vpHomogeneousMatrix wMc_
double getMaxRotationVelocity(void) const
Definition: vpRobot.cpp:273
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition: vpRobot.cpp:201
void setMaxRotationVelocity(double maxVr)
Definition: vpRobot.cpp:260
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
void get_cVe(vpVelocityTwistMatrix &cVe) const
Initialize the velocity controller.
Definition: vpRobot.h:66
void extract(vpRotationMatrix &R) const
vpHomogeneousMatrix getPosition() const
int areJointLimitsAvailable
Definition: vpRobot.h:112
static double rad(double deg)
Definition: vpMath.h:110
int nDof
number of degrees of freedom
Definition: vpRobot.h:102
void resize(unsigned int i, bool flagNullify=true)
Definition: vpColVector.h:310
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
virtual vpRobotStateType getRobotState(void) const
Definition: vpRobot.h:144
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
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:110
void get_eJe(vpMatrix &eJe)
void setMaxTranslationVelocity(double maxVt)
Definition: vpRobot.cpp:239
void eye()
Definition: vpMatrix.cpp:449