Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpServo.h
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 * Visual servoing control law.
32 */
33
38
39#ifndef VP_SERVO_H
40#define VP_SERVO_H
41
42#include <list>
43
44#include <visp3/core/vpConfig.h>
45#include <visp3/core/vpMatrix.h>
46#include <visp3/core/vpVelocityTwistMatrix.h>
47#include <visp3/visual_features/vpBasicFeature.h>
48#include <visp3/vs/vpAdaptiveGain.h>
49#include <visp3/vs/vpServoException.h>
50
158class VISP_EXPORT vpServo
159{
160
161public:
206
210 typedef enum
211 {
235 } vpServoIteractionMatrixType;
236
240 typedef enum
241 {
251 } vpServoInversionType;
252
267
268 // private:
269 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
270 // vpServo(const vpServo &)
271 // : L(), error(), J1(), J1p(), s(), sStar(), e1(), e(), q_dot(), v(),
272 // servoType(vpServo::NONE),
273 // rankJ1(0), featureList(), desiredFeatureList(),
274 // featureSelectionList(), lambda(), signInteractionMatrix(1),
275 // interactionMatrixType(DESIRED), inversionType(PSEUDO_INVERSE),
276 // cVe(), init_cVe(false), cVf(), init_cVf(false), fVe(),
277 // init_fVe(false), eJe(), init_eJe(false), fJe(), init_fJe(false),
278 // errorComputed(false), interactionMatrixComputed(false), dim_task(0),
279 // taskWasKilled(false), forceInteractionMatrixComputation(false),
280 // WpW(), I_WpW(), P(), sv(), mu(4.), e1_initial()
281 // {
282 // throw vpException(vpException::functionNotImplementedError, "Not
283 // implemented!");
284 // }
285 // vpServo &operator=(const vpServo &){
286 // throw vpException(vpException::functionNotImplementedError, "Not
287 // implemented!"); return *this;
288 // }
289 //#endif
290
291#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
292 vpServo(const vpServo &) = delete; // non construction-copyable
293 vpServo &operator=(const vpServo &) = delete; // non copyable
294#endif
295
296public:
312 vpServo();
313
328 VP_EXPLICIT vpServo(vpServoType servo_type);
329
337 virtual ~vpServo();
338
366 void addFeature(vpBasicFeature &s_cur, vpBasicFeature &s_star, unsigned int select = vpBasicFeature::FEATURE_ALL);
367
395 void addFeature(vpBasicFeature &s_cur, unsigned int select = vpBasicFeature::FEATURE_ALL);
396
423
459
495 vpColVector computeControlLaw(double t, const vpColVector &e_dot_init);
496
504
513
517 unsigned int getDimension() const;
518
530 inline vpColVector getError() const { return error; }
531
545 inline vpMatrix getInteractionMatrix() const { return L; }
546
559 vpMatrix getI_WpW() const { return I_WpW; }
560
564 inline vpServoType getServoType() const { return servoType; }
565
578 vpMatrix getLargeP() const { return P; }
579
594 vpMatrix getTaskJacobian() const { return J1; }
595
615
626 unsigned int getTaskRank() const { return rankJ1; }
627
633 inline vpColVector getTaskSingularValues() const { return sv; }
634
650 vpMatrix getWpW() const { return WpW; }
651
663
670
674 vpMatrix get_eJe() const { return eJe; }
675
680 vpMatrix get_fJe() const { return fJe; }
681
690
706 void kill();
707
716 void print(const vpServo::vpServoPrintType display_level = ALL, std::ostream &os = std::cout);
717
789 vpColVector secondaryTask(const vpColVector &de2dt, const bool &useLargeProjectionOperator = false);
790
865 vpColVector secondaryTask(const vpColVector &e2, const vpColVector &de2dt,
866 const bool &useLargeProjectionOperator = false);
867
911 vpColVector secondaryTaskJointLimitAvoidance(const vpColVector &q, const vpColVector &dq, const vpColVector &qmin,
912 const vpColVector &qmax, const double &rho = 0.1,
913 const double &rho1 = 0.3, const double &lambda_tune = 0.7);
914
962 void setCameraDoF(const vpColVector &dof);
963
979 void setForceInteractionMatrixComputation(bool force_computation)
980 {
981 this->forceInteractionMatrixComputation = force_computation;
982 }
983
993 void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType,
994 const vpServoInversionType &interactionMatrixInversion = PSEUDO_INVERSE);
995
1006 void setLambda(double c) { lambda.initFromConstant(c); }
1007
1022 void setLambda(double gain_at_zero, double gain_at_infinity, double slope_at_zero)
1023 {
1024 lambda.initStandard(gain_at_zero, gain_at_infinity, slope_at_zero);
1025 }
1026
1037 void setLambda(const vpAdaptiveGain &l) { lambda = l; }
1038
1045 void setMu(double mu_) { this->mu = mu_; }
1046
1052 void setServo(const vpServoType &servo_type);
1053
1059 {
1060 this->cVe = cVe_;
1061 init_cVe = true;
1062 }
1063
1069 {
1070 cVe.buildFrom(cMe);
1071 init_cVe = true;
1072 }
1073
1080 {
1081 this->cVf = cVf_;
1082 init_cVf = true;
1083 }
1084
1091 {
1092 cVf.buildFrom(cMf);
1093 init_cVf = true;
1094 }
1095
1102 {
1103 this->fVe = fVe_;
1104 init_fVe = true;
1105 }
1106
1113 {
1114 fVe.buildFrom(fMe);
1115 init_fVe = true;
1116 }
1117
1121 void set_eJe(const vpMatrix &eJe_)
1122 {
1123 this->eJe = eJe_;
1124 init_eJe = true;
1125 }
1126
1131 void set_fJe(const vpMatrix &fJe_)
1132 {
1133 this->fJe = fJe_;
1134 init_fJe = true;
1135 }
1136
1144 void setPseudoInverseThreshold(double pseudo_inverse_threshold)
1145 {
1146 m_pseudo_inverse_threshold = pseudo_inverse_threshold;
1147 }
1148
1153 bool testInitialization();
1154
1158 bool testUpdated();
1159
1160protected:
1174 void init();
1175
1179 void computeProjectionOperators(const vpMatrix &J1_, const vpMatrix &I_, const vpMatrix &I_WpW_,
1180 const vpColVector &error_, vpMatrix &P_) const;
1181
1182public:
1194
1203
1208
1213
1216
1218 unsigned int rankJ1;
1219
1221 std::list<vpBasicFeature *> featureList;
1223 std::list<vpBasicFeature *> desiredFeatureList;
1226 std::list<unsigned int> featureSelectionList;
1227
1230
1239
1240protected:
1241 /*
1242 Twist transformation matrix
1243 */
1244
1250
1276
1277 /*
1278 * Jacobians
1279 */
1280
1288
1296
1297 /*
1298 * Task building
1299 */
1300
1306 unsigned int dim_task;
1311
1335
1338
1344 double mu;
1345
1352
1355
1361
1363
1365};
1366END_VISP_NAMESPACE
1367#endif
Adaptive gain computation.
class that defines what is a visual feature
Implementation of column vector and the associated operations.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
vpColVector q_dot
Articular velocity.
Definition vpServo.h:1210
unsigned int rankJ1
Rank of the task Jacobian.
Definition vpServo.h:1218
vpMatrix eJe
Jacobian expressed in the end-effector frame (e).
Definition vpServo.h:1282
int signInteractionMatrix
Definition vpServo.h:1233
vpMatrix WpW
Projection operators .
Definition vpServo.h:1315
void setPseudoInverseThreshold(double pseudo_inverse_threshold)
Definition vpServo.h:1144
vpVelocityTwistMatrix cVf
Twist transformation matrix between camera frame (c) and robot base frame (f).
Definition vpServo.h:1258
vpMatrix J1
Task Jacobian .
Definition vpServo.h:1191
vpServoType getServoType() const
Definition vpServo.h:564
vpMatrix getInteractionMatrix() const
Definition vpServo.h:545
void setMu(double mu_)
Definition vpServo.h:1045
bool init_cVe
Definition vpServo.h:1256
bool errorComputed
true if the error has been computed.
Definition vpServo.h:1302
vpMatrix fJe
Jacobian expressed in the robot base frame (f).
Definition vpServo.h:1290
vpServoType
Definition vpServo.h:166
@ EYETOHAND_L_cVe_eJe
Definition vpServo.h:190
@ EYEINHAND_CAMERA
Definition vpServo.h:176
@ EYETOHAND_L_cVf_fJe
Definition vpServo.h:204
@ EYEINHAND_L_cVe_eJe
Definition vpServo.h:183
@ EYETOHAND_L_cVf_fVe_eJe
Definition vpServo.h:197
unsigned int getDimension() const
Definition vpServo.cpp:366
void set_cVf(const vpVelocityTwistMatrix &cVf_)
Definition vpServo.h:1079
void set_cVf(const vpHomogeneousMatrix &cMf)
Definition vpServo.h:1090
vpServo & operator=(const vpServo &)=delete
bool init_cVf
Definition vpServo.h:1264
double mu
Definition vpServo.h:1344
vpVelocityTwistMatrix get_cVe() const
Definition vpServo.h:656
vpMatrix get_fJe() const
Definition vpServo.h:680
vpVelocityTwistMatrix cVe
Definition vpServo.h:1249
bool init_fJe
Definition vpServo.h:1295
void addFeature(vpBasicFeature &s_cur, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
Definition vpServo.cpp:331
vpMatrix getI_WpW() const
Definition vpServo.h:559
vpMatrix P
Definition vpServo.h:1334
void set_cVe(const vpVelocityTwistMatrix &cVe_)
Definition vpServo.h:1058
vpColVector e1
Primary task .
Definition vpServo.h:1205
unsigned int getTaskRank() const
Definition vpServo.h:626
vpColVector e1_initial
Definition vpServo.h:1351
vpVelocityTwistMatrix get_fVe() const
Definition vpServo.h:669
bool forceInteractionMatrixComputation
Force the interaction matrix computation even if it is already done.
Definition vpServo.h:1310
void set_fVe(const vpHomogeneousMatrix &fMe)
Definition vpServo.h:1112
void setLambda(double c)
Definition vpServo.h:1006
void setForceInteractionMatrixComputation(bool force_computation)
Definition vpServo.h:979
vpMatrix cJc
Definition vpServo.h:1360
vpVelocityTwistMatrix fVe
Definition vpServo.h:1269
void set_eJe(const vpMatrix &eJe_)
Definition vpServo.h:1121
bool taskWasKilled
Flag to indicate if the task was killed.
Definition vpServo.h:1308
std::list< vpBasicFeature * > featureList
List of current visual features .
Definition vpServo.h:1221
vpColVector error
Definition vpServo.h:1189
bool iscJcIdentity
Boolean to know if cJc is identity (for fast computation).
Definition vpServo.h:1354
vpMatrix I_WpW
Projection operators .
Definition vpServo.h:1317
void set_fVe(const vpVelocityTwistMatrix &fVe_)
Definition vpServo.h:1101
double getPseudoInverseThreshold() const
Definition vpServo.h:689
vpColVector v
Camera velocity.
Definition vpServo.h:1212
vpColVector sStar
Definition vpServo.h:1202
vpMatrix computeInteractionMatrix()
Definition vpServo.cpp:452
vpMatrix J1p
Pseudo inverse of the task Jacobian.
Definition vpServo.h:1193
vpMatrix getTaskJacobian() const
Definition vpServo.h:594
vpMatrix get_eJe() const
Definition vpServo.h:674
vpColVector s
Definition vpServo.h:1198
void setLambda(const vpAdaptiveGain &l)
Definition vpServo.h:1037
vpMatrix I
Identity matrix.
Definition vpServo.h:1313
void set_fJe(const vpMatrix &fJe_)
Definition vpServo.h:1131
std::list< vpBasicFeature * > desiredFeatureList
List of desired visual features .
Definition vpServo.h:1223
vpColVector getTaskSingularValues() const
Definition vpServo.h:633
bool m_first_iteration
True until first call of computeControlLaw() is achieved.
Definition vpServo.h:1362
vpMatrix L
Interaction matrix.
Definition vpServo.h:1184
vpServoType servoType
Chosen visual servoing control law.
Definition vpServo.h:1215
vpServoIteractionMatrixType interactionMatrixType
Type of the interaction matrix (current, mean, desired, user).
Definition vpServo.h:1235
double m_pseudo_inverse_threshold
Threshold used in the pseudo inverse.
Definition vpServo.h:1364
vpColVector getError() const
Definition vpServo.h:530
void setLambda(double gain_at_zero, double gain_at_infinity, double slope_at_zero)
Definition vpServo.h:1022
vpVelocityTwistMatrix get_cVf() const
Definition vpServo.h:662
vpServoInversionType
Definition vpServo.h:241
@ PSEUDO_INVERSE
Definition vpServo.h:250
@ TRANSPOSE
Definition vpServo.h:246
std::list< unsigned int > featureSelectionList
Definition vpServo.h:1226
vpColVector computeControlLaw()
Definition vpServo.cpp:699
vpColVector e
Task .
Definition vpServo.h:1207
bool init_eJe
Definition vpServo.h:1287
vpServoPrintType
Definition vpServo.h:257
@ ALL
Print all the task information.
Definition vpServo.h:258
@ CONTROLLER
Print the type of controller law.
Definition vpServo.h:259
@ ERROR_VECTOR
Print the error vector .
Definition vpServo.h:260
@ GAIN
Print the gain .
Definition vpServo.h:263
@ FEATURE_CURRENT
Print the current features .
Definition vpServo.h:261
@ FEATURE_DESIRED
Print the desired features .
Definition vpServo.h:262
@ MINIMUM
Same as vpServo::vpServoPrintType::ERROR_VECTOR.
Definition vpServo.h:265
@ INTERACTION_MATRIX
Print the interaction matrix.
Definition vpServo.h:264
vpServo(const vpServo &)=delete
vpColVector sv
Singular values from the pseudo inverse.
Definition vpServo.h:1337
vpMatrix getTaskJacobianPseudoInverse() const
Definition vpServo.h:614
vpServoIteractionMatrixType
Definition vpServo.h:211
@ DESIRED
Definition vpServo.h:223
@ USER_DEFINED
Definition vpServo.h:234
@ CURRENT
Definition vpServo.h:217
vpMatrix getLargeP() const
Definition vpServo.h:578
bool interactionMatrixComputed
true if the interaction matrix has been computed.
Definition vpServo.h:1304
void set_cVe(const vpHomogeneousMatrix &cMe)
Definition vpServo.h:1068
bool init_fVe
Definition vpServo.h:1275
vpColVector computeError()
Definition vpServo.cpp:509
unsigned int dim_task
Dimension of the task updated during computeControlLaw().
Definition vpServo.h:1306
vpServoInversionType inversionType
Definition vpServo.h:1238
vpMatrix getWpW() const
Definition vpServo.h:650
vpAdaptiveGain lambda
Gain used in the control law.
Definition vpServo.h:1229