ViSP  2.8.0
tutorial-ibvs-4pts-ogre.cpp
1 
2 #include <visp/vpAROgre.h>
3 #include <visp/vpFeatureBuilder.h>
4 #include <visp/vpServo.h>
5 #include <visp/vpSimulatorCamera.h>
6 
7 int main()
8 {
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  // Define the target as 4 points
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 #if defined(VISP_HAVE_OGRE)
20  // Color image used as background texture.
21  vpImage<unsigned char> background(480, 640, 255);
22 
23  // Parameters of our camera
24  vpCameraParameters cam(840, 840, background.getWidth()/2, background.getHeight()/2);
25 
26  // Our object
27  // A simulator with the camera parameters defined above,
28  // and the background image size
29  vpAROgre ogre;
30  ogre.setShowConfigDialog(false);
31  ogre.setCameraParameters(cam);
32  ogre.addResource("./"); // Add the path to the Sphere.mesh resource
33  ogre.init(background, false, true);
34 
35  // Create the scene that contains 4 spheres
36  // Sphere.mesh contains a sphere with 1 meter radius
37  std::vector<std::string> name(4);
38  for (int i=0; i<4; i++) {
39  std::ostringstream s; s << "Sphere" << i; name[i] = s.str();
40  ogre.load(name[i], "Sphere.mesh");
41  ogre.setScale(name[i], 0.02f, 0.02f, 0.02f); // Rescale the sphere to 2 cm radius
42  // Set the position of each sphere in the object frame
43  ogre.setPosition(name[i], vpTranslationVector(point[i].get_oX(), point[i].get_oY(), point[i].get_oZ()));
44  }
45 
46  // Add an optional point light source
47  Ogre::Light * light = ogre.getSceneManager()->createLight();
48  light->setDiffuseColour(1, 1, 1); // scaled RGB values
49  light->setSpecularColour(1, 1, 1); // scaled RGB values
50  light->setPosition((Ogre::Real)cdMo[0][3], (Ogre::Real)cdMo[1][3], (Ogre::Real)(-cdMo[2][3]));
51  light->setType(Ogre::Light::LT_POINT);
52 #endif
53 
54  vpServo task ;
57  task.setLambda(0.5);
58 
59  vpFeaturePoint p[4], pd[4] ;
60  for (int i = 0 ; i < 4 ; i++) {
61  point[i].track(cdMo);
62  vpFeatureBuilder::create(pd[i], point[i]);
63  point[i].track(cMo);
64  vpFeatureBuilder::create(p[i], point[i]);
65  task.addFeature(p[i], pd[i]);
66  }
67 
68  vpHomogeneousMatrix wMc, wMo;
69  vpSimulatorCamera robot;
70  robot.setSamplingTime(0.040);
71  robot.getPosition(wMc);
72  wMo = wMc * cMo;
73 
74  for (unsigned int iter=0; iter < 150; iter ++) {
75  robot.getPosition(wMc);
76  cMo = wMc.inverse() * wMo;
77  for (int i = 0 ; i < 4 ; i++) {
78  point[i].track(cMo);
79  vpFeatureBuilder::create(p[i], point[i]);
80  }
81 #if defined(VISP_HAVE_OGRE)
82  // Update the scene from the new camera position
83  ogre.display(background, cMo);
84 #endif
85  vpColVector v = task.computeControlLaw();
87  vpTime::wait( robot.getSamplingTime() * 1000);
88  }
89  task.kill();
90 }
91 
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
double getSamplingTime() const
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 setShowConfigDialog(const bool showConfigDialog)
Definition: vpAROgre.h:221
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, const unsigned int select=vpBasicFeature::FEATURE_ALL)
create a new ste of two visual features
Definition: vpServo.cpp:444
void setLambda(double _lambda)
set the gain lambda
Definition: vpServo.h:253
void track(const vpHomogeneousMatrix &cMo)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
Implementation of an augmented reality viewer.
Definition: vpAROgre.h:90
static int wait(double t0, double t)
Definition: vpTime.cpp:149
Class that defines what is a point.
Definition: vpPoint.h:65
virtual void setSamplingTime(const double &delta_t)
void kill()
destruction (memory deallocation if required)
Definition: vpServo.cpp:177
vpColVector computeControlLaw()
compute the desired control law
Definition: vpServo.cpp:883
Generic class defining intrinsic camera parameters.
void getPosition(vpHomogeneousMatrix &wMc) const
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Set the type of the interaction matrix (current, mean, desired, user).
Definition: vpServo.cpp:509
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)
Class required to compute the visual servoing control law descbribed in and .
Definition: vpServo.h:153
Class that consider the case of a translation vector.
void setServo(vpServoType _servo_type)
Choice of the visual servoing control law.
Definition: vpServo.cpp:214
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