Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-ibvs-4pts-plotter-continuous-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 try {
14 vpHomogeneousMatrix cdMo(0, 0, 0.75, 0, 0, 0);
15 vpHomogeneousMatrix cMo(0.15, -0.1, 1., vpMath::rad(10), vpMath::rad(-10), vpMath::rad(50));
16
17 vpPoint point[4];
18 point[0].setWorldCoordinates(-0.1, -0.1, 0);
19 point[1].setWorldCoordinates(0.1, -0.1, 0);
20 point[2].setWorldCoordinates(0.1, 0.1, 0);
21 point[3].setWorldCoordinates(-0.1, 0.1, 0);
22
25 task.setInteractionMatrixType(vpServo::CURRENT);
26
27 vpAdaptiveGain lambda(4, 0.4, 30);
28 task.setLambda(lambda);
29
30 vpFeaturePoint p[4], pd[4];
31 for (unsigned int i = 0; i < 4; i++) {
32 point[i].track(cdMo);
33 vpFeatureBuilder::create(pd[i], point[i]);
34 point[i].track(cMo);
35 vpFeatureBuilder::create(p[i], point[i]);
36 task.addFeature(p[i], pd[i]);
37 }
38
39 vpHomogeneousMatrix wMc, wMo;
41 robot.setSamplingTime(0.040);
42 robot.getPosition(wMc);
43 wMo = wMc * cMo;
44
45#ifdef VISP_HAVE_DISPLAY
46 vpPlot plotter(2, 250 * 2, 500, 100, 200, "Real time curves plotter");
47 plotter.setTitle(0, "Visual features error");
48 plotter.setTitle(1, "Camera velocities");
49
50 plotter.initGraph(0, 8);
51 plotter.initGraph(1, 6);
52
53 plotter.setLegend(0, 0, "x1");
54 plotter.setLegend(0, 1, "y1");
55 plotter.setLegend(0, 2, "x2");
56 plotter.setLegend(0, 3, "y2");
57 plotter.setLegend(0, 4, "x3");
58 plotter.setLegend(0, 5, "y3");
59 plotter.setLegend(0, 6, "x4");
60 plotter.setLegend(0, 7, "y4");
61
62 plotter.setLegend(1, 0, "v_x");
63 plotter.setLegend(1, 1, "v_y");
64 plotter.setLegend(1, 2, "v_z");
65 plotter.setLegend(1, 3, "w_x");
66 plotter.setLegend(1, 4, "w_y");
67 plotter.setLegend(1, 5, "w_z");
68#endif
69
70 unsigned int iter = 0;
71 while (1) {
72 robot.getPosition(wMc);
73 cMo = wMc.inverse() * wMo;
74 for (unsigned int i = 0; i < 4; i++) {
75 point[i].track(cMo);
76 vpFeatureBuilder::create(p[i], point[i]);
77 }
78 vpColVector v = task.computeControlLaw(iter * robot.getSamplingTime());
79 robot.setVelocity(vpRobot::CAMERA_FRAME, v);
80
81#ifdef VISP_HAVE_DISPLAY
82 plotter.plot(0, iter, task.getError());
83 plotter.plot(1, iter, v);
84#endif
85 if ((task.getError()).sumSquare() < 0.0001)
86 break;
87
88 vpTime::wait(100);
89
90 iter++;
91 }
92 std::cout << "Convergence in " << iter << " iterations" << std::endl;
93
94#ifdef VISP_HAVE_DISPLAY
95 plotter.saveData(0, "error.dat");
96 plotter.saveData(1, "vc.dat");
97
99#endif
100 }
101 catch (const vpException &e) {
102 std::cout << "Catch an exception: " << e << std::endl;
103 }
104}
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)