Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpRobot.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Generic virtual robot.
32 */
33
34#include <visp3/core/vpDebug.h>
35#include <visp3/robot/vpRobot.h>
36#include <visp3/robot/vpRobotException.h>
37
41
42/* -------------------------------------------------------------------------
43 */
44/* --- CONSTRUCTEUR --------------------------------------------------------
45 */
46/* -------------------------------------------------------------------------
47 */
48
55
57 : stateRobot(vpRobot::STATE_STOP), frameRobot(vpRobot::CAMERA_FRAME),
59 eJe(), eJeAvailable(false), fJe(), fJeAvailable(false), areJointLimitsAvailable(false), qmin(nullptr), qmax(nullptr),
60 verbose_(true)
61{
62 *this = robot;
63}
64
69{
70 if (qmin != nullptr) {
71 delete[] qmin;
72 qmin = nullptr;
73 }
74 if (qmax != nullptr) {
75 delete[] qmax;
76 qmax = nullptr;
77 }
78}
79
82{
83 stateRobot = robot.stateRobot;
84 frameRobot = robot.frameRobot;
85 maxTranslationVelocity = robot.maxTranslationVelocity;
86 maxRotationVelocity = robot.maxRotationVelocity;
87 nDof = robot.nDof;
88 eJe = robot.eJe;
89 eJeAvailable = robot.eJeAvailable;
90 fJe = robot.fJe;
91 fJeAvailable = robot.fJeAvailable;
92 areJointLimitsAvailable = robot.areJointLimitsAvailable;
93 qmin = new double[nDof];
94 qmax = new double[nDof];
95 for (int i = 0; i < nDof; i++) {
96 qmin[i] = robot.qmin[i];
97 qmax[i] = robot.qmax[i];
98 }
99 verbose_ = robot.verbose_;
100
101 return (*this);
102}
103
162vpColVector vpRobot::saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose)
163{
164 unsigned int size = v_in.size();
165 if (size != v_max.size())
166 throw vpRobotException(vpRobotException::dimensionError, "Velocity vectors should have the same dimension");
167
168 double scale = 1; // global scale factor to saturate all the axis
169 for (unsigned int i = 0; i < size; i++) {
170 double v_i = fabs(v_in[i]);
171 double v_max_i = fabs(v_max[i]);
172 if (v_i > v_max_i) // Test if we should saturate the axis
173 {
174 double scale_i = v_max_i / v_i;
175 if (scale_i < scale)
176 scale = scale_i;
177
178 if (verbose)
179 std::cout << "Excess velocity " << v_in[i] << " axis nr. " << i << std::endl;
180 }
181 }
182
183 vpColVector v_sat(size);
184 v_sat = v_in * scale;
185
186 return v_sat;
187}
188
189/* --------------------------------------------------------------------------
190 */
191/* --------------------------------------------------------------------------
192 */
193/* --------------------------------------------------------------------------
194 */
195
201{
202 stateRobot = newState;
203 return newState;
204}
205
207{
208 frameRobot = newFrame;
209 return newFrame;
210}
211
216{
217 vpColVector r;
218 this->getPosition(frame, r);
219
220 return r;
221}
222
223/* -------------------------------------------------------------------------
224 */
225/* --- VELOCITY CONTROL ----------------------------------------------------
226 */
227/* -------------------------------------------------------------------------
228 */
229
239{
240 this->maxTranslationVelocity = v_max;
241 return;
242}
243
251
260{
261 this->maxRotationVelocity = w_max;
262 return;
263}
264
272double vpRobot::getMaxRotationVelocity(void) const { return this->maxRotationVelocity; }
273END_VISP_NAMESPACE
unsigned int size() const
Return the number of elements of the 2D array.
Definition vpArray2D.h:435
Implementation of column vector and the associated operations.
@ dimensionError
Bad dimension.
Definition vpException.h:71
Error that can be emitted by the vpRobot class and its derivatives.
int nDof
number of degrees of freedom
Definition vpRobot.h:101
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
Definition vpRobot.h:103
vpRobot & operator=(const vpRobot &robot)
Definition vpRobot.cpp:81
virtual ~vpRobot()
Definition vpRobot.cpp:68
double * qmin
Definition vpRobot.h:112
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition vpRobot.cpp:162
vpControlFrameType
Definition vpRobot.h:74
@ CAMERA_FRAME
Definition vpRobot.h:81
static const double maxRotationVelocityDefault
Definition vpRobot.h:98
double * qmax
Definition vpRobot.h:113
int areJointLimitsAvailable
Definition vpRobot.h:111
virtual void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)=0
Get the robot position (frame has to be specified).
int fJeAvailable
is the robot Jacobian expressed in the robot reference frame available
Definition vpRobot.h:109
vpRobotStateType
Definition vpRobot.h:62
@ STATE_STOP
Stops robot motion especially in velocity and acceleration control.
Definition vpRobot.h:63
static const double maxTranslationVelocityDefault
Definition vpRobot.h:96
double getMaxRotationVelocity(void) const
Definition vpRobot.cpp:272
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
Definition vpRobot.h:107
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition vpRobot.cpp:200
double maxTranslationVelocity
Definition vpRobot.h:95
int eJeAvailable
is the robot Jacobian expressed in the end-effector frame available
Definition vpRobot.h:105
double getMaxTranslationVelocity(void) const
Definition vpRobot.cpp:250
vpRobot(void)
Definition vpRobot.cpp:49
double maxRotationVelocity
Definition vpRobot.h:97
void setMaxRotationVelocity(double maxVr)
Definition vpRobot.cpp:259
vpControlFrameType setRobotFrame(vpRobot::vpControlFrameType newFrame)
Definition vpRobot.cpp:206
void setMaxTranslationVelocity(double maxVt)
Definition vpRobot.cpp:238
bool verbose_
Definition vpRobot.h:115