Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tutorial-ibvs-4pts.cpp
1 
2 #include <visp3/visual_features/vpFeatureBuilder.h>
3 #include <visp3/vs/vpServo.h>
4 #include <visp3/robot/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)
Implementation of an homogeneous matrix and operations on such kind of matrices.
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:512
error that can be emited by ViSP classes.
Definition: vpException.h:73
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:59
virtual void setSamplingTime(const double &delta_t)
void kill()
Definition: vpServo.cpp:191
vpColVector computeControlLaw()
Definition: vpServo.cpp:954
void setLambda(double c)
Definition: vpServo.h:391
vpHomogeneousMatrix getPosition() const
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Definition: vpServo.cpp:585
static double rad(double deg)
Definition: vpMath.h:104
void setWorldCoordinates(const double oX, const double oY, const double oZ)
Definition: vpPoint.cpp:111
Implementation of column vector and the associated operations.
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:222