Visual Servoing Platform  version 3.0.0
tutorial-ibvs-4pts-plotter-continuous-gain-adaptive.cpp
1 
2 #include <visp3/visual_features/vpFeatureBuilder.h>
3 #include <visp3/vs/vpServo.h>
4 #include <visp3/robot/vpSimulatorCamera.h>
5 #include <visp3/gui/vpPlot.h>
6 
7 int main()
8 {
9  try {
10  vpHomogeneousMatrix cdMo(0, 0, 0.75, 0, 0, 0);
11  vpHomogeneousMatrix cMo(0.15, -0.1, 1., vpMath::rad(10), vpMath::rad(-10), vpMath::rad(50));
12 
13  vpPoint point[4] ;
14  point[0].setWorldCoordinates(-0.1,-0.1, 0);
15  point[1].setWorldCoordinates( 0.1,-0.1, 0);
16  point[2].setWorldCoordinates( 0.1, 0.1, 0);
17  point[3].setWorldCoordinates(-0.1, 0.1, 0);
18 
19  vpServo task ;
22 
23  vpAdaptiveGain lambda(4, 0.4, 30);
24  task.setLambda(lambda);
25 
26  vpFeaturePoint p[4], pd[4] ;
27  for (unsigned int i = 0 ; i < 4 ; i++) {
28  point[i].track(cdMo);
29  vpFeatureBuilder::create(pd[i], point[i]);
30  point[i].track(cMo);
31  vpFeatureBuilder::create(p[i], point[i]);
32  task.addFeature(p[i], pd[i]);
33  }
34 
35  vpHomogeneousMatrix wMc, wMo;
36  vpSimulatorCamera robot;
37  robot.setSamplingTime(0.040);
38  robot.getPosition(wMc);
39  wMo = wMc * cMo;
40 
41 #ifdef VISP_HAVE_DISPLAY
42  vpPlot plotter(2, 250*2, 500, 100, 200, "Real time curves plotter");
43  plotter.setTitle(0, "Visual features error");
44  plotter.setTitle(1, "Camera velocities");
45 
46  plotter.initGraph(0, 8);
47  plotter.initGraph(1, 6);
48 
49  plotter.setLegend(0, 0, "x1");
50  plotter.setLegend(0, 1, "y1");
51  plotter.setLegend(0, 2, "x2");
52  plotter.setLegend(0, 3, "y2");
53  plotter.setLegend(0, 4, "x3");
54  plotter.setLegend(0, 5, "y3");
55  plotter.setLegend(0, 6, "x4");
56  plotter.setLegend(0, 7, "y4");
57 
58  plotter.setLegend(1, 0, "v_x");
59  plotter.setLegend(1, 1, "v_y");
60  plotter.setLegend(1, 2, "v_z");
61  plotter.setLegend(1, 3, "w_x");
62  plotter.setLegend(1, 4, "w_y");
63  plotter.setLegend(1, 5, "w_z");
64 #endif
65 
66  unsigned int iter = 0;
67  while(1) {
68  robot.getPosition(wMc);
69  cMo = wMc.inverse() * wMo;
70  for (unsigned int i = 0 ; i < 4 ; i++) {
71  point[i].track(cMo);
72  vpFeatureBuilder::create(p[i], point[i]);
73  }
74  vpColVector v = task.computeControlLaw(iter*robot.getSamplingTime());
76 
77 #ifdef VISP_HAVE_DISPLAY
78  plotter.plot(0, iter, task.getError());
79  plotter.plot(1, iter, v);
80 #endif
81  if (( task.getError() ).sumSquare() < 0.0001)
82  break;
83 
84  iter++;
85  }
86  std::cout << "Convergence in " << iter << " iterations" << std::endl;
87 
88  task.kill();
89 
90 #ifdef VISP_HAVE_DISPLAY
91  plotter.saveData(0, "error.dat");
92  plotter.saveData(1, "vc.dat");
93 
94  vpDisplay::getClick(plotter.I);
95 #endif
96  }
97  catch(vpException e) {
98  std::cout << "Catch an exception: " << e << std::endl;
99  }
100 }
101 
102 
Adaptive gain computation.
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
double getSamplingTime() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines the simplest robot: a free flying camera.
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
Definition: vpServo.cpp:446
error that can be emited by ViSP classes.
Definition: vpException.h:73
void track(const vpHomogeneousMatrix &cMo)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
Class that defines what is a point.
Definition: vpPoint.h:59
virtual void setSamplingTime(const double &delta_t)
void kill()
Definition: vpServo.cpp:186
vpColVector getError() const
Definition: vpServo.h:271
vpColVector computeControlLaw()
Definition: vpServo.cpp:899
void setLambda(double c)
Definition: vpServo.h:390
vpHomogeneousMatrix getPosition() const
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Definition: vpServo.cpp:519
static double rad(double deg)
Definition: vpMath.h:104
void setWorldCoordinates(const double oX, const double oY, const double oZ)
Definition: vpPoint.cpp:111
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
vpHomogeneousMatrix inverse() const
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:113
virtual bool getClick(bool blocking=true)=0
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void setServo(const vpServoType &servo_type)
Definition: vpServo.cpp:217