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(),
75 iscJcIdentity(true), cJc(6,6)
94 : L(), error(), J1(), J1p(), s(), sStar(), e1(), e(), q_dot(), v(), servoType(servo_type),
95 rankJ1(0), featureList(), desiredFeatureList(), featureSelectionList(), lambda(), signInteractionMatrix(1),
96 interactionMatrixType(DESIRED), inversionType(PSEUDO_INVERSE), cVe(), init_cVe(false),
97 cVf(), init_cVf(false), fVe(), init_fVe(false), eJe(), init_eJe(false), fJe(), init_fJe(false),
98 errorComputed(false), interactionMatrixComputed(false), dim_task(0), taskWasKilled(false),
99 forceInteractionMatrixComputation(false), WpW(), I_WpW(), P(), sv(), mu(4), e1_initial(),
100 iscJcIdentity(true), cJc(6,6)
119 vpTRACE(
"--- Begin Warning Warning Warning Warning Warning ---");
120 vpTRACE(
"--- You should explicitly call vpServo.kill()... ---");
121 vpTRACE(
"--- End Warning Warning Warning Warning Warning ---");
292 for(
unsigned int i = 0 ; i < 6 ; i++) {
293 if(std::fabs(dof[i]) > std::numeric_limits<double>::epsilon()){
316 switch (displayLevel)
320 os <<
"Visual servoing task: " <<std::endl ;
322 os <<
"Type of control law " <<std::endl ;
326 os <<
"Type of task have not been chosen yet ! " << std::endl ;
329 os <<
"Eye-in-hand configuration " << std::endl ;
330 os <<
"Control in the camera frame " << std::endl ;
333 os <<
"Eye-in-hand configuration " << std::endl ;
334 os <<
"Control in the articular frame " << std::endl ;
337 os <<
"Eye-to-hand configuration " << std::endl ;
338 os <<
"s_dot = _L_cVe_eJe q_dot " << std::endl ;
341 os <<
"Eye-to-hand configuration " << std::endl ;
342 os <<
"s_dot = _L_cVe_fVe_eJe q_dot " << std::endl ;
345 os <<
"Eye-to-hand configuration " << std::endl ;
346 os <<
"s_dot = _L_cVf_fJe q_dot " << std::endl ;
350 os <<
"List of visual features : s" <<std::endl ;
351 std::list<vpBasicFeature *>::const_iterator it_s;
352 std::list<vpBasicFeature *>::const_iterator it_s_star;
353 std::list<unsigned int>::const_iterator it_select;
358 (*it_s)->print( (*it_select) ) ;
361 os <<
"List of desired visual features : s*" <<std::endl ;
365 (*it_s_star)->print( (*it_select) ) ;
368 os <<
"Interaction Matrix Ls "<<std::endl ;
371 os <<
L << std::endl;
375 os <<
"not yet computed "<<std::endl ;
378 os <<
"Error vector (s-s*) "<<std::endl ;
381 os <<
error.
t() << std::endl;
385 os <<
"not yet computed "<<std::endl ;
388 os <<
"Gain : " <<
lambda <<std::endl ;
395 os <<
"Type of control law " <<std::endl ;
399 os <<
"Type of task have not been chosen yet ! " << std::endl ;
402 os <<
"Eye-in-hand configuration " << std::endl ;
403 os <<
"Control in the camera frame " << std::endl ;
406 os <<
"Eye-in-hand configuration " << std::endl ;
407 os <<
"Control in the articular frame " << std::endl ;
410 os <<
"Eye-to-hand configuration " << std::endl ;
411 os <<
"s_dot = _L_cVe_eJe q_dot " << std::endl ;
414 os <<
"Eye-to-hand configuration " << std::endl ;
415 os <<
"s_dot = _L_cVe_fVe_eJe q_dot " << std::endl ;
418 os <<
"Eye-to-hand configuration " << std::endl ;
419 os <<
"s_dot = _L_cVf_fJe q_dot " << std::endl ;
427 os <<
"List of visual features : s" <<std::endl ;
429 std::list<vpBasicFeature *>::const_iterator it_s;
430 std::list<unsigned int>::const_iterator it_select;
435 (*it_s)->print( (*it_select) ) ;
441 os <<
"List of desired visual features : s*" <<std::endl ;
443 std::list<vpBasicFeature *>::const_iterator it_s_star;
444 std::list<unsigned int>::const_iterator it_select;
449 (*it_s_star)->print( (*it_select) ) ;
455 os <<
"Gain : " <<
lambda <<std::endl ;
460 os <<
"Interaction Matrix Ls "<<std::endl ;
462 os <<
L << std::endl;
465 os <<
"not yet computed "<<std::endl ;
474 os <<
"Error vector (s-s*) "<<std::endl ;
476 os <<
error.
t() << std::endl;
479 os <<
"not yet computed "<<std::endl ;
573 unsigned int dim = 0 ;
574 std::list<vpBasicFeature *>::const_iterator it_s;
575 std::list<unsigned int>::const_iterator it_select;
579 dim += (*it_s)->getDimension(*it_select) ;
593 static void computeInteractionMatrixFromList (
const std::list<vpBasicFeature *> & featureList,
594 const std::list<unsigned int> & featureSelectionList,
597 if (featureList.empty())
601 "feature list empty, cannot compute Ls")) ;
616 unsigned int rowL = L.
getRows();
617 const unsigned int colL = 6;
630 unsigned int cursorL = 0;
632 std::list<vpBasicFeature *>::const_iterator it;
633 std::list<unsigned int>::const_iterator it_select;
635 for (it = featureList.begin(), it_select = featureSelectionList.begin(); it != featureList.end(); ++it, ++it_select)
638 matrixTmp = (*it)->interaction( *it_select );
639 unsigned int rowMatrixTmp = matrixTmp .
getRows();
640 unsigned int colMatrixTmp = matrixTmp .
getCols();
643 while (rowMatrixTmp + cursorL > rowL) {
645 L.
resize (rowL,colL,
false);
650 for (
unsigned int k = 0; k < rowMatrixTmp; ++k, ++cursorL) {
651 for (
unsigned int j = 0; j < colMatrixTmp; ++j) {
652 L[cursorL][j] = matrixTmp[k][j];
657 L.
resize (cursorL,colL,
false);
679 computeInteractionMatrixFromList(
this ->featureList,
680 this ->featureSelectionList,
699 this ->featureSelectionList, L);
717 computeInteractionMatrixFromList(
this ->featureList,
718 this ->featureSelectionList, L);
720 this ->featureSelectionList, Lstar);
756 if (featureList.empty())
760 "feature list empty, cannot compute Ls")) ;
766 "feature list empty, cannot compute Ls")) ;
790 if (0 == dimError) { dimError = 1;
error .
resize(dimError);}
791 if (0 == dimS) { dimS = 1;
s .
resize(dimS);}
792 if (0 == dimSStar) { dimSStar = 1;
sStar .
resize(dimSStar);}
801 unsigned int cursorS = 0;
802 unsigned int cursorSStar = 0;
803 unsigned int cursorError = 0;
806 std::list<vpBasicFeature *>::const_iterator it_s;
807 std::list<vpBasicFeature *>::const_iterator it_s_star;
808 std::list<unsigned int>::const_iterator it_select;
810 for (it_s = featureList.begin(), it_s_star =
desiredFeatureList.begin(), it_select = featureSelectionList.begin();
811 it_s != featureList.end();
812 ++it_s, ++it_s_star, ++it_select)
815 desired_s = (*it_s_star);
816 unsigned int select = (*it_select);
819 vectTmp = current_s->
get_s(select);
820 unsigned int dimVectTmp = vectTmp .
getRows();
821 while (dimVectTmp + cursorS > dimS)
823 for (
unsigned int k = 0; k < dimVectTmp; ++k) {
s[cursorS++] = vectTmp[k]; }
826 vectTmp = desired_s->
get_s(select);
827 dimVectTmp = vectTmp .
getRows();
828 while (dimVectTmp + cursorSStar > dimSStar) {
832 for (
unsigned int k = 0; k < dimVectTmp; ++k) {
833 sStar[cursorSStar++] = vectTmp[k];
837 vectTmp = current_s->
error(*desired_s, select) ;
838 dimVectTmp = vectTmp .
getRows();
839 while (dimVectTmp + cursorError > dimError) {
843 for (
unsigned int k = 0; k < dimVectTmp; ++k) {
844 error[cursorError++] = vectTmp[k];
871 "No control law have been yet defined")) ;
905 "No control law have been yet defined")) ;
956 static int iteration =0;
966 vpERROR_TRACE(
"All the matrices are not correctly initialized") ;
968 "Cannot compute control law "
969 "All the matrices are not correctly"
974 vpERROR_TRACE(
"All the matrices are not correctly updated") ;
983 "No control law have been yet defined")) ;
1015 J1 = L*
cJc*cVa*aJe ;
1025 bool imageComputed = false ;
1031 imageComputed = true ;
1047 if (imageComputed!=
true)
1054 WpW = imJ1t*imJ1t.
t() ;
1057 std::cout <<
"rank J1 " <<
rankJ1 <<std::endl ;
1058 std::cout <<
"imJ1t"<<std::endl << imJ1t ;
1059 std::cout <<
"imJ1"<<std::endl << imJ1 ;
1061 std::cout <<
"WpW" <<std::endl <<
WpW ;
1062 std::cout <<
"J1" <<std::endl <<
J1 ;
1063 std::cout <<
"J1p" <<std::endl <<
J1p ;
1114 static int iteration =0;
1125 vpERROR_TRACE(
"All the matrices are not correctly initialized") ;
1127 "Cannot compute control law "
1128 "All the matrices are not correctly"
1133 vpERROR_TRACE(
"All the matrices are not correctly updated") ;
1142 "No control law have been yet defined")) ;
1181 bool imageComputed = false ;
1187 imageComputed = true ;
1203 if (imageComputed!=
true)
1210 WpW = imJ1t*imJ1t.
t() ;
1213 std::cout <<
"rank J1 " <<
rankJ1 <<std::endl ;
1214 std::cout <<
"imJ1t"<<std::endl << imJ1t ;
1215 std::cout <<
"imJ1"<<std::endl << imJ1 ;
1217 std::cout <<
"WpW" <<std::endl <<
WpW ;
1218 std::cout <<
"J1" <<std::endl <<
J1 ;
1219 std::cout <<
"J1p" <<std::endl <<
J1p ;
1225 if (iteration==0 || std::fabs(t) < std::numeric_limits<double>::epsilon()) {
1278 static int iteration =0;
1288 vpERROR_TRACE(
"All the matrices are not correctly initialized") ;
1290 "Cannot compute control law "
1291 "All the matrices are not correctly"
1296 vpERROR_TRACE(
"All the matrices are not correctly updated") ;
1305 "No control law have been yet defined")) ;
1344 bool imageComputed = false ;
1350 imageComputed = true ;
1366 if (imageComputed!=
true)
1373 WpW = imJ1t*imJ1t.
t() ;
1376 std::cout <<
"rank J1 " <<
rankJ1 <<std::endl ;
1377 std::cout <<
"imJ1t"<<std::endl << imJ1t ;
1378 std::cout <<
"imJ1"<<std::endl << imJ1 ;
1380 std::cout <<
"WpW" <<std::endl <<
WpW ;
1381 std::cout <<
"J1" <<std::endl <<
J1 ;
1382 std::cout <<
"J1p" <<std::endl <<
J1p ;
1388 if (iteration==0 || std::fabs(t) < std::numeric_limits<double>::epsilon()) {
1431 else if (e0_ <= norm_e && norm_e <= e1_ )
1432 sig = 1.0 / (1.0 + exp(-12.0 * ( (norm_e-e0_)/((e1_-e0_))) + 6.0 ) );
1444 P_norm_e = I - (1.0 / pp ) * J1t * ee_t *
J1;
1446 P = sig * P_norm_e + (1 - sig) *
I_WpW;
1517 if (!useLargeProjectionOperator)
1521 vpERROR_TRACE(
"no degree of freedom is free, cannot use secondary task") ;
1523 "no degree of freedom is free, cannot use secondary task")) ;
1617 if (!useLargeProjectionOperator)
1621 vpERROR_TRACE(
"no degree of freedom is free, cannot use secondary task") ;
1623 "no degree of freedom is free, cannot use secondary task")) ;
1686 const double &rho,
const double &rho1,
const double &lambda_tune)
const
1690 if (qmin.
size() != n || qmax.
size() != n )
1692 std::stringstream msg;
1693 msg <<
"Dimension vector qmin (" << qmin.
size() <<
") or qmax () does not correspond to the number of jacobian columns";
1694 msg <<
"qmin size: " << qmin.
size() << std::endl;
1697 if (q.
size() != n || dq.
size() != n )
1699 vpERROR_TRACE(
"Dimension vector q or dq does not correspont to the number of jacobian columns") ;
1701 "Dimension vector q or dq does not correspont to the number of jacobian columns")) ;
1704 double lambda_l = 0.0;
1717 for(
unsigned int i = 0; i < n; i++)
1719 q_l0_min[i] = qmin[i] + rho *(qmax[i] - qmin[i]);
1720 q_l0_max[i] = qmax[i] - rho *(qmax[i] - qmin[i]);
1722 q_l1_min[i] = q_l0_min[i] - rho * rho1 * (qmax[i] - qmin[i]);
1723 q_l1_max[i] = q_l0_max[i] + rho * rho1 * (qmax[i] - qmin[i]);
1725 if (q[i] < q_l0_min[i] )
1727 else if (q[i] > q_l0_max[i] )
1733 for(
unsigned int i = 0; i < n; i++)
1735 if (q[i] > q_l0_min[i] && q[i] < q_l0_max[i])
1746 if (q[i] < q_l1_min[i] || q[i] > q_l1_max[i] )
1747 q2_i = - (1 + lambda_tune) * b * Pg_i;
1751 if (q[i] >= q_l0_max[i] && q[i] <= q_l1_max[i] )
1752 lambda_l = 1 / (1 + exp(-12 *( (q[i] - q_l0_max[i]) / (q_l1_max[i] - q_l0_max[i]) ) + 6 ) );
1754 else if (q[i] >= q_l1_min[i] && q[i] <= q_l0_min[i])
1755 lambda_l = 1 / (1 + exp(-12 *( (q[i] - q_l0_min[i]) / (q_l1_min[i] - q_l0_min[i]) ) + 6 ) );
1757 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)
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 iscJcIdentity
Boolean to know if cJc is identity (for fast computation)
bool testInitialization()
vpColVector computeError()
int signInteractionMatrix
vpColVector computeControlLaw()
vpMatrix J1
Task Jacobian .
void setCameraDoF(const vpColVector &dof)
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)
vpMatrix cJc
A diag matrix used to determine which are the degrees of freedom that are controlled in the camera fr...
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)