Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpSimulatorCamera.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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 *****************************************************************************/
35 
41 #include <visp3/core/vpDebug.h>
42 #include <visp3/core/vpExponentialMap.h>
43 #include <visp3/core/vpHomogeneousMatrix.h>
44 #include <visp3/robot/vpRobotException.h>
45 #include <visp3/robot/vpSimulatorCamera.h>
46 
54 
62 void vpSimulatorCamera::init()
63 {
64  nDof = 6;
65  eJe.eye(6, 6);
66  eJeAvailable = true;
67  fJeAvailable = false;
69  qmin = nullptr;
70  qmax = nullptr;
71 
72  setMaxTranslationVelocity(1.); // vx, vy and vz max set to 1 m/s
73  setMaxRotationVelocity(vpMath::rad(90)); // wx, wy and wz max set to 90 deg/s
74 }
75 
87 {
89  cVe = cVe_;
90 }
91 
100 void vpSimulatorCamera::get_eJe(vpMatrix &eJe_) { eJe_ = this->eJe; }
101 
106 void vpSimulatorCamera::getPosition(vpHomogeneousMatrix &wMc) const { wMc = this->wMc_; }
112 
113 /*
114  Get the current position of the camera.
115 
116  \param frame : Control frame type in which to get the position, either :
117  - in the camera cartesian frame,
118  - joint (articular) coordinates of each axes
119  - in a reference or fixed cartesian frame attached to the robot base
120  - in a mixt cartesian frame (translation in reference frame, and rotation in
121  camera frame)
122 
123  \param position : Measured position of the robot:
124  - in camera cartesian frame, a 6 dimension vector, set to 0.
125 
126  - in articular, a 6 dimension vector corresponding to the articular
127  position of each dof, first the 3 translations, then the 3
128  articular rotation positions represented by a vpRxyzVector.
129 
130  - in reference frame, a 6 dimension vector, the first 3 values correspond to
131  the translation tx, ty, tz in meters (like a vpTranslationVector), and the
132  last 3 values to the rx, ry, rz rotation (like a vpRxyzVector).
133 */
135 {
136  q.resize(6);
137 
138  switch (frame) {
140  q = 0;
141  break;
142 
145  // Convert wMc_ to a position
146  // From fMc extract the pose
147  vpRotationMatrix wRc;
148  this->wMc_.extract(wRc);
149  vpRxyzVector rxyz;
150  rxyz.build(wRc);
151 
152  for (unsigned int i = 0; i < 3; i++) {
153  q[i] = this->wMc_[i][3]; // translation x,y,z
154  q[i + 3] = rxyz[i]; // Euler rotation x,y,z
155  }
156 
157  break;
158  }
159  case vpRobot::MIXT_FRAME:
160  std::cout << "MIXT_FRAME is not implemented in vpSimulatorCamera::getPosition()" << std::endl;
161  break;
163  std::cout << "END_EFFECTOR_FRAME is not implemented in vpSimulatorCamera::getPosition()" << std::endl;
164  break;
165  }
166 }
167 
191 {
194  }
195 
196  switch (frame) {
198  case vpRobot::CAMERA_FRAME: {
199  vpColVector v_max(6);
200 
201  for (unsigned int i = 0; i < 3; i++)
202  v_max[i] = getMaxTranslationVelocity();
203  for (unsigned int i = 3; i < 6; i++)
204  v_max[i] = getMaxRotationVelocity();
205 
206  vpColVector v_sat = vpRobot::saturateVelocities(v, v_max, true);
207 
209  setRobotFrame(frame);
210  break;
211  }
213  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the reference frame:"
214  "functionality not implemented");
215  break;
216  case vpRobot::MIXT_FRAME:
217  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the mixt frame:"
218  "functionality not implemented");
219 
220  break;
222  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the end-effector frame:"
223  "functionality not implemented");
224 
225  break;
226  }
227 }
228 
235 {
238  }
239 
240  this->wMc_ = wMc;
241 }
242 END_VISP_NAMESPACE
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
void resize(unsigned int i, bool flagNullify=true)
Definition: vpColVector.h:1143
static vpHomogeneousMatrix direct(const vpColVector &v)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void extract(vpRotationMatrix &R) const
static double rad(double deg)
Definition: vpMath.h:129
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
Error that can be emitted by the vpRobot class and its derivatives.
@ wrongStateError
Wrong robot state.
int nDof
number of degrees of freedom
Definition: vpRobot.h:104
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
Definition: vpRobot.h:106
virtual vpRobotStateType getRobotState(void) const
Definition: vpRobot.h:155
double * qmin
Definition: vpRobot.h:115
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition: vpRobot.cpp:164
vpControlFrameType
Definition: vpRobot.h:77
@ REFERENCE_FRAME
Definition: vpRobot.h:78
@ ARTICULAR_FRAME
Definition: vpRobot.h:80
@ MIXT_FRAME
Definition: vpRobot.h:88
@ CAMERA_FRAME
Definition: vpRobot.h:84
@ END_EFFECTOR_FRAME
Definition: vpRobot.h:83
double * qmax
Definition: vpRobot.h:116
int areJointLimitsAvailable
Definition: vpRobot.h:114
int fJeAvailable
is the robot Jacobian expressed in the robot reference frame available
Definition: vpRobot.h:112
@ STATE_POSITION_CONTROL
Initialize the position controller.
Definition: vpRobot.h:68
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
Definition: vpRobot.h:67
double getMaxRotationVelocity(void) const
Definition: vpRobot.cpp:274
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition: vpRobot.cpp:202
int eJeAvailable
is the robot Jacobian expressed in the end-effector frame available
Definition: vpRobot.h:108
double getMaxTranslationVelocity(void) const
Definition: vpRobot.cpp:252
void setMaxRotationVelocity(double maxVr)
Definition: vpRobot.cpp:261
vpControlFrameType setRobotFrame(vpRobot::vpControlFrameType newFrame)
Definition: vpRobot.cpp:208
void setMaxTranslationVelocity(double maxVt)
Definition: vpRobot.cpp:240
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:183
vpRxyzVector & build(const vpRotationMatrix &R)
void get_eJe(vpMatrix &eJe) VP_OVERRIDE
vpHomogeneousMatrix wMc_
void setPosition(const vpHomogeneousMatrix &wMc)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
vpHomogeneousMatrix getPosition() const
void get_cVe(vpVelocityTwistMatrix &cVe) const