Visual Servoing Platform  version 3.6.1 under development (2024-11-14)
tutorial-ibvs-4pts.cpp
1 
2 #include <visp3/core/vpConfig.h>
3 #include <visp3/robot/vpSimulatorCamera.h>
4 #include <visp3/visual_features/vpFeatureBuilder.h>
5 #include <visp3/vs/vpServo.h>
6 
7 int main()
8 {
9 #ifdef ENABLE_VISP_NAMESPACE
10  using namespace VISP_NAMESPACE_NAME;
11 #endif
12 
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 
23  vpServo task;
26  task.setLambda(0.5);
27 
28  vpFeaturePoint p[4], pd[4];
29  for (unsigned int i = 0; i < 4; i++) {
30  point[i].track(cdMo);
31  vpFeatureBuilder::create(pd[i], point[i]);
32  point[i].track(cMo);
33  vpFeatureBuilder::create(p[i], point[i]);
34  task.addFeature(p[i], pd[i]);
35  }
36 
37  vpHomogeneousMatrix wMc, wMo;
38  vpSimulatorCamera robot;
39  robot.setSamplingTime(0.040);
40  robot.getPosition(wMc);
41  wMo = wMc * cMo;
42 
43  std::cout << "Start visual-servoing loop..." << std::endl;
44  for (unsigned int iter = 0; iter < 150; iter++) {
45  robot.getPosition(wMc);
46  cMo = wMc.inverse() * wMo;
47  for (unsigned int i = 0; i < 4; i++) {
48  point[i].track(cMo);
49  vpFeatureBuilder::create(p[i], point[i]);
50  }
51  vpColVector v = task.computeControlLaw();
53  }
54 
55  std::cout << "Stop visual-servoing loop" << std::endl;
56  }
57  catch (const vpException &e) {
58  std::cout << "Catch an exception: " << e << std::endl;
59  }
60 }
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
error that can be emitted by ViSP classes.
Definition: vpException.h:60
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpImagePoint &t)
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
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:111
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
@ CAMERA_FRAME
Definition: vpRobot.h:84
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Definition: vpServo.cpp:380
@ EYEINHAND_CAMERA
Definition: vpServo.h:161
void addFeature(vpBasicFeature &s_cur, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
Definition: vpServo.cpp:331
void setLambda(double c)
Definition: vpServo.h:986
void setServo(const vpServoType &servo_type)
Definition: vpServo.cpp:134
vpColVector computeControlLaw()
Definition: vpServo.cpp:705
@ CURRENT
Definition: vpServo.h:202
Class that defines the simplest robot: a free flying camera.