45 #include <visp/vpServo.h>
48 #include <visp/vpException.h>
49 #include <visp/vpMatrixException.h>
52 #include <visp/vpDebug.h>
72 : L(), error(), J1(), J1p(), s(), sStar(), e1(), e(), q_dot(), v(), servoType(
vpServo::NONE),
73 rankJ1(0), featureList(), desiredFeatureList(), featureSelectionList(), lambda(), signInteractionMatrix(1),
74 interactionMatrixType(DESIRED), inversionType(PSEUDO_INVERSE), cVe(), init_cVe(false),
75 cVf(), init_cVf(false), fVe(), init_fVe(false), eJe(), init_eJe(false), fJe(), init_fJe(false),
76 errorComputed(false), interactionMatrixComputed(false), dim_task(0), taskWasKilled(false),
77 forceInteractionMatrixComputation(false), WpW(), I_WpW(), sv(), mu(4.)
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(), sv(), mu(4)
117 vpTRACE(
"--- Begin Warning Warning Warning Warning Warning ---");
118 vpTRACE(
"--- You should explicitly call vpServo.kill()... ---");
119 vpTRACE(
"--- End Warning Warning Warning Warning Warning ---");
253 switch (displayLevel)
257 os <<
"Visual servoing task: " <<std::endl ;
259 os <<
"Type of control law " <<std::endl ;
263 os <<
"Type of task have not been chosen yet ! " << std::endl ;
266 os <<
"Eye-in-hand configuration " << std::endl ;
267 os <<
"Control in the camera frame " << std::endl ;
270 os <<
"Eye-in-hand configuration " << std::endl ;
271 os <<
"Control in the articular frame " << std::endl ;
274 os <<
"Eye-to-hand configuration " << std::endl ;
275 os <<
"s_dot = _L_cVe_eJe q_dot " << std::endl ;
278 os <<
"Eye-to-hand configuration " << std::endl ;
279 os <<
"s_dot = _L_cVe_fVe_eJe q_dot " << std::endl ;
282 os <<
"Eye-to-hand configuration " << std::endl ;
283 os <<
"s_dot = _L_cVf_fJe q_dot " << std::endl ;
287 os <<
"List of visual features : s" <<std::endl ;
288 std::list<vpBasicFeature *>::const_iterator it_s;
289 std::list<vpBasicFeature *>::const_iterator it_s_star;
290 std::list<unsigned int>::const_iterator it_select;
295 (*it_s)->print( (*it_select) ) ;
298 os <<
"List of desired visual features : s*" <<std::endl ;
302 (*it_s_star)->print( (*it_select) ) ;
305 os <<
"Interaction Matrix Ls "<<std::endl ;
308 os <<
L << std::endl;
312 os <<
"not yet computed "<<std::endl ;
315 os <<
"Error vector (s-s*) "<<std::endl ;
318 os <<
error.
t() << std::endl;
322 os <<
"not yet computed "<<std::endl ;
325 os <<
"Gain : " <<
lambda <<std::endl ;
332 os <<
"Type of control law " <<std::endl ;
336 os <<
"Type of task have not been chosen yet ! " << std::endl ;
339 os <<
"Eye-in-hand configuration " << std::endl ;
340 os <<
"Control in the camera frame " << std::endl ;
343 os <<
"Eye-in-hand configuration " << std::endl ;
344 os <<
"Control in the articular frame " << std::endl ;
347 os <<
"Eye-to-hand configuration " << std::endl ;
348 os <<
"s_dot = _L_cVe_eJe q_dot " << std::endl ;
351 os <<
"Eye-to-hand configuration " << std::endl ;
352 os <<
"s_dot = _L_cVe_fVe_eJe q_dot " << std::endl ;
355 os <<
"Eye-to-hand configuration " << std::endl ;
356 os <<
"s_dot = _L_cVf_fJe q_dot " << std::endl ;
364 os <<
"List of visual features : s" <<std::endl ;
366 std::list<vpBasicFeature *>::const_iterator it_s;
367 std::list<unsigned int>::const_iterator it_select;
372 (*it_s)->print( (*it_select) ) ;
378 os <<
"List of desired visual features : s*" <<std::endl ;
380 std::list<vpBasicFeature *>::const_iterator it_s_star;
381 std::list<unsigned int>::const_iterator it_select;
386 (*it_s_star)->print( (*it_select) ) ;
392 os <<
"Gain : " <<
lambda <<std::endl ;
397 os <<
"Interaction Matrix Ls "<<std::endl ;
399 os <<
L << std::endl;
402 os <<
"not yet computed "<<std::endl ;
411 os <<
"Error vector (s-s*) "<<std::endl ;
413 os <<
error.
t() << std::endl;
416 os <<
"not yet computed "<<std::endl ;
510 unsigned int dim = 0 ;
511 std::list<vpBasicFeature *>::const_iterator it_s;
512 std::list<unsigned int>::const_iterator it_select;
516 dim += (*it_s)->getDimension(*it_select) ;
530 static void computeInteractionMatrixFromList (
const std::list<vpBasicFeature *> & featureList,
531 const std::list<unsigned int> & featureSelectionList,
534 if (featureList.empty())
538 "feature list empty, cannot compute Ls")) ;
553 unsigned int rowL = L.
getRows();
554 const unsigned int colL = 6;
563 unsigned int rowMatrixTmp, colMatrixTmp;
568 unsigned int cursorL = 0;
570 std::list<vpBasicFeature *>::const_iterator it;
571 std::list<unsigned int>::const_iterator it_select;
573 for (it = featureList.begin(), it_select = featureSelectionList.begin(); it != featureList.end(); ++it, ++it_select)
576 matrixTmp = (*it)->interaction( *it_select );
577 rowMatrixTmp = matrixTmp .
getRows();
578 colMatrixTmp = matrixTmp .
getCols();
581 while (rowMatrixTmp + cursorL > rowL) {
583 L.
resize (rowL,colL,
false);
588 for (
unsigned int k = 0; k < rowMatrixTmp; ++k, ++cursorL) {
589 for (
unsigned int j = 0; j < colMatrixTmp; ++j) {
590 L[cursorL][j] = matrixTmp[k][j];
595 L.
resize (cursorL,colL,
false);
617 computeInteractionMatrixFromList(
this ->featureList,
618 this ->featureSelectionList,
638 this ->featureSelectionList, L);
657 computeInteractionMatrixFromList(
this ->featureList,
658 this ->featureSelectionList, L);
660 this ->featureSelectionList, Lstar);
698 if (featureList.empty())
702 "feature list empty, cannot compute Ls")) ;
708 "feature list empty, cannot compute Ls")) ;
732 if (0 == dimError) { dimError = 1;
error .
resize(dimError);}
733 if (0 == dimS) { dimS = 1;
s .
resize(dimS);}
734 if (0 == dimSStar) { dimSStar = 1;
sStar .
resize(dimSStar);}
739 unsigned int dimVectTmp;
744 unsigned int cursorS = 0;
745 unsigned int cursorSStar = 0;
746 unsigned int cursorError = 0;
749 std::list<vpBasicFeature *>::const_iterator it_s;
750 std::list<vpBasicFeature *>::const_iterator it_s_star;
751 std::list<unsigned int>::const_iterator it_select;
753 for (it_s = featureList.begin(), it_s_star =
desiredFeatureList.begin(), it_select = featureSelectionList.begin();
754 it_s != featureList.end();
755 ++it_s, ++it_s_star, ++it_select)
758 desired_s = (*it_s_star);
759 unsigned int select = (*it_select);
762 vectTmp = current_s->
get_s(select);
763 dimVectTmp = vectTmp .
getRows();
764 while (dimVectTmp + cursorS > dimS)
766 for (
unsigned int k = 0; k < dimVectTmp; ++k) {
s[cursorS++] = vectTmp[k]; }
769 vectTmp = desired_s->
get_s(select);
770 dimVectTmp = vectTmp .
getRows();
771 while (dimVectTmp + cursorSStar > dimSStar) {
775 for (
unsigned int k = 0; k < dimVectTmp; ++k) {
776 sStar[cursorSStar++] = vectTmp[k];
780 vectTmp = current_s->
error(*desired_s, select) ;
781 dimVectTmp = vectTmp .
getRows();
782 while (dimVectTmp + cursorError > dimError) {
786 for (
unsigned int k = 0; k < dimVectTmp; ++k) {
787 error[cursorError++] = vectTmp[k];
819 "No control law have been yet defined")) ;
853 "No control law have been yet defined")) ;
904 static int iteration =0;
914 vpERROR_TRACE(
"All the matrices are not correctly initialized") ;
916 "Cannot compute control law "
917 "All the matrices are not correctly"
922 vpERROR_TRACE(
"All the matrices are not correctly updated") ;
931 "No control law have been yet defined")) ;
970 bool imageComputed = false ;
976 imageComputed = true ;
993 if (imageComputed!=
true)
999 imageComputed = true ;
1001 WpW = imJ1t*imJ1t.
t() ;
1004 std::cout <<
"rank J1 " <<
rankJ1 <<std::endl ;
1005 std::cout <<
"imJ1t"<<std::endl << imJ1t ;
1006 std::cout <<
"imJ1"<<std::endl << imJ1 ;
1008 std::cout <<
"WpW" <<std::endl <<
WpW ;
1009 std::cout <<
"J1" <<std::endl <<
J1 ;
1010 std::cout <<
"J1p" <<std::endl <<
J1p ;
1026 std::cout << me << std::endl ;
1032 std::cout << me << std::endl ;
1070 static int iteration =0;
1081 vpERROR_TRACE(
"All the matrices are not correctly initialized") ;
1083 "Cannot compute control law "
1084 "All the matrices are not correctly"
1089 vpERROR_TRACE(
"All the matrices are not correctly updated") ;
1098 "No control law have been yet defined")) ;
1137 bool imageComputed = false ;
1143 imageComputed = true ;
1160 if (imageComputed!=
true)
1166 imageComputed = true ;
1168 WpW = imJ1t*imJ1t.
t() ;
1171 std::cout <<
"rank J1 " <<
rankJ1 <<std::endl ;
1172 std::cout <<
"imJ1t"<<std::endl << imJ1t ;
1173 std::cout <<
"imJ1"<<std::endl << imJ1 ;
1175 std::cout <<
"WpW" <<std::endl <<
WpW ;
1176 std::cout <<
"J1" <<std::endl <<
J1 ;
1177 std::cout <<
"J1p" <<std::endl <<
J1p ;
1183 if (iteration==0 || std::fabs(t) < std::numeric_limits<double>::epsilon()) {
1199 std::cout << me << std::endl ;
1205 std::cout << me << std::endl ;
1243 static int iteration =0;
1254 vpERROR_TRACE(
"All the matrices are not correctly initialized") ;
1256 "Cannot compute control law "
1257 "All the matrices are not correctly"
1262 vpERROR_TRACE(
"All the matrices are not correctly updated") ;
1271 "No control law have been yet defined")) ;
1310 bool imageComputed = false ;
1316 imageComputed = true ;
1333 if (imageComputed!=
true)
1339 imageComputed = true ;
1341 WpW = imJ1t*imJ1t.
t() ;
1344 std::cout <<
"rank J1 " <<
rankJ1 <<std::endl ;
1345 std::cout <<
"imJ1t"<<std::endl << imJ1t ;
1346 std::cout <<
"imJ1"<<std::endl << imJ1 ;
1348 std::cout <<
"WpW" <<std::endl <<
WpW ;
1349 std::cout <<
"J1" <<std::endl <<
J1 ;
1350 std::cout <<
"J1p" <<std::endl <<
J1p ;
1356 if (iteration==0 || std::fabs(t) < std::numeric_limits<double>::epsilon()) {
1372 std::cout << me << std::endl ;
1378 std::cout << me << std::endl ;
1420 vpERROR_TRACE(
"no degree of freedom is free, cannot use secondary task") ;
1422 "no degree of freedom is free, cannot use secondary task")) ;
1478 vpERROR_TRACE(
"no degree of freedom is free, cannot use secondary task") ;
1480 "no degree of freedom is free, cannot use secondary task")) ;
Definition of the vpMatrix class.
unsigned int getDimension() const
Return the task dimension.
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
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.
vpMatrix getTaskJacobian() const
unsigned int rankJ1
Rank of the task Jacobian.
vpVelocityTwistMatrix cVf
Twist transformation matrix between Rf and Rc.
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.
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.
vpMatrix getI_WpW() const
unsigned int dim_task
Dimension of the task updated during computeControlLaw().
vpServoInversionType inversionType
vpColVector secondaryTask(const vpColVector &de2dt)
class that defines what is a visual feature
vpMatrix computeInteractionMatrix()
std::list< unsigned int > featureSelectionList
void setIdentity(const double &val=1.0)
bool testInitialization()
vpColVector computeError()
int signInteractionMatrix
vpColVector computeControlLaw()
vpMatrix J1
Task Jacobian .
vpMatrix L
Interaction matrix.
vpRowVector t() const
transpose of Vector
bool forceInteractionMatrixComputation
Force the interaction matrix computation even if it is already done.
vpAdaptiveGain lambda
Gain used in the control law.
vpVelocityTwistMatrix cVe
Twist transformation matrix between Re and Rc.
Class that consider the particular case of twist transformation matrix that allows to transform a vel...
vpServoIteractionMatrixType
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
vpMatrix getTaskJacobianPseudoInverse() const
std::list< vpBasicFeature * > desiredFeatureList
List of desired visual features .
Class that provides a data structure for the column vectors as well as a set of operations on these v...
void set_cVe(const vpVelocityTwistMatrix &cVe_)
unsigned int getCols() const
Return the number of columns of the matrix.
error that can be emited by the vpMatrix class and its derivates
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.
unsigned int getRows() const
Return the number of rows of the matrix.
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)