Visual Servoing Platform  version 3.6.1 under development (2024-12-17)
vpRobotCamera.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/robot/vpRobotCamera.h>
42 
43 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
44 
45 #include <visp3/core/vpDebug.h>
46 #include <visp3/core/vpExponentialMap.h>
47 #include <visp3/core/vpHomogeneousMatrix.h>
48 #include <visp3/robot/vpRobotException.h>
49 
50 BEGIN_VISP_NAMESPACE
70 vpRobotCamera::vpRobotCamera() : cMw_() { init(); }
71 
79 void vpRobotCamera::init()
80 {
81  nDof = 6;
82  eJe.eye(6, 6);
83  eJeAvailable = true;
84  fJeAvailable = false;
85  areJointLimitsAvailable = false;
86  qmin = nullptr;
87  qmax = nullptr;
88 
89  setMaxTranslationVelocity(1.); // vx, vy and vz max set to 1 m/s
90  setMaxRotationVelocity(vpMath::rad(90)); // wx, wy and wz max set to 90 deg/s
91 }
92 
103 void vpRobotCamera::get_cVe(vpVelocityTwistMatrix &cVe) const
104 {
106  cVe = cVe_;
107 }
108 
116 void vpRobotCamera::get_eJe(vpMatrix &eJe_) { eJe_ = this->eJe; }
117 
140 void vpRobotCamera::setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v)
141 {
142  switch (frame) {
144  case vpRobot::CAMERA_FRAME: {
145  if (vpRobot::STATE_VELOCITY_CONTROL != getRobotState()) {
146  setRobotState(vpRobot::STATE_VELOCITY_CONTROL);
147  }
148 
149  vpColVector v_max(6);
150 
151  for (unsigned int i = 0; i < 3; i++)
152  v_max[i] = getMaxTranslationVelocity();
153  for (unsigned int i = 3; i < 6; i++)
154  v_max[i] = getMaxRotationVelocity();
155 
156  vpColVector v_sat = vpRobot::saturateVelocities(v, v_max, true);
157 
158  this->cMw_ = vpExponentialMap::direct(v_sat, delta_t_).inverse() * this->cMw_;
159  break;
160  }
162  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the reference frame:"
163  "functionality not implemented");
164  break;
165  case vpRobot::MIXT_FRAME:
166  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the mixt frame:"
167  "functionality not implemented");
168 
169  break;
171  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the end-effector frame:"
172  "functionality not implemented");
173  break;
174  }
175 }
176 
181 void vpRobotCamera::getPosition(vpHomogeneousMatrix &cMw) const { cMw = this->cMw_; }
182 
183 /*
184  Get the current position of the robot.
185 
186  \param frame : Control frame type in which to get the position, either :
187  - in the camera cartesian frame,
188  - joint (articular) coordinates of each axes
189  - in a reference or fixed cartesian frame attached to the robot base
190  - in a mixt cartesian frame (translation in reference frame, and rotation in
191  camera frame)
192 
193  \param position : Measured position of the robot:
194  - in camera cartesian frame, a 6 dimension vector, set to 0.
195 
196  - in articular, a 6 dimension vector corresponding to the articular
197  position of each dof, first the 3 translations, then the 3
198  articular rotation positions represented by a vpRxyzVector.
199 
200  - in reference frame, a 6 dimension vector, the first 3 values correspond to
201  the translation tx, ty, tz in meters (like a vpTranslationVector), and the
202  last 3 values to the rx, ry, rz rotation (like a vpRxyzVector).
203 */
204 void vpRobotCamera::getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q)
205 {
206  q.resize(6);
207 
208  switch (frame) {
210  q = 0;
211  break;
212 
215  // Convert wMc_ to a position
216  // From fMc extract the pose
217  vpRotationMatrix cRw;
218  this->cMw_.extract(cRw);
219  vpRxyzVector rxyz;
220  rxyz.buildFrom(cRw);
221 
222  for (unsigned int i = 0; i < 3; i++) {
223  q[i] = this->cMw_[i][3]; // translation x,y,z
224  q[i + 3] = rxyz[i]; // Euler rotation x,y,z
225  }
226 
227  break;
228  }
229  case vpRobot::MIXT_FRAME:
230  std::cout << "MIXT_FRAME is not implemented in vpSimulatorCamera::getPosition()" << std::endl;
231  break;
233  std::cout << "END_EFFECTOR_FRAME is not implemented in vpSimulatorCamera::getPosition()" << std::endl;
234  break;
235  }
236 }
237 
242 void vpRobotCamera::setPosition(const vpHomogeneousMatrix &cMw)
243 {
244  if (vpRobot::STATE_POSITION_CONTROL != getRobotState()) {
245  setRobotState(vpRobot::STATE_POSITION_CONTROL);
246  }
247 
248  this->cMw_ = cMw;
249 }
250 END_VISP_NAMESPACE
251 #elif !defined(VISP_BUILD_SHARED_LIBS)
252 // Work around to avoid warning: libvisp_robot.a(vpRobotCamera.cpp.o) has no symbols
253 void dummy_vpRobotCamera() { };
254 #endif
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.
vpHomogeneousMatrix inverse() const
void init(unsigned int h, unsigned int w, Type value)
Definition: vpImage.h:378
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.
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
@ STATE_POSITION_CONTROL
Initialize the position controller.
Definition: vpRobot.h:68
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
Definition: vpRobot.h:67
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 & buildFrom(const vpRotationMatrix &R)