Visual Servoing Platform  version 3.6.1 under development (2024-03-29)
tutorial-ibvs-4pts.cpp
1 
2 #include <visp3/robot/vpSimulatorCamera.h>
3 #include <visp3/visual_features/vpFeatureBuilder.h>
4 #include <visp3/vs/vpServo.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., 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 (unsigned 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  std::cout << "Start visual-servoing loop..." << std::endl;
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  std::cout << "Stop visual-servoing loop" << std::endl;
51  }
52  catch (const vpException &e) {
53  std::cout << "Catch an exception: " << e << std::endl;
54  }
55 }
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
error that can be emitted by ViSP classes.
Definition: vpException.h:59
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
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:127
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:77
void setWorldCoordinates(double oX, double oY, double oZ)
Definition: vpPoint.cpp:110
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) vp_override
@ CAMERA_FRAME
Definition: vpRobot.h:82
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Definition: vpServo.cpp:378
@ EYEINHAND_CAMERA
Definition: vpServo.h:155
void addFeature(vpBasicFeature &s_cur, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
Definition: vpServo.cpp:329
void setLambda(double c)
Definition: vpServo.h:976
void setServo(const vpServoType &servo_type)
Definition: vpServo.cpp:132
vpColVector computeControlLaw()
Definition: vpServo.cpp:703
@ CURRENT
Definition: vpServo.h:196
Class that defines the simplest robot: a free flying camera.