34 rawOdometryIncrementReading(),
35 estimationMethod(emOdometry),
36 hasEncodersInfo(false),
40 velocityLocal(.0, .0, .0),
41 motionModelConfiguration(),
65 if (estimationMethod == emOdometry)
68 out << rawOdometryIncrementReading;
70 i =
static_cast<uint32_t>(motionModelConfiguration.modelSelection);
72 out << motionModelConfiguration.gaussianModel.a1
73 << motionModelConfiguration.gaussianModel.a2
74 << motionModelConfiguration.gaussianModel.a3
75 << motionModelConfiguration.gaussianModel.a4
76 << motionModelConfiguration.gaussianModel.minStdXY
77 << motionModelConfiguration.gaussianModel.minStdPHI;
79 out << motionModelConfiguration.thrunModel.nParticlesCount
80 << motionModelConfiguration.thrunModel.alfa1_rot_rot
81 << motionModelConfiguration.thrunModel.alfa2_rot_trans
82 << motionModelConfiguration.thrunModel.alfa3_trans_trans
83 << motionModelConfiguration.thrunModel.alfa4_trans_rot
84 << motionModelConfiguration.thrunModel.additional_std_XY
85 << motionModelConfiguration.thrunModel.additional_std_phi;
95 if (hasVelocities) out << velocityLocal;
97 out << hasEncodersInfo;
99 out << encoderLeftTicks << encoderRightTicks;
128 if (estimationMethod == emOdometry)
131 in >> rawOdometryIncrementReading;
134 motionModelConfiguration.modelSelection =
137 in >> motionModelConfiguration.gaussianModel.a1 >>
138 motionModelConfiguration.gaussianModel.a2 >>
139 motionModelConfiguration.gaussianModel.a3 >>
140 motionModelConfiguration.gaussianModel.a4 >>
141 motionModelConfiguration.gaussianModel.minStdXY >>
142 motionModelConfiguration.gaussianModel.minStdPHI;
145 motionModelConfiguration.thrunModel.nParticlesCount = i;
146 in >> motionModelConfiguration.thrunModel.alfa1_rot_rot >>
147 motionModelConfiguration.thrunModel.alfa2_rot_trans >>
148 motionModelConfiguration.thrunModel.alfa3_trans_trans >>
149 motionModelConfiguration.thrunModel.alfa4_trans_rot;
154 motionModelConfiguration.thrunModel.additional_std_XY >>
155 motionModelConfiguration.thrunModel.additional_std_phi;
159 motionModelConfiguration.thrunModel.additional_std_XY =
160 motionModelConfiguration.thrunModel.additional_std_phi =
166 rawOdometryIncrementReading, motionModelConfiguration);
179 if (hasVelocities)
in >> velocityLocal;
183 float velocityLin, velocityAng;
184 in >> velocityLin >> velocityAng;
185 velocityLocal.vx = velocityLin;
186 velocityLocal.vy = .0f;
187 velocityLocal.omega = velocityAng;
189 in >> hasEncodersInfo;
190 if (version < 7 || hasEncodersInfo)
193 encoderLeftTicks = i;
195 encoderRightTicks = i;
199 encoderLeftTicks = 0;
200 encoderRightTicks = 0;
221 if (estimationMethod == emOdometry)
224 in >> rawOdometryIncrementReading;
227 motionModelConfiguration.modelSelection =
230 float dum1, dum2, dum3;
232 in >> dum1 >> dum2 >> dum3 >>
233 motionModelConfiguration.gaussianModel.minStdXY >>
234 motionModelConfiguration.gaussianModel.minStdPHI;
238 motionModelConfiguration.thrunModel.nParticlesCount = i;
239 in >> motionModelConfiguration.thrunModel.alfa1_rot_rot;
240 in >> motionModelConfiguration.thrunModel.alfa2_rot_trans >>
241 motionModelConfiguration.thrunModel.alfa3_trans_trans >>
242 motionModelConfiguration.thrunModel.alfa4_trans_rot;
246 rawOdometryIncrementReading, motionModelConfiguration);
258 float velocityLin, velocityAng;
259 in >> velocityLin >> velocityAng;
260 velocityLocal.vx = velocityLin;
261 velocityLocal.vy = .0f;
262 velocityLocal.omega = velocityAng;
264 in >> hasEncodersInfo;
267 encoderLeftTicks = i;
269 encoderRightTicks = i;
284 if (estimationMethod == emOdometry)
287 in >> rawOdometryIncrementReading;
293 in.ReadBuffer(&dummy,
sizeof(dummy));
299 rawOdometryIncrementReading, motionModelConfiguration);
311 float velocityLin, velocityAng;
312 in >> velocityLin >> velocityAng;
313 velocityLocal.vx = velocityLin;
314 velocityLocal.vy = .0f;
315 velocityLocal.omega = velocityAng;
317 in >> hasEncodersInfo;
319 encoderLeftTicks = i;
321 encoderRightTicks = i;
339 if (estimationMethod == emOdometry)
340 poseChange->getMean(rawOdometryIncrementReading);
342 rawOdometryIncrementReading =
CPose2D(0, 0, 0);
348 float velocityLin, velocityAng;
349 in >> velocityLin >> velocityAng;
350 velocityLocal.vx = velocityLin;
351 velocityLocal.vy = .0f;
352 velocityLocal.omega = velocityAng;
354 in >> hasEncodersInfo;
356 encoderLeftTicks = i;
358 encoderRightTicks = i;
363 hasVelocities = hasEncodersInfo =
false;
364 encoderLeftTicks = encoderRightTicks = 0;
378 double K_left,
double K_right,
double D)
383 0.5 * (K_right * encoderRightTicks + K_left * encoderLeftTicks);
385 (K_right * encoderRightTicks - K_left * encoderLeftTicks) / D;
390 const double R = As / Aphi;
392 y =
R * (1 - cos(Aphi));
401 computeFromOdometry(
CPose2D(
x,
y, Aphi), motionModelConfiguration);
412 estimationMethod = emOdometry;
413 rawOdometryIncrementReading = odometryIncrement;
414 motionModelConfiguration = options;
417 computeFromOdometry_modelGaussian(odometryIncrement, options);
419 computeFromOdometry_modelThrun(odometryIncrement, options);
455 poseChange = mrpt::make_aligned_shared<CPosePDFGaussian>();
463 double Al = odometryIncrement.
norm();
479 double cos_Aphi_2 = cos(odometryIncrement.
phi() / 2);
480 double sin_Aphi_2 = sin(odometryIncrement.
phi() / 2);
482 H(0, 0) = H(1, 1) = cos_Aphi_2;
483 H(0, 1) = -(H(1, 0) = sin_Aphi_2);
488 J(0, 2) = -sin_Aphi_2 * ODO_INCR(0, 0) - cos_Aphi_2 * ODO_INCR(1, 0);
489 J(1, 2) = cos_Aphi_2 * ODO_INCR(0, 0) - sin_Aphi_2 * ODO_INCR(1, 0);
492 aux->mean = odometryIncrement;
495 J.multiply_HCHt(C_ODO, aux->cov);
507 static CPose2D nullPose(0, 0, 0);
509 poseChange = mrpt::make_aligned_shared<CPosePDFParticles>();
523 float Arot1 = (odometryIncrement.
y() != 0 || odometryIncrement.
x() != 0)
524 ? atan2(odometryIncrement.
y(), odometryIncrement.
x())
526 float Atrans = odometryIncrement.
norm();
532 float Arot1_draw = Arot1 -
541 float Arot2_draw = Arot2 -
547 aux->m_particles[i].d->x(
548 Atrans_draw * cos(Arot1_draw) +
551 aux->m_particles[i].d->y(
552 Atrans_draw * sin(Arot1_draw) +
555 aux->m_particles[i].d->phi(
556 Arot1_draw + Arot2_draw +
559 aux->m_particles[i].d->normalizePhi();
627 (fabs(Arot1) + fabs(Arot2))) *
637 Atrans_draw * cos(Arot1_draw) +
641 Atrans_draw * sin(Arot1_draw) +
645 Arot1_draw + Arot2_draw +
713 D = D.array().sqrt().matrix();
730 for (
size_t i = 0; i < 3; i++)
733 for (
size_t d = 0; d < 3; d++)
A namespace of pseudo-random numbers genrators of diferent distributions.
double x() const
Common members of all points & poses classes.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
CPose2D mean
The mean value.
TEstimationMethod estimationMethod
This fields indicates the way in which this estimation was obtained.
void drawSingleSample(mrpt::poses::CPose2D &outSample) const
Using this method instead of "poseChange->drawSingleSample()" may be more efficient in most situation...
void drawSingleSample_modelThrun(mrpt::poses::CPose2D &outSample) const
The sample generator for the model "computeFromOdometry_modelThrun", internally called when the user ...
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
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...
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
void computeFromOdometry(const mrpt::poses::CPose2D &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".
void computeFromOdometry_modelGaussian(const mrpt::poses::CPose2D &odometryIncrement, const TMotionModelOptions &o)
Computes the PDF of the pose increment from an odometry reading, using a Gaussian approximation as th...
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
void drawSingleSample_modelGaussian(mrpt::poses::CPose2D &outSample) const
The sample generator for the model "computeFromOdometry_modelGaussian", internally called when the us...
mrpt::poses::CPose2D m_fastDrawGauss_M
T square(const T x)
Inline function for the square of a number.
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
Represents a probabilistic 2D movement of the robot mobile base.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
TMotionModelOptions()
Default values loader.
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
std::shared_ptr< CPosePDF > Ptr
mrpt::math::CMatrixDouble33 m_fastDrawGauss_Z
Auxiliary matrix.
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
void fastDrawSingleSample(mrpt::poses::CPose2D &outSample) const
Faster version than "drawSingleSample", but requires a previous call to "prepareFastDrawSingleSamples...
double norm() const
Returns the euclidean norm of vector: .
mrpt::utils::poly_ptr_ptr< mrpt::poses::CPosePDF::Ptr > poseChange
The 2D pose change probabilistic estimation.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
float additional_std_XY
An additional noise added to the thrun model (std.
void computeFromOdometry_modelThrun(const mrpt::poses::CPose2D &odometryIncrement, const TMotionModelOptions &o)
Computes the PDF of the pose increment from an odometry reading, using the motion model from Thrun's ...
void fastDrawSingleSample_modelThrun(mrpt::poses::CPose2D &outSample) const
Internal use.
This namespace contains representation of robot actions and observations.
void computeFromEncoders(double K_left, double K_right, double D)
If "hasEncodersInfo"=true, this method updates the pose estimation according to the ticks from both e...
TEstimationMethod
A list of posible ways for estimating the content of a CActionRobotMovement2D object.
Declares a class that represents a Probability Density Function (PDF) over a 2D pose (x...
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
TDrawSampleMotionModel modelSelection
The model to be used.
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
void fastDrawSingleSample_modelGaussian(mrpt::poses::CPose2D &outSample) const
Internal use.
struct mrpt::obs::CActionRobotMovement2D::TMotionModelOptions::TOptions_GaussianModel gaussianModel
Declares a class for storing a robot action.
void prepareFastDrawSingleSamples() const
Call this before calling a high number of times "fastDrawSingleSample", which is much faster than "dr...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void prepareFastDrawSingleSample_modelGaussian() const
Internal use.
struct mrpt::obs::CActionRobotMovement2D::TMotionModelOptions::TOptions_ThrunModel thrunModel
void prepareFastDrawSingleSample_modelThrun() const
Internal use.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
void resetDeterministic(const CPose2D &location, size_t particlesCount=0)
Reset the PDF to a single point: All m_particles will be set exactly to the supplied pose...
const double & phi() const
Get the phi angle of the 2D pose (in radians)
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of t...
uint32_t nParticlesCount
The default number of particles to generate in a internal representation (anyway you can draw as many...
std::shared_ptr< T > make_aligned_shared(Args &&... args)
Creates a shared_ptr with 16-byte aligned memory.
Eigen::Matrix< typename MATRIX::Scalar, MATRIX::ColsAtCompileTime, MATRIX::ColsAtCompileTime > cov(const MATRIX &v)
Computes the covariance matrix from a list of samples in an NxM matrix, where each row is a sample...
unsigned __int32 uint32_t
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
struct mrpt::obs::CActionRobotMovement2D::TMotionModelOptions motionModelConfiguration
void normalizePhi()
Forces "phi" to be in the range [-pi,pi];.
CMatrixFixedNumeric< double, 3, 1 > CMatrixDouble31
mrpt::poses::CPose2D rawOdometryIncrementReading
This is the raw odometry reading, and only is used when "estimationMethod" is "TEstimationMethod::emO...
double drawGaussian1D_normalized()
Generate a normalized (mean=0, std=1) normally distributed sample.