Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
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
7int 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
25 task.setInteractionMatrixType(vpServo::CURRENT);
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;
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();
52 robot.setVelocity(vpRobot::CAMERA_FRAME, v);
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.
error that can be emitted by ViSP classes.
Definition vpException.h:60
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: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:116
virtual void setSamplingTime(const double &delta_t)
@ CAMERA_FRAME
Definition vpRobot.h:81
@ EYEINHAND_CAMERA
Definition vpServo.h:176
@ CURRENT
Definition vpServo.h:217
Class that defines the simplest robot: a free flying camera.