Visual Servoing Platform  version 3.5.1 under development (2022-07-06)
tutorial-ibvs-4pts-plotter-continuous-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(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  vpTime::wait(100);
85 
86  iter++;
87  }
88  std::cout << "Convergence in " << iter << " iterations" << std::endl;
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.
Implementation of column vector and the associated operations.
Definition: vpColVector.h:131
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
error that can be emited by ViSP classes.
Definition: vpException.h:72
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
void track(const vpHomogeneousMatrix &cMo)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
static double rad(double deg)
Definition: vpMath.h:117
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:116
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:82
void setWorldCoordinates(double oX, double oY, double oZ)
Definition: vpPoint.cpp:113
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
@ CAMERA_FRAME
Definition: vpRobot.h:83
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Definition: vpServo.cpp:564
@ EYEINHAND_CAMERA
Definition: vpServo.h:155
void setLambda(double c)
Definition: vpServo.h:404
void setServo(const vpServoType &servo_type)
Definition: vpServo.cpp:215
vpColVector getError() const
Definition: vpServo.h:278
vpColVector computeControlLaw()
Definition: vpServo.cpp:926
@ CURRENT
Definition: vpServo.h:182
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
Definition: vpServo.cpp:487
Class that defines the simplest robot: a free flying camera.
VISP_EXPORT int wait(double t0, double t)