Visual Servoing Platform  version 3.0.0
vpServo.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Authors:
34  * Eric Marchand
35  * Nicolas Mansard
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
40 
41 #ifndef vpServo_H
42 #define vpServo_H
43 
49 #include <list>
50 
51 #include <visp3/core/vpMatrix.h>
52 #include <visp3/core/vpVelocityTwistMatrix.h>
53 #include <visp3/visual_features/vpBasicFeature.h>
54 #include <visp3/vs/vpServoException.h>
55 #include <visp3/vs/vpAdaptiveGain.h>
56 
57 
151 class VISP_EXPORT vpServo
152 {
153  /*
154  Choice of the visual servoing control law
155  */
156 public:
157  typedef enum
158  {
159  NONE,
161  EYEINHAND_CAMERA,
165  EYEINHAND_L_cVe_eJe,
169  EYETOHAND_L_cVe_eJe,
173  EYETOHAND_L_cVf_fVe_eJe,
177  EYETOHAND_L_cVf_fJe
181  } vpServoType;
182 
183  typedef enum
184  {
185  CURRENT,
187  DESIRED,
189  MEAN,
191  USER_DEFINED
193  } vpServoIteractionMatrixType;
194 
195  typedef enum
196  {
198  PSEUDO_INVERSE
199  } vpServoInversionType;
200 
201  typedef enum
202  {
203  ALL,
210  MINIMUM
211  } vpServoPrintType;
212 
213 //private:
214 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
215 // vpServo(const vpServo &)
216 // : L(), error(), J1(), J1p(), s(), sStar(), e1(), e(), q_dot(), v(), servoType(vpServo::NONE),
217 // rankJ1(0), featureList(), desiredFeatureList(), featureSelectionList(), lambda(), signInteractionMatrix(1),
218 // interactionMatrixType(DESIRED), inversionType(PSEUDO_INVERSE), cVe(), init_cVe(false),
219 // cVf(), init_cVf(false), fVe(), init_fVe(false), eJe(), init_eJe(false), fJe(), init_fJe(false),
220 // errorComputed(false), interactionMatrixComputed(false), dim_task(0), taskWasKilled(false),
221 // forceInteractionMatrixComputation(false), WpW(), I_WpW(), P(), sv(), mu(4.), e1_initial()
222 // {
223 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
224 // }
225 // vpServo &operator=(const vpServo &){
226 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
227 // return *this;
228 // }
229 //#endif
230 
231 public:
232  // default constructor
233  vpServo();
234  // constructor with Choice of the visual servoing control law
235  vpServo(vpServoType servoType) ;
236  // destructor
237  virtual ~vpServo() ;
238 
239  // create a new ste of two visual features
240  void addFeature(vpBasicFeature& s, vpBasicFeature& s_star,
241  const unsigned int select=vpBasicFeature::FEATURE_ALL) ;
242  // create a new ste of two visual features
243  void addFeature(vpBasicFeature& s,
244  const unsigned int select=vpBasicFeature::FEATURE_ALL) ;
245 
246  // compute the desired control law
247  vpColVector computeControlLaw() ;
248  // compute the desired control law
249  vpColVector computeControlLaw(double t) ;
250  vpColVector computeControlLaw(double t, const vpColVector &e_dot_init);
251 
252  // compute the error between the current set of visual features and
253  // the desired set of visual features
254  vpColVector computeError() ;
255  // compute the interaction matrix related to the set of visual features
256  vpMatrix computeInteractionMatrix() ;
257 
258  // Return the task dimension.
259  unsigned int getDimension() const ;
271  inline vpColVector getError() const
272  {
273  return error ;
274  }
275  /*
276  Return the interaction matrix \f$L\f$ used to compute the task jacobian \f$J_1\f$.
277  The interaction matrix is updated after a call to computeInteractionMatrix() or computeControlLaw().
278 
279  \code
280  vpServo task;
281  ...
282  vpColVector v = task.computeControlLaw(); // Compute the velocity corresponding to the visual servoing
283  vpMatrix L = task.getInteractionMatrix(); // Get the interaction matrix used to compute v
284  \endcode
285  \sa getTaskJacobian()
286  */
288  {
289  return L;
290  }
291 
292  vpMatrix getI_WpW() const;
296  inline vpServoType getServoType() const
297  {
298  return servoType;
299  }
300 
301  vpMatrix getLargeP() const;
302 
303  vpMatrix getTaskJacobian() const;
304  vpMatrix getTaskJacobianPseudoInverse() const;
305  unsigned int getTaskRank() const;
306 
313  {
314  return sv;
315  }
316 
317  vpMatrix getWpW() const;
318 
322  vpVelocityTwistMatrix get_cVe() const { return cVe; }
326  vpVelocityTwistMatrix get_cVf() const { return cVf; }
330  vpVelocityTwistMatrix get_fVe() const { return fVe; }
334  vpMatrix get_eJe() const { return eJe; }
338  vpMatrix get_fJe() const { return fJe; }
339 
340  // destruction (memory deallocation if required)
341  void kill() ;
342 
343  void print(const vpServo::vpServoPrintType display_level=ALL,
344  std::ostream &os = std::cout) ;
345 
346  // Add a secondary task.
347  vpColVector secondaryTask(const vpColVector &de2dt, const bool &useLargeProjectionOperator = false) ;
348  // Add a secondary task.
349  vpColVector secondaryTask(const vpColVector &e2, const vpColVector &de2dt, const bool &useLargeProjectionOperator = false) ;
350  // Add a secondary task to avoid the joint limit.
351  vpColVector secondaryTaskJointLimitAvoidance(const vpColVector &q, const vpColVector &dq, const vpColVector & jointMin,
352  const vpColVector & jointMax, const double &rho=0.1, const double &rho1=0.3, const double &lambda_tune=0.7) const;
353 
354 
367  void setForceInteractionMatrixComputation(bool force_computation)
368  {
369  this->forceInteractionMatrixComputation = force_computation;
370  }
371 
379  void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType,
380  const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE) ;
381 
390  void setLambda(double c)
391  {
392  lambda .initFromConstant (c) ;
393  }
394 
407  void setLambda(const double gain_at_zero,
408  const double gain_at_infinity,
409  const double slope_at_zero)
410  {
411  lambda .initStandard (gain_at_zero, gain_at_infinity, slope_at_zero) ;
412  }
420  void setLambda(const vpAdaptiveGain& l){lambda=l;}
427  void setMu(double mu_){this->mu=mu_;}
428  // Choice of the visual servoing control law
429  void setServo(const vpServoType &servo_type) ;
430 
434  void set_cVe(const vpVelocityTwistMatrix &cVe_) { this->cVe = cVe_ ; init_cVe = true ; }
438  void set_cVe(const vpHomogeneousMatrix &cMe) { cVe.buildFrom(cMe); init_cVe=true ;}
442  void set_cVf(const vpVelocityTwistMatrix &cVf_) { this->cVf = cVf_ ; init_cVf = true ; }
446  void set_cVf(const vpHomogeneousMatrix &cMf) { cVf.buildFrom(cMf); init_cVf=true ;}
450  void set_fVe(const vpVelocityTwistMatrix &fVe_) { this->fVe = fVe_ ; init_fVe = true ; }
454  void set_fVe(const vpHomogeneousMatrix &fMe) { fVe.buildFrom(fMe); init_fVe=true ;}
455 
459  void set_eJe(const vpMatrix &eJe_) { this->eJe = eJe_ ; init_eJe = true ; }
463  void set_fJe(const vpMatrix &fJe_) { this->fJe = fJe_ ; init_fJe = true ; }
464 
468  bool testInitialization() ;
472  bool testUpdated() ;
473 
474  protected:
476  void init() ;
477 
481  void computeProjectionOperators();
482 
483  public:
494 
501 
506 
511 
514 
516  unsigned int rankJ1 ;
517 
519  std::list<vpBasicFeature *> featureList ;
521  std::list<vpBasicFeature *> desiredFeatureList ;
524  std::list<unsigned int> featureSelectionList ;
525 
528 
537 
538  protected:
539  /*
540  Twist transformation matrix
541  */
542 
545  bool init_cVe ;
548  bool init_cVf ;
551  bool init_fVe ;
552 
553  /*
554  Jacobians
555  */
556 
559  bool init_eJe ;
562  bool init_fJe ;
563 
564  /*
565  Task building
566  */
567 
573  unsigned int dim_task ;
578 
600 
601 
602 
605 
606  double mu;
607 
609 
610 } ;
611 
612 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:92
Adaptive gain computation.
vpServoType servoType
Chosen visual servoing control law.
Definition: vpServo.h:513
void set_fVe(const vpHomogeneousMatrix &fMe)
Definition: vpServo.h:454
bool interactionMatrixComputed
true if the interaction matrix has been computed.
Definition: vpServo.h:571
bool taskWasKilled
Flag to indicate if the task was killed.
Definition: vpServo.h:575
unsigned int rankJ1
Rank of the task Jacobian.
Definition: vpServo.h:516
vpVelocityTwistMatrix cVf
Twist transformation matrix between Rf and Rc.
Definition: vpServo.h:547
Implementation of an homogeneous matrix and operations on such kind of matrices.
void set_fJe(const vpMatrix &fJe_)
Definition: vpServo.h:463
bool init_cVf
Definition: vpServo.h:548
vpVelocityTwistMatrix fVe
Twist transformation matrix between Re and Rf.
Definition: vpServo.h:550
vpColVector sv
Singular values from the pseudo inverse.
Definition: vpServo.h:604
vpServoType
Definition: vpServo.h:157
vpColVector e1
Primary task .
Definition: vpServo.h:503
bool init_cVe
Definition: vpServo.h:545
void set_eJe(const vpMatrix &eJe_)
Definition: vpServo.h:459
vpVelocityTwistMatrix get_cVe() const
Definition: vpServo.h:322
vpServoInversionType
Definition: vpServo.h:195
vpMatrix fJe
Jacobian expressed in the robot reference frame.
Definition: vpServo.h:561
vpColVector q_dot
Articular velocity.
Definition: vpServo.h:508
unsigned int dim_task
Dimension of the task updated during computeControlLaw().
Definition: vpServo.h:573
vpColVector getTaskSingularValues() const
Definition: vpServo.h:312
vpServoInversionType inversionType
Definition: vpServo.h:536
class that defines what is a visual feature
double mu
Definition: vpServo.h:606
std::list< unsigned int > featureSelectionList
Definition: vpServo.h:524
vpColVector getError() const
Definition: vpServo.h:271
int signInteractionMatrix
Definition: vpServo.h:531
vpMatrix J1
Task Jacobian .
Definition: vpServo.h:491
vpMatrix L
Interaction matrix.
Definition: vpServo.h:485
vpMatrix get_fJe() const
Definition: vpServo.h:338
bool init_fVe
Definition: vpServo.h:551
void setMu(double mu_)
Definition: vpServo.h:427
bool forceInteractionMatrixComputation
Force the interaction matrix computation even if it is already done.
Definition: vpServo.h:577
void setLambda(double c)
Definition: vpServo.h:390
void setForceInteractionMatrixComputation(bool force_computation)
Definition: vpServo.h:367
vpMatrix getInteractionMatrix() const
Definition: vpServo.h:287
vpVelocityTwistMatrix get_cVf() const
Definition: vpServo.h:326
vpAdaptiveGain lambda
Gain used in the control law.
Definition: vpServo.h:527
void setLambda(const double gain_at_zero, const double gain_at_infinity, const double slope_at_zero)
Definition: vpServo.h:407
vpVelocityTwistMatrix cVe
Twist transformation matrix between Re and Rc.
Definition: vpServo.h:544
Implementation of a velocity twist matrix and operations on such kind of matrices.
vpServoType getServoType() const
Definition: vpServo.h:296
vpColVector s
Definition: vpServo.h:497
vpServoIteractionMatrixType
Definition: vpServo.h:183
vpColVector e1_initial
Definition: vpServo.h:608
void set_cVf(const vpHomogeneousMatrix &cMf)
Definition: vpServo.h:446
void set_fVe(const vpVelocityTwistMatrix &fVe_)
Definition: vpServo.h:450
vpColVector e
Task .
Definition: vpServo.h:505
vpMatrix P
Definition: vpServo.h:599
vpMatrix get_eJe() const
Definition: vpServo.h:334
std::list< vpBasicFeature * > desiredFeatureList
List of desired visual features .
Definition: vpServo.h:521
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
void set_cVe(const vpVelocityTwistMatrix &cVe_)
Definition: vpServo.h:434
bool init_fJe
Definition: vpServo.h:562
void set_cVe(const vpHomogeneousMatrix &cMe)
Definition: vpServo.h:438
vpMatrix I_WpW
Projection operators .
Definition: vpServo.h:582
vpColVector sStar
Definition: vpServo.h:500
vpColVector v
Camera velocity.
Definition: vpServo.h:510
vpVelocityTwistMatrix get_fVe() const
Definition: vpServo.h:330
bool errorComputed
true if the error has been computed.
Definition: vpServo.h:569
vpMatrix WpW
Projection operators .
Definition: vpServo.h:580
bool init_eJe
Definition: vpServo.h:559
vpMatrix J1p
Pseudo inverse of the task Jacobian.
Definition: vpServo.h:493
void setLambda(const vpAdaptiveGain &l)
Definition: vpServo.h:420
std::list< vpBasicFeature * > featureList
List of current visual features .
Definition: vpServo.h:519
void set_cVf(const vpVelocityTwistMatrix &cVf_)
Definition: vpServo.h:442
vpServoPrintType
Definition: vpServo.h:201
vpColVector error
Definition: vpServo.h:489
vpServoIteractionMatrixType interactionMatrixType
Type of the interaction matrox (current, mean, desired, user)
Definition: vpServo.h:533
vpMatrix eJe
Jacobian expressed in the end-effector frame.
Definition: vpServo.h:558