Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-ibvs-4pts-plotter-gain-adaptive.cpp
1
2#include <visp3/core/vpConfig.h>
3#include <visp3/gui/vpPlot.h>
4#include <visp3/robot/vpSimulatorCamera.h>
5#include <visp3/visual_features/vpFeatureBuilder.h>
6#include <visp3/vs/vpServo.h>
7
8int main()
9{
10#ifdef ENABLE_VISP_NAMESPACE
11 using namespace VISP_NAMESPACE_NAME;
12#endif
13
14 try {
15 vpHomogeneousMatrix cdMo(0, 0, 0.75, 0, 0, 0);
16 vpHomogeneousMatrix cMo(0.15, -0.1, 1., vpMath::rad(10), vpMath::rad(-10), vpMath::rad(50));
17
18 vpPoint point[4];
19 point[0].setWorldCoordinates(-0.1, -0.1, 0);
20 point[1].setWorldCoordinates(0.1, -0.1, 0);
21 point[2].setWorldCoordinates(0.1, 0.1, 0);
22 point[3].setWorldCoordinates(-0.1, 0.1, 0);
23
26 task.setInteractionMatrixType(vpServo::CURRENT);
27
28 vpAdaptiveGain lambda(4, 0.4, 30);
29 task.setLambda(lambda);
30
31 vpFeaturePoint p[4], pd[4];
32 for (unsigned int i = 0; i < 4; i++) {
33 point[i].track(cdMo);
34 vpFeatureBuilder::create(pd[i], point[i]);
35 point[i].track(cMo);
36 vpFeatureBuilder::create(p[i], point[i]);
37 task.addFeature(p[i], pd[i]);
38 }
39
40 vpHomogeneousMatrix wMc, wMo;
42 robot.setSamplingTime(0.040);
43 robot.getPosition(wMc);
44 wMo = wMc * cMo;
45
46#ifdef VISP_HAVE_DISPLAY
47 vpPlot plotter(2, 250 * 2, 500, 100, 200, "Real time curves plotter");
48 plotter.setTitle(0, "Visual features error");
49 plotter.setTitle(1, "Camera velocities");
50
51 plotter.initGraph(0, 8);
52 plotter.initGraph(1, 6);
53
54 plotter.setLegend(0, 0, "x1");
55 plotter.setLegend(0, 1, "y1");
56 plotter.setLegend(0, 2, "x2");
57 plotter.setLegend(0, 3, "y2");
58 plotter.setLegend(0, 4, "x3");
59 plotter.setLegend(0, 5, "y3");
60 plotter.setLegend(0, 6, "x4");
61 plotter.setLegend(0, 7, "y4");
62
63 plotter.setLegend(1, 0, "v_x");
64 plotter.setLegend(1, 1, "v_y");
65 plotter.setLegend(1, 2, "v_z");
66 plotter.setLegend(1, 3, "w_x");
67 plotter.setLegend(1, 4, "w_y");
68 plotter.setLegend(1, 5, "w_z");
69#endif
70
71 unsigned int iter = 0;
72 while (1) {
73 robot.getPosition(wMc);
74 cMo = wMc.inverse() * wMo;
75 for (unsigned int i = 0; i < 4; i++) {
76 point[i].track(cMo);
77 vpFeatureBuilder::create(p[i], point[i]);
78 }
79 vpColVector v = task.computeControlLaw();
80 robot.setVelocity(vpRobot::CAMERA_FRAME, v);
81
82#ifdef VISP_HAVE_DISPLAY
83 plotter.plot(0, iter, task.getError());
84 plotter.plot(1, iter, v);
85#endif
86 if ((task.getError()).sumSquare() < 0.0001)
87 break;
88
89 vpTime::wait(100);
90
91 iter++;
92 }
93 std::cout << "Convergence in " << iter << " iterations" << std::endl;
94
95#ifdef VISP_HAVE_DISPLAY
96 plotter.saveData(0, "error.dat");
97 plotter.saveData(1, "vc.dat");
98
100#endif
101 }
102 catch (const vpException &e) {
103 std::cout << "Catch an exception: " << e << std::endl;
104 }
105 }
Adaptive gain computation.
Implementation of column vector and the associated operations.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
error that can be emitted by ViSP classes.
Definition vpException.h:60
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:129
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition vpPlot.h:117
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:79
void setWorldCoordinates(double oX, double oY, double oZ)
Definition vpPoint.cpp:116
virtual void setSamplingTime(const double &delta_t)
@ CAMERA_FRAME
Definition vpRobot.h:81
@ EYEINHAND_CAMERA
Definition vpServo.h:176
@ CURRENT
Definition vpServo.h:217
Class that defines the simplest robot: a free flying camera.
VISP_EXPORT int wait(double t0, double t)