Main MRPT website > C++ reference for MRPT 1.9.9
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 /**
11  * samples/poses example.
12  * Shows the common PDF and 2D/3D pose manipulation operations.
13  */
14 
16 #include <mrpt/poses/CPoint3D.h>
17 #include <mrpt/poses/CPose3D.h>
19 #include <mrpt/system/CTicTac.h>
20 #include <iostream>
21 
22 using namespace mrpt;
23 using namespace mrpt::poses;
24 using namespace mrpt::system;
25 using namespace std;
26 
27 // ------------------------------------------------------
28 // TestPosePDFOperations
29 // ------------------------------------------------------
31 {
32  CPointPDFGaussian p1, p2, p;
33 
34  /**
35  * Construct the CPointPDFGaussian instances
36  * initialize and pass a mean to the p1, p2 instances and a covariance
37  * matrix. The latter is done by explicitly adding the cov. matrix elemnts
38  */
39  p1.mean = CPoint3D(0, -0.12, 0);
40  p2.mean = CPoint3D(0, -0.1, 0);
41 
42  p1.cov.zeros();
43  p1.cov(0, 0) = 0.06f;
44  p1.cov(0, 1) = 0.002f;
45  p1.cov(1, 0) = 0.002f;
46  p1.cov(1, 1) = 0.02f;
47  p1.cov(2, 2) = 0.0002f;
48 
49  p2.cov.zeros();
50  p2.cov(0, 0) = 0.02f;
51  p2.cov(0, 1) = -0.004f;
52  p2.cov(1, 0) = -0.004f;
53  p2.cov(1, 1) = 0.01f;
54  p2.cov(2, 2) = 0.0002f;
55 
56  // Integral of Product of gaussians:
57  CTicTac tictac;
58  double v;
59 
60  tictac.Tic();
61  for (int i = 0; i < 10000; i++) v = p1.productIntegralWith(p2);
62 
63  printf("Time for computing: %.04fus\n", tictac.Tac() * 1e+6f / 10000);
64 
65  printf("product p1,p2 -> %f\n", v);
66  printf("product p2,p1 -> %f\n", p2.productIntegralNormalizedWith(p1));
67 
68  // Bayesian fusion:
69  p.bayesianFusion(p1, p2);
70  p.saveToTextFile("BayesFusion.txt");
71 
72  cout << "Bayesian fusing of p1 & p2: " << endl;
73  cout << " MEAN: " << p.mean << " COV:" << endl << p.cov << endl;
74 }
75 
76 // ------------------------------------------------------
77 // TestPoseComposition
78 // ------------------------------------------------------
80 {
81  CTicTac tictac;
82 
83  // ---------------------------------------------------------------
84  /**
85  * CPose3D default constructor method takes the arguments in the
86  * (X, Y, Z, YAW=0, PITCH=0, ROLL=0) format. The angles are optional
87  */
88  CPose3D A(0, 0, 0), B(1, 1, 0, DEG2RAD(45), 0, 0), C;
89 
90  C = A - B;
91 
92  cout << "A:\n" << A << endl;
93  cout << "B:\n" << B << endl;
94  cout << "C:\n" << C << endl;
95 
96  // ---------------------------------------------------------------
97  CPose2D p(0.5f, 0.2f, DEG2RAD(10.0f));
98 
99  // stores a sequence of relative, incremental 2D poses
100  CPoses2DSequence seq;
101 
102  CPose2D a(1, 2, (float)DEG2RAD(0));
103  CPose2D b(2, 3, (float)DEG2RAD(45));
104  CPose2D D;
105 
106  CPose2D x(1, 0, (float)DEG2RAD(0));
107  CPose2D y(1, 0, (float)DEG2RAD(45));
108 
109  cout << "a= " << a << endl;
110  cout << "b= " << b << endl;
111 
112  // ------------------------------------------
113  tictac.Tic();
114  D = a + b;
115  printf("%f us\t", tictac.Tac() * 1e6);
116  cout << "a+b= " << D << endl;
117  // ------------------------------------------
118  tictac.Tic();
119  D = b - a;
120  printf("%f us\t", tictac.Tac() * 1e6);
121  cout << "b-a= " << D << endl;
122  // ------------------------------------------
123  tictac.Tic();
124  D = a + (b - a);
125  printf("%f us\t", tictac.Tac() * 1e6);
126  cout << "a + (b-a)= " << D << endl;
127  // ------------------------------------------
128 
129  /**
130  * Incrementally update the pose of the "robot".
131  * Appending the pose is equivalent to a position/rotation change with
132  * regards to the body-fixed frame of reference
133  * For more information refer to:
134  * http://reference.mrpt.org/stable/_c_poses2_d_sequence_8h_source.html
135  */
136  seq.appendPose(y);
137  cout << "last= " << seq.absolutePoseAfterAll() << endl;
138  seq.appendPose(y);
139  cout << "last= " << seq.absolutePoseAfterAll() << endl;
140  seq.appendPose(x);
141  cout << "last= " << seq.absolutePoseAfterAll() << endl;
142 
143  // play the poses from the beginning using the getPose method
144  seq.getPose(0, D);
145  cout << "Pose[0] in seq.= " << D << endl;
146  seq.getPose(1, D);
147  cout << "Pose[1] in seq.= " << D << endl;
148  seq.getPose(2, D);
149  cout << "Pose[2] in seq.= " << D << endl;
150 }
151 
152 // ------------------------------------------------------
153 // MAIN
154 // ------------------------------------------------------
155 int main()
156 {
157  try
158  {
161 
162  return 0;
163  }
164  catch (exception& e)
165  {
166  cout << "MRPT exception caught: " << e.what() << endl;
167  return -1;
168  }
169  catch (...)
170  {
171  printf("Untyped exception!!");
172  return -1;
173  }
174 }
mrpt::poses::CPointPDFGaussian::cov
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
Definition: CPointPDFGaussian.h:46
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition: system/CTicTac.h:19
mrpt::poses::CPoses2DSequence::appendPose
void appendPose(CPose2D &newPose)
Appends a new pose at the end of sequence.
Definition: CPoses2DSequence.cpp:70
mrpt::poses::CPointPDFGaussian
A gaussian distribution for 3D points.
Definition: CPointPDFGaussian.h:25
mrpt::poses::CPoses2DSequence::getPose
void getPose(unsigned int ind, CPose2D &outPose)
Reads the stored pose at index "ind", where the first one is 0, the last "posesCount() - 1".
Definition: CPoses2DSequence.cpp:48
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
p
GLfloat GLfloat p
Definition: glext.h:6305
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:25
mrpt::system::CTicTac::Tac
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
v
const GLdouble * v
Definition: glext.h:3678
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::poses::CPose2D
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:40
CPointPDFGaussian.h
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
b
GLubyte GLubyte b
Definition: glext.h:6279
mrpt::poses::CPoses2DSequence
This class stores a sequence of relative, incremental 2D poses.
Definition: CPoses2DSequence.h:26
TestPosePDFOperations
void TestPosePDFOperations()
Definition: vision_stereo_rectify/test.cpp:30
mrpt::system::CTicTac::Tic
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:79
mrpt::poses::CPointPDFGaussian::productIntegralWith
double productIntegralWith(const CPointPDFGaussian &p) const
Computes the "correspondence likelihood" of this PDF with another one: This is implemented as the int...
Definition: CPointPDFGaussian.cpp:175
mrpt::poses::CPointPDFGaussian::productIntegralNormalizedWith
double productIntegralNormalizedWith(const CPointPDFGaussian &p) const
Computes the "correspondence likelihood" of this PDF with another one: This is implemented as the int...
Definition: CPointPDFGaussian.cpp:235
mrpt::poses::CPoses2DSequence::absolutePoseAfterAll
CPose2D absolutePoseAfterAll()
A shortcut for "absolutePoseOf( posesCount() )".
Definition: CPoses2DSequence.cpp:102
CPoint3D.h
CPose3D.h
CTicTac.h
CPoses2DSequence.h
TestPoseComposition
void TestPoseComposition()
Definition: vision_stereo_rectify/test.cpp:79
mrpt::poses::CPoint3D
A class used to store a 3D point.
Definition: CPoint3D.h:33
mrpt::poses::CPointPDFGaussian::mean
CPoint3D mean
The mean value.
Definition: CPointPDFGaussian.h:44
y
GLenum GLint GLint y
Definition: glext.h:3538
x
GLenum GLint x
Definition: glext.h:3538
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25
a
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
mrpt::DEG2RAD
double DEG2RAD(const double x)
Degrees to radians.
Definition: core/include/mrpt/core/bits_math.h:42



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST