ViSP  2.9.0
tutorial-ibvs-4pts.cpp
1 
2 #include <visp/vpFeatureBuilder.h>
3 #include <visp/vpServo.h>
4 #include <visp/vpSimulatorCamera.h>
5 
6 int main()
7 {
8  try {
9  vpHomogeneousMatrix cdMo(0, 0, 0.75, 0, 0, 0);
10  vpHomogeneousMatrix cMo(0.15, -0.1, 1.,
11  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  task.setLambda(0.5);
23 
24  vpFeaturePoint p[4], pd[4] ;
25  for (unsigned int i = 0 ; i < 4 ; i++) {
26  point[i].track(cdMo);
27  vpFeatureBuilder::create(pd[i], point[i]);
28  point[i].track(cMo);
29  vpFeatureBuilder::create(p[i], point[i]);
30  task.addFeature(p[i], pd[i]);
31  }
32 
33  vpHomogeneousMatrix wMc, wMo;
34  vpSimulatorCamera robot;
35  robot.setSamplingTime(0.040);
36  robot.getPosition(wMc);
37  wMo = wMc * cMo;
38 
39  for (unsigned int iter=0; iter < 150; iter ++) {
40  robot.getPosition(wMc);
41  cMo = wMc.inverse() * wMo;
42  for (unsigned int i = 0 ; i < 4 ; i++) {
43  point[i].track(cMo);
44  vpFeatureBuilder::create(p[i], point[i]);
45  }
46  vpColVector v = task.computeControlLaw();
48  }
49 
50  task.kill();
51  }
52  catch(vpException e) {
53  std::cout << "Catch an exception: " << e << std::endl;
54  }
55 }
56 
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)
Definition: vpServo.cpp:449
error that can be emited by ViSP classes.
Definition: vpException.h:76
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()
Definition: vpServo.cpp:189
vpColVector computeControlLaw()
Definition: vpServo.cpp:902
void getPosition(vpHomogeneousMatrix &wMc) const
void setLambda(double c)
Definition: vpServo.h:370
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Definition: vpServo.cpp:522
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
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void setServo(const vpServoType &servo_type)
Definition: vpServo.cpp:220
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