Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
tutorial-ibvs-4pts-plotter-gain-adaptive.cpp
1 
2 #include <visp3/gui/vpPlot.h>
3 #include <visp3/robot/vpSimulatorCamera.h>
4 #include <visp3/visual_features/vpFeatureBuilder.h>
5 #include <visp3/vs/vpServo.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();
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  } catch (const vpException &e) {
97  std::cout << "Catch an exception: " << e << std::endl;
98  }
99 }
Adaptive gain computation.
void setWorldCoordinates(double oX, double oY, double oZ)
Definition: vpPoint.cpp:113
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
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, unsigned int select=vpBasicFeature::FEATURE_ALL)
Definition: vpServo.cpp:497
error that can be emited by ViSP classes.
Definition: vpException.h:71
void track(const vpHomogeneousMatrix &cMo)
vpHomogeneousMatrix inverse() const
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
vpHomogeneousMatrix getPosition() const
Class that defines what is a point.
Definition: vpPoint.h:58
virtual void setSamplingTime(const double &delta_t)
void kill()
Definition: vpServo.cpp:192
vpColVector computeControlLaw()
Definition: vpServo.cpp:935
void setLambda(double c)
Definition: vpServo.h:406
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Definition: vpServo.cpp:574
static double rad(double deg)
Definition: vpMath.h:108
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:115
vpColVector getError() const
Definition: vpServo.h:282
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void setServo(const vpServoType &servo_type)
Definition: vpServo.cpp:223