Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tutorial-simu-pioneer-continuous-gain-adaptive.cpp
1 
18 #include <iostream>
19 
20 #include <visp3/visual_features/vpFeatureBuilder.h>
21 #include <visp3/visual_features/vpFeatureDepth.h>
22 #include <visp3/visual_features/vpFeaturePoint.h>
23 #include <visp3/core/vpHomogeneousMatrix.h>
24 #include <visp3/gui/vpPlot.h>
25 #include <visp3/vs/vpServo.h>
26 #include <visp3/robot/vpSimulatorPioneer.h>
27 #include <visp3/core/vpVelocityTwistMatrix.h>
28 
29 int main()
30 {
31  try {
33  cdMo[1][3] = 1.2;
34  cdMo[2][3] = 0.5;
35 
37  cMo[0][3] = 0.3;
38  cMo[1][3] = cdMo[1][3];
39  cMo[2][3] = 1.;
40  vpRotationMatrix cRo(0, atan2( cMo[0][3], cMo[1][3]), 0);
41  cMo.insert(cRo);
42 
43  vpSimulatorPioneer robot ;
44  robot.setSamplingTime(0.04);
45  vpHomogeneousMatrix wMc, wMo;
46  robot.getPosition(wMc);
47  wMo = wMc * cMo;
48 
49  vpPoint point(0,0,0);
50  point.track(cMo);
51 
52  vpServo task;
55  task.setLambda(2, 0.2, 10);
57  cVe = robot.get_cVe();
58  task.set_cVe(cVe);
59 
60  vpMatrix eJe;
61  robot.get_eJe(eJe);
62  task.set_eJe(eJe);
63 
64  vpFeaturePoint s_x, s_xd;
65  vpFeatureBuilder::create(s_x, point);
66  s_xd.buildFrom(0, 0, cdMo[2][3]);
67  task.addFeature(s_x, s_xd, vpFeaturePoint::selectX());
68 
69  vpFeatureDepth s_Z, s_Zd;
70  double Z = point.get_Z();
71  double Zd = cdMo[2][3];
72  s_Z.buildFrom(s_x.get_x(), s_x.get_y(), Z, log(Z/Zd));
73  s_Zd.buildFrom(0, 0, Zd, 0);
74  task.addFeature(s_Z, s_Zd);
75 
76 #ifdef VISP_HAVE_DISPLAY
77  // Create a window (800 by 500) at position (400, 10) with 3 graphics
78  vpPlot graph(3, 800, 500, 400, 10, "Curves...");
79 
80  // Init the curve plotter
81  graph.initGraph(0,2);
82  graph.initGraph(1,2);
83  graph.initGraph(2,1);
84  graph.setTitle(0, "Velocities");
85  graph.setTitle(1, "Error s-s*");
86  graph.setTitle(2, "Depth");
87  graph.setLegend(0, 0, "vx");
88  graph.setLegend(0, 1, "wz");
89  graph.setLegend(1, 0, "x");
90  graph.setLegend(1, 1, "log(Z/Z*)");
91  graph.setLegend(2, 0, "Z");
92 #endif
93 
94  int iter = 0;
95  for (; ;)
96  {
97  robot.getPosition(wMc) ;
98  cMo = wMc.inverse() * wMo;
99 
100  point.track(cMo);
101 
102  vpFeatureBuilder::create(s_x, point);
103 
104  Z = point.get_Z() ;
105  s_Z.buildFrom(s_x.get_x(), s_x.get_y(), Z, log(Z/Zd)) ;
106 
107  robot.get_cVe(cVe);
108  task.set_cVe(cVe);
109  robot.get_eJe(eJe);
110  task.set_eJe(eJe);
111 
112  vpColVector v = task.computeControlLaw(iter*robot.getSamplingTime());
114 
115 #ifdef VISP_HAVE_DISPLAY
116  graph.plot(0, iter, v); // plot velocities applied to the robot
117  graph.plot(1, iter, task.getError()); // plot error vector
118  graph.plot(2, 0, iter, Z); // plot the depth
119 #endif
120 
121  iter ++;
122 
123  if (task.getError().sumSquare() < 0.0001) {
124  std::cout << "Reached a small error. We stop the loop... " << std::endl;
125  break;
126  }
127  }
128 #ifdef VISP_HAVE_DISPLAY
129  graph.saveData(0, "./v2.dat");
130  graph.saveData(1, "./error2.dat");
131 
132  const char *legend = "Click to quit...";
133  vpDisplay::displayText(graph.I, (int)graph.I.getHeight()-60, (int)graph.I.getWidth()-150, legend, vpColor::red);
134  vpDisplay::flush(graph.I);
135  vpDisplay::getClick(graph.I);
136 #endif
137 
138 
139  // Kill the servo task
140  task.print() ;
141  task.kill();
142 
143  }
144  catch(vpException &e) {
145  std::cout << "Catch an exception: " << e << std::endl;
146  }
147 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
double getSamplingTime() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
void set_eJe(const vpMatrix &eJe_)
Definition: vpServo.h:460
vpVelocityTwistMatrix get_cVe() const
Definition: vpUnicycle.h:87
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
void buildFrom(const double x, const double y, const double Z, const double LogZoverZstar)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
Definition: vpServo.cpp:512
Class that defines a 3D point visual feature which is composed by one parameters that is that defin...
Class that defines the Pioneer mobile robot simulator equipped with a static camera.
error that can be emited by ViSP classes.
Definition: vpException.h:73
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
void getPosition(vpHomogeneousMatrix &wMc) const
static void flush(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:163
Class that defines what is a point.
Definition: vpPoint.h:59
Implementation of a rotation matrix and operations on such kind of matrices.
virtual void setSamplingTime(const double &delta_t)
void insert(const vpRotationMatrix &R)
void kill()
Definition: vpServo.cpp:191
vpColVector getError() const
Definition: vpServo.h:271
vpColVector computeControlLaw()
Definition: vpServo.cpp:954
static unsigned int selectX()
void setLambda(double c)
Definition: vpServo.h:391
Implementation of a velocity twist matrix and operations on such kind of matrices.
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Definition: vpServo.cpp:585
void buildFrom(const double x, const double y, const double Z)
double sumSquare() const
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
double get_y() const
double get_x() const
void set_cVe(const vpVelocityTwistMatrix &cVe_)
Definition: vpServo.h:435
vpHomogeneousMatrix inverse() const
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
Definition: vpServo.cpp:314
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:113
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void get_eJe(vpMatrix &eJe)
void setServo(const vpServoType &servo_type)
Definition: vpServo.cpp:222