Visual Servoing Platform  version 3.6.1 under development (2024-04-28)
vpSimulatorPioneer.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  * Pioneer mobile robot simulator without display.
33  *
34 *****************************************************************************/
35 
43 #include <visp3/core/vpDebug.h>
44 #include <visp3/core/vpExponentialMap.h>
45 #include <visp3/core/vpHomogeneousMatrix.h>
46 #include <visp3/robot/vpRobotException.h>
47 #include <visp3/robot/vpSimulatorPioneer.h>
48 
53 vpSimulatorPioneer::vpSimulatorPioneer() : wMc_(), wMe_(), xm_(0), ym_(0), theta_(0) { init(); }
54 
62 void vpSimulatorPioneer::init()
63 {
64  xm_ = 0;
65  ym_ = 0;
66  theta_ = 0;
67 
68  nDof = 2;
69  eJeAvailable = true;
70  fJeAvailable = false;
72  qmin = nullptr;
73  qmax = nullptr;
74 
75  wMc_ = wMe_ * cMe_.inverse();
76 }
77 
86 
105 {
106  switch (frame) {
110  }
111  setRobotFrame(frame);
112 
113  // v is a 2 dimension vector that contains v,w
114  if (v.size() != 2) {
115  vpERROR_TRACE("Bad dimension of the control vector");
116  throw vpRobotException(vpRobotException::dimensionError, "Bad dimension of the control vector");
117  }
118 
119  vpColVector v_max(2);
120 
121  v_max[0] = getMaxTranslationVelocity();
122  v_max[1] = getMaxRotationVelocity();
123 
124  vpColVector v_sat = vpRobot::saturateVelocities(v, v_max, true);
125 
126  xm_ += delta_t_ * v_sat[0] * cos(theta_);
127  ym_ += delta_t_ * v_sat[0] * sin(theta_);
128  theta_ += delta_t_ * v_sat[1];
129 
130  vpRotationMatrix wRe(0, 0, theta_);
131  vpTranslationVector wte(xm_, ym_, 0);
132  wMe_.buildFrom(wte, wRe);
133  wMc_ = wMe_ * cMe_.inverse();
134 
135  break;
136  } break;
138  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the camera frame:"
139  "functionality not implemented");
140  break;
142  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the articular frame:"
143  "functionality not implemented");
144  case vpRobot::MIXT_FRAME:
145  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the mixt frame:"
146  "functionality not implemented");
147 
148  break;
150  throw vpRobotException(vpRobotException::wrongStateError, "Cannot set a velocity in the end-effector frame:"
151  "functionality not implemented");
152 
153  break;
154  }
155 }
156 
162 
163 /*
164  Get the current position of the robot.
165 
166  \param frame : Control frame type in which to get the position, either :
167  - in the camera cartesien frame,
168  - joint (articular) coordinates of each axes (not implemented)
169  - in a reference or fixed cartesien frame attached to the robot base
170  - in a mixt cartesien frame (translation in reference frame, and rotation in
171  camera frame)
172 
173  \param position : Measured position of the robot:
174  - in camera cartesien frame, a 6 dimension vector, set to 0.
175 
176  - in articular, this functionality is not implemented.
177 
178  - in reference frame, a 6 dimension vector, the first 3 values correspond to
179  the translation tx, ty, tz in meters (like a vpTranslationVector), and the
180  last 3 values to the rx, ry, rz rotation (like a vpRxyzVector).
181 */
183 {
184  q.resize(6);
185 
186  switch (frame) {
188  q = 0;
189  break;
190 
192  std::cout << "ARTICULAR_FRAME is not implemented in "
193  "vpSimulatorPioneer::getPosition()"
194  << std::endl;
195  break;
197  // Convert wMc_ to a position
198  // From fMc extract the pose
199  vpRotationMatrix wRc;
200  this->wMc_.extract(wRc);
201  vpRxyzVector rxyz;
202  rxyz.buildFrom(wRc);
203 
204  for (unsigned int i = 0; i < 3; i++) {
205  q[i] = this->wMc_[i][3]; // translation x,y,z
206  q[i + 3] = rxyz[i]; // Euler rotation x,y,z
207  }
208 
209  break;
210  }
211  case vpRobot::MIXT_FRAME:
212  std::cout << "MIXT_FRAME is not implemented in vpSimulatorCamera::getPosition()" << std::endl;
213  break;
215  std::cout << "END_EFFECTOR_FRAME is not implemented in vpSimulatorCamera::getPosition()" << std::endl;
216  break;
217  }
218 }
unsigned int size() const
Return the number of elements of the 2D array.
Definition: vpArray2D.h:339
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
void resize(unsigned int i, bool flagNullify=true)
Definition: vpColVector.h:1056
@ dimensionError
Bad dimension.
Definition: vpException.h:83
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
void extract(vpRotationMatrix &R) const
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:146
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:102
virtual vpRobotStateType getRobotState(void) const
Definition: vpRobot.h:153
double * qmin
Definition: vpRobot.h:113
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition: vpRobot.cpp:160
vpControlFrameType
Definition: vpRobot.h:75
@ REFERENCE_FRAME
Definition: vpRobot.h:76
@ ARTICULAR_FRAME
Definition: vpRobot.h:78
@ MIXT_FRAME
Definition: vpRobot.h:86
@ CAMERA_FRAME
Definition: vpRobot.h:82
@ END_EFFECTOR_FRAME
Definition: vpRobot.h:81
double * qmax
Definition: vpRobot.h:114
int areJointLimitsAvailable
Definition: vpRobot.h:112
int fJeAvailable
is the robot Jacobian expressed in the robot reference frame available
Definition: vpRobot.h:110
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
Definition: vpRobot.h:65
double getMaxRotationVelocity(void) const
Definition: vpRobot.cpp:270
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition: vpRobot.cpp:198
int eJeAvailable
is the robot Jacobian expressed in the end-effector frame available
Definition: vpRobot.h:106
double getMaxTranslationVelocity(void) const
Definition: vpRobot.cpp:248
vpControlFrameType setRobotFrame(vpRobot::vpControlFrameType newFrame)
Definition: vpRobot.cpp:204
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:176
vpRxyzVector buildFrom(const vpRotationMatrix &R)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) vp_override
vpHomogeneousMatrix wMc_
void getPosition(vpHomogeneousMatrix &wMc) const
vpHomogeneousMatrix wMe_
Class that consider the case of a translation vector.
vpMatrix get_eJe() const
Definition: vpUnicycle.h:94
vpHomogeneousMatrix cMe_
Definition: vpUnicycle.h:114
#define vpERROR_TRACE
Definition: vpDebug.h:382