Main MRPT website > C++ reference for MRPT 1.9.9
CActionRobotMovement3D.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-2017, 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 #include "obs-precomp.h" // Precompiled headers
11 
12 #include <mrpt/random.h>
13 #include <mrpt/utils/CStream.h>
16 
17 using namespace mrpt;
18 using namespace mrpt::obs;
19 using namespace mrpt::utils;
20 using namespace mrpt::poses;
21 using namespace mrpt::random;
22 using namespace mrpt::utils;
23 
25 
26 /*---------------------------------------------------------------
27  Constructor
28  ---------------------------------------------------------------*/
30  : poseChange(),
31  rawOdometryIncrementReading(),
32  estimationMethod(emOdometry),
33  motionModelConfiguration(),
34  hasVelocities(6, false),
35  velocities(6)
36 {
37  velocities.assign(.0);
38 }
39 
40 /*---------------------------------------------------------------
41  Implements the writing to a CStream capability of CSerializable objects
42  ---------------------------------------------------------------*/
44  mrpt::utils::CStream& out, int* version) const
45 {
46  if (version)
47  *version = 1;
48  else
49  {
50  uint32_t i = static_cast<uint32_t>(estimationMethod);
51 
52  out << i;
53 
54  // The PDF:
55  out << poseChange;
56 
57  out << hasVelocities << velocities;
58 
59  out << timestamp;
60  }
61 }
62 
63 /*---------------------------------------------------------------
64  Implements the reading from a CStream capability of CSerializable objects
65  ---------------------------------------------------------------*/
67  mrpt::utils::CStream& in, int version)
68 {
69  switch (version)
70  {
71  case 0:
72  case 1:
73  {
74  uint32_t i;
75 
76  // Read the estimation method first:
77  in >> i;
78  estimationMethod = static_cast<TEstimationMethod>(i);
79 
80  in >> poseChange;
81  in >> hasVelocities >> velocities;
82 
83  if (version >= 1)
84  in >> timestamp;
85  else
86  timestamp = INVALID_TIMESTAMP;
87  }
88  break;
89  default:
91  };
92 }
93 
95  const CPose3D& odometryIncrement, const TMotionModelOptions& options)
96 {
97  // Set the members data:
98  estimationMethod = emOdometry;
99  rawOdometryIncrementReading = odometryIncrement;
100  motionModelConfiguration = options;
101 
102  if (options.modelSelection == mm6DOF)
103  computeFromOdometry_model6DOF(odometryIncrement, options);
104 }
105 
106 /*---------------------------------------------------------------
107  TMotionModelOptions
108  ---------------------------------------------------------------*/
110  : modelSelection(mm6DOF), mm6DOFModel()
111 {
113  mm6DOFModel.a1 = 0.05f;
114  mm6DOFModel.a2 = 0.05f;
115  mm6DOFModel.a3 = 0.05f;
116  mm6DOFModel.a4 = 0.05f;
117  mm6DOFModel.a5 = 0.05f;
118  mm6DOFModel.a6 = 0.05f;
119  mm6DOFModel.a7 = 0.05f;
120  mm6DOFModel.a8 = 0.05f;
121  mm6DOFModel.a9 = 0.05f;
122  mm6DOFModel.a10 = 0.05f;
125 }
126 
127 /*---------------------------------------------------------------
128  computeFromOdometry_model6DOF
129  ---------------------------------------------------------------*/
131  const CPose3D& odometryIncrement, const TMotionModelOptions& o)
132 {
133  // The Gaussian PDF:
134  // ---------------------------
135  CPose3DPDFParticles* aux;
136  static CPose3D nullPose(0, 0, 0, 0, 0, 0);
137 
138  mrpt::poses::CPose3DPDF::Ptr poseChangeTemp =
139  mrpt::make_aligned_shared<CPose3DPDFParticles>();
140  aux = static_cast<CPose3DPDFParticles*>(poseChangeTemp.get());
141 
142  // Set the number of particles:
144 
145  // The motion model: A. L. Ballardini, A. Furlan, A. Galbiati, M. Matteucci,
146  // F. Sacchi, D. G. Sorrenti An effective 6DoF motion model for 3D-6DoF
147  // Monte Carlo Localization 4th Workshop on Planning, Perception and
148  // Navigation for Intelligent Vehicles, IROS, 2012
149 
150  /*
151  The brief description:
152  Find XYZ deltas: dX=x(t)-x(t-1); dY=y(t)-y(t-1); dZ=z(t)-z(t-1)
153  Find angular deltas (normalised): dRoll=roll(t)-roll(t-1);
154  dPitch=pitch(t)-pitch(t-1); dYaw=yaw(t)-yaw(t-1)
155 
156  Here t - is time step
157 
158  Calculate the odometry for 6DOF:
159 
160 
161  yaw1 = atan2 (dY,dX)
162  pitch1 = atan2 (dZ , sqrt(dX^2 + dY^2 + dZ^2) )
163  trans = sqrt(dX^2 + dY^2 + dZ^2)
164  roll = dRoll
165  yaw2= dYaw
166  pitch2= dPitch
167 
168 
169  Model the error:
170 
171 
172  yaw1_draw = yaw1 + sample(a1 * yaw1 + a2 * trans )
173  pitch1_draw = pitch1 + sample(a3 * dZ )
174  trans_draw = trans + sample( a4 * trans + a5 * yaw2 + a6 * (roll
175  + pitch2 ) )
176  roll_draw = roll + sample(a7 * roll)
177  pitch2_draw = pitch2 + sample(a8 * pitch2 )
178  yaw2_draw = yaw2 + sample(a9 * yaw2 + a10 * trans )
179 
180  Here sample() - sampling from zero mean Gaussian distribution
181 
182  Calculate the spherical coordinates:
183  x = trans_draw * sin( pitch1_draw ) * cos ( yaw1_draw )
184  y = trans_draw * sin( pitch1_draw ) * sin ( yaw1_draw )
185  z = trans_draw * cos( pitch1_draw )
186  roll = roll_draw
187  pitch = pitch1_draw + pitch2_draw
188  yaw = yaw1_draw + yaw2_draw
189 
190  normalize_angle(roll, pitch, yaw )
191  */
192 
193  // The increments in odometry:
194  float Ayaw1 = (odometryIncrement.y() != 0 || odometryIncrement.x() != 0)
195  ? atan2(odometryIncrement.y(), odometryIncrement.x())
196  : 0;
197 
198  float Atrans = odometryIncrement.norm();
199 
200  float Apitch1 = (odometryIncrement.y() != 0 || odometryIncrement.x() != 0 ||
201  odometryIncrement.z() != 0)
202  ? atan2(odometryIncrement.z(), odometryIncrement.norm())
203  : 0;
204 
205  float Aroll = odometryIncrement.roll();
206  float Apitch2 = odometryIncrement.pitch();
207  float Ayaw2 = odometryIncrement.yaw();
208 
209  // Draw samples:
210  for (size_t i = 0; i < o.mm6DOFModel.nParticlesCount; i++)
211  {
212  float Ayaw1_draw =
213  Ayaw1 +
214  (o.mm6DOFModel.a1 * Ayaw1 + o.mm6DOFModel.a2 * Atrans) *
216  float Apitch1_draw = Apitch1 +
217  (o.mm6DOFModel.a3 * odometryIncrement.z()) *
219  float Atrans_draw =
220  Atrans +
221  (o.mm6DOFModel.a4 * Atrans + o.mm6DOFModel.a5 * Ayaw2 +
222  o.mm6DOFModel.a6 * (Aroll + Apitch2)) *
224 
225  float Aroll_draw = Aroll +
226  (o.mm6DOFModel.a7 * Aroll) *
228  float Apitch2_draw = Apitch2 +
229  (o.mm6DOFModel.a8 * Apitch2) *
231  float Ayaw2_draw =
232  Ayaw2 +
233  (o.mm6DOFModel.a9 * Ayaw2 + o.mm6DOFModel.a10 * Atrans) *
235 
236  // Output:
237  aux->m_particles[i].d->x(
238  Atrans_draw * sin(Apitch1_draw) * cos(Ayaw1_draw) +
240  getRandomGenerator().drawGaussian1D_normalized());
241  aux->m_particles[i].d->y(
242  Atrans_draw * sin(Apitch1_draw) * sin(Ayaw1_draw) +
244  getRandomGenerator().drawGaussian1D_normalized());
245  aux->m_particles[i].d->z(
246  Atrans_draw * cos(Apitch1_draw) +
248  getRandomGenerator().drawGaussian1D_normalized());
249 
250  double new_yaw =
251  Ayaw1_draw + Ayaw2_draw +
254  double new_pitch =
255  Apitch1_draw + Apitch2_draw +
258  double new_roll =
259  Aroll_draw +
262 
263  aux->m_particles[i].d->setYawPitchRoll(new_yaw, new_pitch, new_roll);
264  aux->m_particles[i].d->normalizeAngles();
265  }
266 
267  poseChange.copyFrom(*poseChangeTemp);
268 }
A namespace of pseudo-random numbers genrators of diferent distributions.
struct mrpt::obs::CActionRobotMovement3D::TMotionModelOptions::TOptions_6DOFModel mm6DOFModel
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:135
mrpt::poses::CPose3DPDFGaussian poseChange
The 3D pose change probabilistic estimation.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
void copyFrom(const CPose3DPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
void computeFromOdometry_model6DOF(const mrpt::poses::CPose3D &odometryIncrement, const TMotionModelOptions &o)
Computes the PDF of the pose increment from an odometry reading, using the motion model for 6 DOF...
double pitch() const
Get the PITCH angle (in radians)
Definition: CPose3D.h:539
double yaw() const
Get the YAW angle (in radians)
Definition: CPose3D.h:533
struct mrpt::obs::CActionRobotMovement3D::TMotionModelOptions motionModelConfiguration
float additional_std_XYZ
An additional noise added to the 6DOF model (std.
void computeFromOdometry(const mrpt::poses::CPose3D &odometryIncrement, const TMotionModelOptions &options)
Computes the PDF of the pose increment from an odometry reading and according to the given motion mod...
The parameter to be passed to "computeFromOdometry".
Represents a probabilistic 3D (6D) movement.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
uint32_t nParticlesCount
Options for the 6DOFModel model which generates a CPosePDFParticles object an then create from that C...
double norm() const
Returns the euclidean norm of vector: .
Definition: CPoseOrPoint.h:252
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
TEstimationMethod
A list of posible ways for estimating the content of a CActionRobotMovement3D object.
std::shared_ptr< CPose3DPDF > Ptr
Definition: CPose3DPDF.h:45
This namespace contains representation of robot actions and observations.
#define DEG2RAD
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
double roll() const
Get the ROLL angle (in radians)
Definition: CPose3D.h:545
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
Definition: datetime.h:16
Declares a class for storing a robot action.
Definition: CAction.h:28
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
TDrawSampleMotionModel modelSelection
The model to be used.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
void resetDeterministic(const CPose3D &location, size_t particlesCount=0)
Reset the PDF to a single point: All m_particles will be set exactly to the supplied pose...
GLuint in
Definition: glext.h:7274
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
unsigned __int32 uint32_t
Definition: rptypes.h:47
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
Declares a class that represents a Probability Density function (PDF) of a 3D pose.
double drawGaussian1D_normalized()
Generate a normalized (mean=0, std=1) normally distributed sample.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019