Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpServo.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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  void setCameraDoF(const vpColVector& dof);
355 
368  void setForceInteractionMatrixComputation(bool force_computation)
369  {
370  this->forceInteractionMatrixComputation = force_computation;
371  }
372 
380  void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType,
381  const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE) ;
382 
391  void setLambda(double c)
392  {
393  lambda .initFromConstant (c) ;
394  }
395 
408  void setLambda(const double gain_at_zero,
409  const double gain_at_infinity,
410  const double slope_at_zero)
411  {
412  lambda .initStandard (gain_at_zero, gain_at_infinity, slope_at_zero) ;
413  }
421  void setLambda(const vpAdaptiveGain& l){lambda=l;}
428  void setMu(double mu_){this->mu=mu_;}
429  // Choice of the visual servoing control law
430  void setServo(const vpServoType &servo_type) ;
431 
435  void set_cVe(const vpVelocityTwistMatrix &cVe_) { this->cVe = cVe_ ; init_cVe = true ; }
439  void set_cVe(const vpHomogeneousMatrix &cMe) { cVe.buildFrom(cMe); init_cVe=true ;}
443  void set_cVf(const vpVelocityTwistMatrix &cVf_) { this->cVf = cVf_ ; init_cVf = true ; }
447  void set_cVf(const vpHomogeneousMatrix &cMf) { cVf.buildFrom(cMf); init_cVf=true ;}
451  void set_fVe(const vpVelocityTwistMatrix &fVe_) { this->fVe = fVe_ ; init_fVe = true ; }
455  void set_fVe(const vpHomogeneousMatrix &fMe) { fVe.buildFrom(fMe); init_fVe=true ;}
456 
460  void set_eJe(const vpMatrix &eJe_) { this->eJe = eJe_ ; init_eJe = true ; }
464  void set_fJe(const vpMatrix &fJe_) { this->fJe = fJe_ ; init_fJe = true ; }
465 
469  bool testInitialization() ;
473  bool testUpdated() ;
474 
475  protected:
477  void init() ;
478 
482  void computeProjectionOperators();
483 
484  public:
495 
502 
507 
512 
515 
517  unsigned int rankJ1 ;
518 
520  std::list<vpBasicFeature *> featureList ;
522  std::list<vpBasicFeature *> desiredFeatureList ;
525  std::list<unsigned int> featureSelectionList ;
526 
529 
538 
539  protected:
540  /*
541  Twist transformation matrix
542  */
543 
546  bool init_cVe ;
549  bool init_cVf ;
552  bool init_fVe ;
553 
554  /*
555  Jacobians
556  */
557 
560  bool init_eJe ;
563  bool init_fJe ;
564 
565  /*
566  Task building
567  */
568 
574  unsigned int dim_task ;
579 
601 
604 
605  double mu;
606 
608 
611 
614 } ;
615 
616 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
Adaptive gain computation.
vpServoType servoType
Chosen visual servoing control law.
Definition: vpServo.h:514
void set_fVe(const vpHomogeneousMatrix &fMe)
Definition: vpServo.h:455
bool interactionMatrixComputed
true if the interaction matrix has been computed.
Definition: vpServo.h:572
bool taskWasKilled
Flag to indicate if the task was killed.
Definition: vpServo.h:576
unsigned int rankJ1
Rank of the task Jacobian.
Definition: vpServo.h:517
vpVelocityTwistMatrix cVf
Twist transformation matrix between Rf and Rc.
Definition: vpServo.h:548
Implementation of an homogeneous matrix and operations on such kind of matrices.
void set_fJe(const vpMatrix &fJe_)
Definition: vpServo.h:464
bool init_cVf
Definition: vpServo.h:549
vpVelocityTwistMatrix fVe
Twist transformation matrix between Re and Rf.
Definition: vpServo.h:551
vpColVector sv
Singular values from the pseudo inverse.
Definition: vpServo.h:603
vpServoType
Definition: vpServo.h:157
vpColVector e1
Primary task .
Definition: vpServo.h:504
bool init_cVe
Definition: vpServo.h:546
void set_eJe(const vpMatrix &eJe_)
Definition: vpServo.h:460
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:562
vpColVector q_dot
Articular velocity.
Definition: vpServo.h:509
unsigned int dim_task
Dimension of the task updated during computeControlLaw().
Definition: vpServo.h:574
vpColVector getTaskSingularValues() const
Definition: vpServo.h:312
vpServoInversionType inversionType
Definition: vpServo.h:537
class that defines what is a visual feature
double mu
Definition: vpServo.h:605
std::list< unsigned int > featureSelectionList
Definition: vpServo.h:525
bool iscJcIdentity
Boolean to know if cJc is identity (for fast computation)
Definition: vpServo.h:610
vpColVector getError() const
Definition: vpServo.h:271
int signInteractionMatrix
Definition: vpServo.h:532
vpMatrix J1
Task Jacobian .
Definition: vpServo.h:492
vpMatrix L
Interaction matrix.
Definition: vpServo.h:486
vpMatrix get_fJe() const
Definition: vpServo.h:338
bool init_fVe
Definition: vpServo.h:552
void setMu(double mu_)
Definition: vpServo.h:428
bool forceInteractionMatrixComputation
Force the interaction matrix computation even if it is already done.
Definition: vpServo.h:578
void setLambda(double c)
Definition: vpServo.h:391
void setForceInteractionMatrixComputation(bool force_computation)
Definition: vpServo.h:368
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:528
void setLambda(const double gain_at_zero, const double gain_at_infinity, const double slope_at_zero)
Definition: vpServo.h:408
vpVelocityTwistMatrix cVe
Twist transformation matrix between Re and Rc.
Definition: vpServo.h:545
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:498
vpServoIteractionMatrixType
Definition: vpServo.h:183
vpColVector e1_initial
Definition: vpServo.h:607
vpMatrix cJc
A diag matrix used to determine which are the degrees of freedom that are controlled in the camera fr...
Definition: vpServo.h:613
void set_cVf(const vpHomogeneousMatrix &cMf)
Definition: vpServo.h:447
void set_fVe(const vpVelocityTwistMatrix &fVe_)
Definition: vpServo.h:451
vpColVector e
Task .
Definition: vpServo.h:506
vpMatrix P
Definition: vpServo.h:600
vpMatrix get_eJe() const
Definition: vpServo.h:334
std::list< vpBasicFeature * > desiredFeatureList
List of desired visual features .
Definition: vpServo.h:522
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
void set_cVe(const vpVelocityTwistMatrix &cVe_)
Definition: vpServo.h:435
bool init_fJe
Definition: vpServo.h:563
void set_cVe(const vpHomogeneousMatrix &cMe)
Definition: vpServo.h:439
vpMatrix I_WpW
Projection operators .
Definition: vpServo.h:583
vpColVector sStar
Definition: vpServo.h:501
vpColVector v
Camera velocity.
Definition: vpServo.h:511
vpVelocityTwistMatrix get_fVe() const
Definition: vpServo.h:330
bool errorComputed
true if the error has been computed.
Definition: vpServo.h:570
vpMatrix WpW
Projection operators .
Definition: vpServo.h:581
bool init_eJe
Definition: vpServo.h:560
vpMatrix J1p
Pseudo inverse of the task Jacobian.
Definition: vpServo.h:494
void setLambda(const vpAdaptiveGain &l)
Definition: vpServo.h:421
std::list< vpBasicFeature * > featureList
List of current visual features .
Definition: vpServo.h:520
void set_cVf(const vpVelocityTwistMatrix &cVf_)
Definition: vpServo.h:443
vpServoPrintType
Definition: vpServo.h:201
vpColVector error
Definition: vpServo.h:490
vpServoIteractionMatrixType interactionMatrixType
Type of the interaction matrox (current, mean, desired, user)
Definition: vpServo.h:534
vpMatrix eJe
Jacobian expressed in the end-effector frame.
Definition: vpServo.h:559