Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
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
38
BEGIN_VISP_NAMESPACE
39
const
double
vpRobot::maxTranslationVelocityDefault
= 0.2;
40
const
double
vpRobot::maxRotationVelocityDefault
= 0.7;
41
42
/* -------------------------------------------------------------------------
43
*/
44
/* --- CONSTRUCTEUR --------------------------------------------------------
45
*/
46
/* -------------------------------------------------------------------------
47
*/
48
49
vpRobot::vpRobot
(
void
)
50
: stateRobot(
vpRobot
::
STATE_STOP
), frameRobot(
vpRobot
::
CAMERA_FRAME
),
51
maxTranslationVelocity
(
maxTranslationVelocityDefault
),
maxRotationVelocity
(
maxRotationVelocityDefault
),
nDof
(0),
52
eJe
(),
eJeAvailable
(false),
fJe
(),
fJeAvailable
(false),
areJointLimitsAvailable
(false),
qmin
(nullptr),
qmax
(nullptr),
53
verbose_
(true)
54
{ }
55
56
vpRobot::vpRobot
(
const
vpRobot
&robot)
57
: stateRobot(
vpRobot
::
STATE_STOP
), frameRobot(
vpRobot
::
CAMERA_FRAME
),
58
maxTranslationVelocity
(
maxTranslationVelocityDefault
),
maxRotationVelocity
(
maxRotationVelocityDefault
),
nDof
(0),
59
eJe
(),
eJeAvailable
(false),
fJe
(),
fJeAvailable
(false),
areJointLimitsAvailable
(false),
qmin
(nullptr),
qmax
(nullptr),
60
verbose_
(true)
61
{
62
*
this
= robot;
63
}
64
68
vpRobot::~vpRobot
()
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
81
vpRobot
&
vpRobot::operator=
(
const
vpRobot
&robot)
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
162
vpColVector
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
200
vpRobot::vpRobotStateType
vpRobot::setRobotState
(
const
vpRobot::vpRobotStateType
newState)
201
{
202
stateRobot = newState;
203
return
newState;
204
}
205
206
vpRobot::vpControlFrameType
vpRobot::setRobotFrame
(
vpRobot::vpControlFrameType
newFrame)
207
{
208
frameRobot = newFrame;
209
return
newFrame;
210
}
211
215
vpColVector
vpRobot::getPosition
(
vpRobot::vpControlFrameType
frame)
216
{
217
vpColVector
r;
218
this->
getPosition
(frame, r);
219
220
return
r;
221
}
222
223
/* -------------------------------------------------------------------------
224
*/
225
/* --- VELOCITY CONTROL ----------------------------------------------------
226
*/
227
/* -------------------------------------------------------------------------
228
*/
229
238
void
vpRobot::setMaxTranslationVelocity
(
double
v_max)
239
{
240
this->
maxTranslationVelocity
= v_max;
241
return
;
242
}
243
250
double
vpRobot::getMaxTranslationVelocity
(
void
)
const
{
return
this->
maxTranslationVelocity
; }
251
259
void
vpRobot::setMaxRotationVelocity
(
double
w_max)
260
{
261
this->
maxRotationVelocity
= w_max;
262
return
;
263
}
264
272
double
vpRobot::getMaxRotationVelocity
(
void
)
const
{
return
this->
maxRotationVelocity
; }
273
END_VISP_NAMESPACE
vpArray2D::size
unsigned int size() const
Return the number of elements of the 2D array.
Definition
vpArray2D.h:435
vpColVector
Implementation of column vector and the associated operations.
Definition
vpColVector.h:191
vpException::dimensionError
@ dimensionError
Bad dimension.
Definition
vpException.h:71
vpRobotException
Error that can be emitted by the vpRobot class and its derivatives.
Definition
vpRobotException.h:54
vpRobot::nDof
int nDof
number of degrees of freedom
Definition
vpRobot.h:101
vpRobot::eJe
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
Definition
vpRobot.h:103
vpRobot::operator=
vpRobot & operator=(const vpRobot &robot)
Definition
vpRobot.cpp:81
vpRobot::~vpRobot
virtual ~vpRobot()
Definition
vpRobot.cpp:68
vpRobot::qmin
double * qmin
Definition
vpRobot.h:112
vpRobot::saturateVelocities
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition
vpRobot.cpp:162
vpRobot::vpControlFrameType
vpControlFrameType
Definition
vpRobot.h:74
vpRobot::CAMERA_FRAME
@ CAMERA_FRAME
Definition
vpRobot.h:81
vpRobot::maxRotationVelocityDefault
static const double maxRotationVelocityDefault
Definition
vpRobot.h:98
vpRobot::qmax
double * qmax
Definition
vpRobot.h:113
vpRobot::areJointLimitsAvailable
int areJointLimitsAvailable
Definition
vpRobot.h:111
vpRobot::getPosition
virtual void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)=0
Get the robot position (frame has to be specified).
vpRobot::fJeAvailable
int fJeAvailable
is the robot Jacobian expressed in the robot reference frame available
Definition
vpRobot.h:109
vpRobot::vpRobotStateType
vpRobotStateType
Definition
vpRobot.h:62
vpRobot::STATE_STOP
@ STATE_STOP
Stops robot motion especially in velocity and acceleration control.
Definition
vpRobot.h:63
vpRobot::maxTranslationVelocityDefault
static const double maxTranslationVelocityDefault
Definition
vpRobot.h:96
vpRobot::getMaxRotationVelocity
double getMaxRotationVelocity(void) const
Definition
vpRobot.cpp:272
vpRobot::fJe
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
Definition
vpRobot.h:107
vpRobot::setRobotState
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition
vpRobot.cpp:200
vpRobot::maxTranslationVelocity
double maxTranslationVelocity
Definition
vpRobot.h:95
vpRobot::eJeAvailable
int eJeAvailable
is the robot Jacobian expressed in the end-effector frame available
Definition
vpRobot.h:105
vpRobot::getMaxTranslationVelocity
double getMaxTranslationVelocity(void) const
Definition
vpRobot.cpp:250
vpRobot::vpRobot
vpRobot(void)
Definition
vpRobot.cpp:49
vpRobot::maxRotationVelocity
double maxRotationVelocity
Definition
vpRobot.h:97
vpRobot::setMaxRotationVelocity
void setMaxRotationVelocity(double maxVr)
Definition
vpRobot.cpp:259
vpRobot::setRobotFrame
vpControlFrameType setRobotFrame(vpRobot::vpControlFrameType newFrame)
Definition
vpRobot.cpp:206
vpRobot::setMaxTranslationVelocity
void setMaxTranslationVelocity(double maxVt)
Definition
vpRobot.cpp:238
vpRobot::verbose_
bool verbose_
Definition
vpRobot.h:115
BEGIN_VISP_NAMESPACE
Definition
vpMbtDistanceCircle.cpp:55
modules
robot
src
vpRobot.cpp
Generated by
1.17.0