41 #include <visp3/vs/vpServo.h>
46 #include <visp3/core/vpException.h>
49 #include <visp3/core/vpDebug.h>
69 : L(), error(), J1(), J1p(), s(), sStar(), e1(), e(), q_dot(), v(), servoType(
vpServo::NONE),
70 rankJ1(0), featureList(), desiredFeatureList(), featureSelectionList(), lambda(), signInteractionMatrix(1),
71 interactionMatrixType(DESIRED), inversionType(PSEUDO_INVERSE), cVe(), init_cVe(false),
72 cVf(), init_cVf(false), fVe(), init_fVe(false), eJe(), init_eJe(false), fJe(), init_fJe(false),
73 errorComputed(false), interactionMatrixComputed(false), dim_task(0), taskWasKilled(false),
74 forceInteractionMatrixComputation(false), WpW(), I_WpW(), P(), sv(), mu(4.), e1_initial()
91 : L(), error(), J1(), J1p(), s(), sStar(), e1(), e(), q_dot(), v(), servoType(servo_type),
92 rankJ1(0), featureList(), desiredFeatureList(), featureSelectionList(), lambda(), signInteractionMatrix(1),
93 interactionMatrixType(DESIRED), inversionType(PSEUDO_INVERSE), cVe(), init_cVe(false),
94 cVf(), init_cVf(false), fVe(), init_fVe(false), eJe(), init_eJe(false), fJe(), init_fJe(false),
95 errorComputed(false), interactionMatrixComputed(false), dim_task(0), taskWasKilled(false),
96 forceInteractionMatrixComputation(false), WpW(), I_WpW(), P(), sv(), mu(4), e1_initial()
114 vpTRACE(
"--- Begin Warning Warning Warning Warning Warning ---");
115 vpTRACE(
"--- You should explicitly call vpServo.kill()... ---");
116 vpTRACE(
"--- End Warning Warning Warning Warning Warning ---");
250 switch (displayLevel)
254 os <<
"Visual servoing task: " <<std::endl ;
256 os <<
"Type of control law " <<std::endl ;
260 os <<
"Type of task have not been chosen yet ! " << std::endl ;
263 os <<
"Eye-in-hand configuration " << std::endl ;
264 os <<
"Control in the camera frame " << std::endl ;
267 os <<
"Eye-in-hand configuration " << std::endl ;
268 os <<
"Control in the articular frame " << std::endl ;
271 os <<
"Eye-to-hand configuration " << std::endl ;
272 os <<
"s_dot = _L_cVe_eJe q_dot " << std::endl ;
275 os <<
"Eye-to-hand configuration " << std::endl ;
276 os <<
"s_dot = _L_cVe_fVe_eJe q_dot " << std::endl ;
279 os <<
"Eye-to-hand configuration " << std::endl ;
280 os <<
"s_dot = _L_cVf_fJe q_dot " << std::endl ;
284 os <<
"List of visual features : s" <<std::endl ;
285 std::list<vpBasicFeature *>::const_iterator it_s;
286 std::list<vpBasicFeature *>::const_iterator it_s_star;
287 std::list<unsigned int>::const_iterator it_select;
292 (*it_s)->print( (*it_select) ) ;
295 os <<
"List of desired visual features : s*" <<std::endl ;
299 (*it_s_star)->print( (*it_select) ) ;
302 os <<
"Interaction Matrix Ls "<<std::endl ;
305 os <<
L << std::endl;
309 os <<
"not yet computed "<<std::endl ;
312 os <<
"Error vector (s-s*) "<<std::endl ;
315 os <<
error.
t() << std::endl;
319 os <<
"not yet computed "<<std::endl ;
322 os <<
"Gain : " <<
lambda <<std::endl ;
329 os <<
"Type of control law " <<std::endl ;
333 os <<
"Type of task have not been chosen yet ! " << std::endl ;
336 os <<
"Eye-in-hand configuration " << std::endl ;
337 os <<
"Control in the camera frame " << std::endl ;
340 os <<
"Eye-in-hand configuration " << std::endl ;
341 os <<
"Control in the articular frame " << std::endl ;
344 os <<
"Eye-to-hand configuration " << std::endl ;
345 os <<
"s_dot = _L_cVe_eJe q_dot " << std::endl ;
348 os <<
"Eye-to-hand configuration " << std::endl ;
349 os <<
"s_dot = _L_cVe_fVe_eJe q_dot " << std::endl ;
352 os <<
"Eye-to-hand configuration " << std::endl ;
353 os <<
"s_dot = _L_cVf_fJe q_dot " << std::endl ;
361 os <<
"List of visual features : s" <<std::endl ;
363 std::list<vpBasicFeature *>::const_iterator it_s;
364 std::list<unsigned int>::const_iterator it_select;
369 (*it_s)->print( (*it_select) ) ;
375 os <<
"List of desired visual features : s*" <<std::endl ;
377 std::list<vpBasicFeature *>::const_iterator it_s_star;
378 std::list<unsigned int>::const_iterator it_select;
383 (*it_s_star)->print( (*it_select) ) ;
389 os <<
"Gain : " <<
lambda <<std::endl ;
394 os <<
"Interaction Matrix Ls "<<std::endl ;
396 os <<
L << std::endl;
399 os <<
"not yet computed "<<std::endl ;
408 os <<
"Error vector (s-s*) "<<std::endl ;
410 os <<
error.
t() << std::endl;
413 os <<
"not yet computed "<<std::endl ;
507 unsigned int dim = 0 ;
508 std::list<vpBasicFeature *>::const_iterator it_s;
509 std::list<unsigned int>::const_iterator it_select;
513 dim += (*it_s)->getDimension(*it_select) ;
527 static void computeInteractionMatrixFromList (
const std::list<vpBasicFeature *> & featureList,
528 const std::list<unsigned int> & featureSelectionList,
531 if (featureList.empty())
535 "feature list empty, cannot compute Ls")) ;
550 unsigned int rowL = L.
getRows();
551 const unsigned int colL = 6;
560 unsigned int rowMatrixTmp, colMatrixTmp;
565 unsigned int cursorL = 0;
567 std::list<vpBasicFeature *>::const_iterator it;
568 std::list<unsigned int>::const_iterator it_select;
570 for (it = featureList.begin(), it_select = featureSelectionList.begin(); it != featureList.end(); ++it, ++it_select)
573 matrixTmp = (*it)->interaction( *it_select );
574 rowMatrixTmp = matrixTmp .
getRows();
575 colMatrixTmp = matrixTmp .
getCols();
578 while (rowMatrixTmp + cursorL > rowL) {
580 L.
resize (rowL,colL,
false);
585 for (
unsigned int k = 0; k < rowMatrixTmp; ++k, ++cursorL) {
586 for (
unsigned int j = 0; j < colMatrixTmp; ++j) {
587 L[cursorL][j] = matrixTmp[k][j];
592 L.
resize (cursorL,colL,
false);
614 computeInteractionMatrixFromList(
this ->featureList,
615 this ->featureSelectionList,
635 this ->featureSelectionList, L);
654 computeInteractionMatrixFromList(
this ->featureList,
655 this ->featureSelectionList, L);
657 this ->featureSelectionList, Lstar);
695 if (featureList.empty())
699 "feature list empty, cannot compute Ls")) ;
705 "feature list empty, cannot compute Ls")) ;
729 if (0 == dimError) { dimError = 1;
error .
resize(dimError);}
730 if (0 == dimS) { dimS = 1;
s .
resize(dimS);}
731 if (0 == dimSStar) { dimSStar = 1;
sStar .
resize(dimSStar);}
736 unsigned int dimVectTmp;
741 unsigned int cursorS = 0;
742 unsigned int cursorSStar = 0;
743 unsigned int cursorError = 0;
746 std::list<vpBasicFeature *>::const_iterator it_s;
747 std::list<vpBasicFeature *>::const_iterator it_s_star;
748 std::list<unsigned int>::const_iterator it_select;
750 for (it_s = featureList.begin(), it_s_star =
desiredFeatureList.begin(), it_select = featureSelectionList.begin();
751 it_s != featureList.end();
752 ++it_s, ++it_s_star, ++it_select)
755 desired_s = (*it_s_star);
756 unsigned int select = (*it_select);
759 vectTmp = current_s->
get_s(select);
760 dimVectTmp = vectTmp .
getRows();
761 while (dimVectTmp + cursorS > dimS)
763 for (
unsigned int k = 0; k < dimVectTmp; ++k) {
s[cursorS++] = vectTmp[k]; }
766 vectTmp = desired_s->
get_s(select);
767 dimVectTmp = vectTmp .
getRows();
768 while (dimVectTmp + cursorSStar > dimSStar) {
772 for (
unsigned int k = 0; k < dimVectTmp; ++k) {
773 sStar[cursorSStar++] = vectTmp[k];
777 vectTmp = current_s->
error(*desired_s, select) ;
778 dimVectTmp = vectTmp .
getRows();
779 while (dimVectTmp + cursorError > dimError) {
783 for (
unsigned int k = 0; k < dimVectTmp; ++k) {
784 error[cursorError++] = vectTmp[k];
816 "No control law have been yet defined")) ;
850 "No control law have been yet defined")) ;
901 static int iteration =0;
911 vpERROR_TRACE(
"All the matrices are not correctly initialized") ;
913 "Cannot compute control law "
914 "All the matrices are not correctly"
919 vpERROR_TRACE(
"All the matrices are not correctly updated") ;
928 "No control law have been yet defined")) ;
967 bool imageComputed = false ;
973 imageComputed = true ;
989 if (imageComputed!=
true)
995 imageComputed = true ;
997 WpW = imJ1t*imJ1t.
t() ;
1000 std::cout <<
"rank J1 " <<
rankJ1 <<std::endl ;
1001 std::cout <<
"imJ1t"<<std::endl << imJ1t ;
1002 std::cout <<
"imJ1"<<std::endl << imJ1 ;
1004 std::cout <<
"WpW" <<std::endl <<
WpW ;
1005 std::cout <<
"J1" <<std::endl <<
J1 ;
1006 std::cout <<
"J1p" <<std::endl <<
J1p ;
1057 static int iteration =0;
1068 vpERROR_TRACE(
"All the matrices are not correctly initialized") ;
1070 "Cannot compute control law "
1071 "All the matrices are not correctly"
1076 vpERROR_TRACE(
"All the matrices are not correctly updated") ;
1085 "No control law have been yet defined")) ;
1124 bool imageComputed = false ;
1130 imageComputed = true ;
1146 if (imageComputed!=
true)
1152 imageComputed = true ;
1154 WpW = imJ1t*imJ1t.
t() ;
1157 std::cout <<
"rank J1 " <<
rankJ1 <<std::endl ;
1158 std::cout <<
"imJ1t"<<std::endl << imJ1t ;
1159 std::cout <<
"imJ1"<<std::endl << imJ1 ;
1161 std::cout <<
"WpW" <<std::endl <<
WpW ;
1162 std::cout <<
"J1" <<std::endl <<
J1 ;
1163 std::cout <<
"J1p" <<std::endl <<
J1p ;
1169 if (iteration==0 || std::fabs(t) < std::numeric_limits<double>::epsilon()) {
1222 static int iteration =0;
1232 vpERROR_TRACE(
"All the matrices are not correctly initialized") ;
1234 "Cannot compute control law "
1235 "All the matrices are not correctly"
1240 vpERROR_TRACE(
"All the matrices are not correctly updated") ;
1249 "No control law have been yet defined")) ;
1288 bool imageComputed = false ;
1294 imageComputed = true ;
1310 if (imageComputed!=
true)
1316 imageComputed = true ;
1318 WpW = imJ1t*imJ1t.
t() ;
1321 std::cout <<
"rank J1 " <<
rankJ1 <<std::endl ;
1322 std::cout <<
"imJ1t"<<std::endl << imJ1t ;
1323 std::cout <<
"imJ1"<<std::endl << imJ1 ;
1325 std::cout <<
"WpW" <<std::endl <<
WpW ;
1326 std::cout <<
"J1" <<std::endl <<
J1 ;
1327 std::cout <<
"J1p" <<std::endl <<
J1p ;
1333 if (iteration==0 || std::fabs(t) < std::numeric_limits<double>::epsilon()) {
1376 else if (e0_ <= norm_e && norm_e <= e1_ )
1377 sig = 1.0 / (1.0 + exp(-12.0 * ( (norm_e-e0_)/((e1_-e0_))) + 6.0 ) );
1389 P_norm_e = I - (1.0 / pp ) * J1t * ee_t *
J1;
1391 P = sig * P_norm_e + (1 - sig) *
I_WpW;
1462 if (!useLargeProjectionOperator)
1466 vpERROR_TRACE(
"no degree of freedom is free, cannot use secondary task") ;
1468 "no degree of freedom is free, cannot use secondary task")) ;
1562 if (!useLargeProjectionOperator)
1566 vpERROR_TRACE(
"no degree of freedom is free, cannot use secondary task") ;
1568 "no degree of freedom is free, cannot use secondary task")) ;
1631 const double &rho,
const double &rho1,
const double &lambda_tune)
const
1635 if (qmin.
size() != n || qmax.
size() != n )
1637 std::stringstream msg;
1638 msg <<
"Dimension vector qmin (" << qmin.
size() <<
") or qmax () does not correspond to the number of jacobian columns";
1639 msg <<
"qmin size: " << qmin.
size() << std::endl;
1642 if (q.
size() != n || dq.
size() != n )
1644 vpERROR_TRACE(
"Dimension vector q or dq does not correspont to the number of jacobian columns") ;
1646 "Dimension vector q or dq does not correspont to the number of jacobian columns")) ;
1649 double lambda_l = 0.0;
1662 for(
unsigned int i = 0; i < n; i++)
1664 q_l0_min[i] = qmin[i] + rho *(qmax[i] - qmin[i]);
1665 q_l0_max[i] = qmax[i] - rho *(qmax[i] - qmin[i]);
1667 q_l1_min[i] = q_l0_min[i] - rho * rho1 * (qmax[i] - qmin[i]);
1668 q_l1_max[i] = q_l0_max[i] + rho * rho1 * (qmax[i] - qmin[i]);
1670 if (q[i] < q_l0_min[i] )
1672 else if (q[i] > q_l0_max[i] )
1678 for(
unsigned int i = 0; i < n; i++)
1680 if (q[i] > q_l0_min[i] && q[i] < q_l0_max[i])
1691 if (q[i] < q_l1_min[i] || q[i] > q_l1_max[i] )
1692 q2_i = - (1 + lambda_tune) * b * Pg_i;
1696 if (q[i] >= q_l0_max[i] && q[i] <= q_l1_max[i] )
1697 lambda_l = 1 / (1 + exp(-12 *( (q[i] - q_l0_max[i]) / (q_l1_max[i] - q_l0_max[i]) ) + 6 ) );
1699 else if (q[i] >= q_l1_min[i] && q[i] <= q_l0_min[i])
1700 lambda_l = 1 / (1 + exp(-12 *( (q[i] - q_l0_min[i]) / (q_l1_min[i] - q_l0_min[i]) ) + 6 ) );
1702 q2_i = - lambda_l * (1 + lambda_tune)* b * Pg_i;
Implementation of a matrix and operations on matrices.
unsigned int getDimension() const
Return the task dimension.
vpServoType servoType
Chosen visual servoing control law.
void setDeallocate(vpBasicFeatureDeallocatorType d)
bool interactionMatrixComputed
true if the interaction matrix has been computed.
bool taskWasKilled
Flag to indicate if the task was killed.
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
vpMatrix getTaskJacobian() const
unsigned int rankJ1
Rank of the task Jacobian.
vpVelocityTwistMatrix cVf
Twist transformation matrix between Rf and Rc.
double euclideanNorm() const
vpVelocityTwistMatrix fVe
Twist transformation matrix between Re and Rf.
vpColVector sv
Singular values from the pseudo inverse.
vpColVector e1
Primary task .
void set_eJe(const vpMatrix &eJe_)
Error that can be emited by the vpServo class and its derivates.
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
error that can be emited by ViSP classes.
vpMatrix fJe
Jacobian expressed in the robot reference frame.
unsigned int size() const
Return the number of elements of the 2D array.
virtual vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
Compute the error between two visual features from a subset of the possible features.
unsigned int getCols() const
Return the number of columns of the 2D array.
vpMatrix getI_WpW() const
unsigned int dim_task
Dimension of the task updated during computeControlLaw().
vpServoInversionType inversionType
static Type abs(const Type &x)
vpColVector secondaryTask(const vpColVector &de2dt, const bool &useLargeProjectionOperator=false)
class that defines what is a visual feature
vpMatrix computeInteractionMatrix()
std::list< unsigned int > featureSelectionList
vp_deprecated void setIdentity(const double &val=1.0)
bool testInitialization()
vpColVector computeError()
int signInteractionMatrix
vpColVector computeControlLaw()
vpMatrix J1
Task Jacobian .
vpMatrix L
Interaction matrix.
vpColVector getCol(const unsigned int j) const
bool forceInteractionMatrixComputation
Force the interaction matrix computation even if it is already done.
vpMatrix transpose() const
vpAdaptiveGain lambda
Gain used in the control law.
vpVelocityTwistMatrix cVe
Twist transformation matrix between Re and Rc.
Implementation of a velocity twist matrix and operations on such kind of matrices.
unsigned int getRows() const
Return the number of rows of the 2D array.
vpServoIteractionMatrixType
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
vpColVector secondaryTaskJointLimitAvoidance(const vpColVector &q, const vpColVector &dq, const vpColVector &jointMin, const vpColVector &jointMax, const double &rho=0.1, const double &rho1=0.3, const double &lambda_tune=0.7) const
vpMatrix getTaskJacobianPseudoInverse() const
void computeProjectionOperators()
std::list< vpBasicFeature * > desiredFeatureList
List of desired visual features .
Implementation of column vector and the associated operations.
void set_cVe(const vpVelocityTwistMatrix &cVe_)
vpMatrix getLargeP() const
No degree of freedom is available to achieve the secondary task.
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
vpMatrix I_WpW
Projection operators .
vpMatrix pseudoInverse(double svThreshold=1e-6) const
Compute the pseudo inverse of the matrix using the SVD.
virtual vpBasicFeature * duplicate() const =0
bool errorComputed
true if the error has been computed.
vpMatrix WpW
Projection operators .
vpMatrix J1p
Pseudo inverse of the task Jacobian.
vpColVector get_s(unsigned int select=FEATURE_ALL) const
Get the feature vector .
std::list< vpBasicFeature * > featureList
List of current visual features .
void setServo(const vpServoType &servo_type)
void init()
Basic initialization.
unsigned int getTaskRank() const
vpServoIteractionMatrixType interactionMatrixType
Type of the interaction matrox (current, mean, desired, user)
vpMatrix eJe
Jacobian expressed in the end-effector frame.
Current or desired feature list is empty.
void resize(const unsigned int i, const bool flagNullify=true)