ViSP  2.8.0
tutorial-ibvs-4pts-plotter.cpp
1 
2 #include <visp/vpFeatureBuilder.h>
3 #include <visp/vpServo.h>
4 #include <visp/vpSimulatorCamera.h>
5 #include <visp/vpPlot.h>
6 
7 int main()
8 {
9  vpHomogeneousMatrix cdMo(0, 0, 0.75, 0, 0, 0);
10  vpHomogeneousMatrix cMo(0.15, -0.1, 1., vpMath::rad(10), vpMath::rad(-10), vpMath::rad(50));
11 
12  vpPoint point[4] ;
13  point[0].setWorldCoordinates(-0.1,-0.1, 0);
14  point[1].setWorldCoordinates( 0.1,-0.1, 0);
15  point[2].setWorldCoordinates( 0.1, 0.1, 0);
16  point[3].setWorldCoordinates(-0.1, 0.1, 0);
17 
18  vpServo task ;
21  task.setLambda(0.5);
22 
23  vpFeaturePoint p[4], pd[4] ;
24  for (int i = 0 ; i < 4 ; i++) {
25  point[i].track(cdMo);
26  vpFeatureBuilder::create(pd[i], point[i]);
27  point[i].track(cMo);
28  vpFeatureBuilder::create(p[i], point[i]);
29  task.addFeature(p[i], pd[i]);
30  }
31 
32  vpHomogeneousMatrix wMc, wMo;
33  vpSimulatorCamera robot;
34  robot.setSamplingTime(0.040);
35  robot.getPosition(wMc);
36  wMo = wMc * cMo;
37 
38 #ifdef VISP_HAVE_DISPLAY
39  vpPlot plotter(2, 250*2, 500, 100, 200, "Real time curves plotter");
40  plotter.setTitle(0, "Visual features error");
41  plotter.setTitle(1, "Camera velocities");
42 
43  plotter.initGraph(0, 8);
44  plotter.initGraph(1, 6);
45 
46  plotter.setLegend(0, 0, "x1");
47  plotter.setLegend(0, 1, "y1");
48  plotter.setLegend(0, 2, "x2");
49  plotter.setLegend(0, 3, "y2");
50  plotter.setLegend(0, 4, "x3");
51  plotter.setLegend(0, 5, "y3");
52  plotter.setLegend(0, 6, "x4");
53  plotter.setLegend(0, 7, "y4");
54 
55  plotter.setLegend(1, 0, "v_x");
56  plotter.setLegend(1, 1, "v_y");
57  plotter.setLegend(1, 2, "v_z");
58  plotter.setLegend(1, 3, "w_x");
59  plotter.setLegend(1, 4, "w_y");
60  plotter.setLegend(1, 5, "w_z");
61 #endif
62 
63  for (unsigned int iter=0; iter < 150; iter ++) {
64  robot.getPosition(wMc);
65  cMo = wMc.inverse() * wMo;
66  for (int i = 0 ; i < 4 ; i++) {
67  point[i].track(cMo);
68  vpFeatureBuilder::create(p[i], point[i]);
69  }
70  vpColVector v = task.computeControlLaw();
72 
73 #ifdef VISP_HAVE_DISPLAY
74  plotter.plot(0, iter, task.getError());
75  plotter.plot(1, iter, v);
76 #endif
77  }
78 
79  task.kill();
80 
81 #ifdef VISP_HAVE_DISPLAY
82  plotter.saveData(0, "error.dat");
83  plotter.saveData(1, "vc.dat");
84 
85  vpDisplay::getClick(plotter.I);
86 #endif
87 }
88 
89 
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
Class that defines the simplest robot: a free flying camera.
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
create a new ste of two visual features
Definition: vpServo.cpp:444
void setLambda(double _lambda)
set the gain lambda
Definition: vpServo.h:253
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:65
virtual void setSamplingTime(const double &delta_t)
void kill()
destruction (memory deallocation if required)
Definition: vpServo.cpp:177
vpColVector getError() const
Definition: vpServo.h:301
vpColVector computeControlLaw()
compute the desired control law
Definition: vpServo.cpp:883
void getPosition(vpHomogeneousMatrix &wMc) const
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Set the type of the interaction matrix (current, mean, desired, user).
Definition: vpServo.cpp:509
static double rad(double deg)
Definition: vpMath.h:100
Class that provides a data structure for the column vectors as well as a set of operations on these v...
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:117
virtual bool getClick(bool blocking=true)=0
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class required to compute the visual servoing control law descbribed in and .
Definition: vpServo.h:153
void setServo(vpServoType _servo_type)
Choice of the visual servoing control law.
Definition: vpServo.cpp:214
void setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...
Definition: vpPoint.cpp:74