20 #include <Eigen/Dense> 46 if (estimationMethod == emOdometry)
49 out << rawOdometryIncrementReading;
51 const auto& gm = motionModelConfiguration.gaussianModel;
56 out.
WriteAs<
float>(gm.minStdXY);
57 out.
WriteAs<
float>(gm.minStdPHI);
59 out << motionModelConfiguration.thrunModel.nParticlesCount
60 << motionModelConfiguration.thrunModel.alfa1_rot_rot
61 << motionModelConfiguration.thrunModel.alfa2_rot_trans
62 << motionModelConfiguration.thrunModel.alfa3_trans_trans
63 << motionModelConfiguration.thrunModel.alfa4_trans_rot
64 << motionModelConfiguration.thrunModel.additional_std_XY
65 << motionModelConfiguration.thrunModel.additional_std_phi;
75 if (hasVelocities) out << velocityLocal;
77 out << hasEncodersInfo;
79 out << encoderLeftTicks << encoderRightTicks;
104 if (estimationMethod == emOdometry)
107 in >> rawOdometryIncrementReading;
110 motionModelConfiguration.modelSelection =
113 auto& gm = motionModelConfiguration.gaussianModel;
114 gm.a1 =
in.ReadAs<
float>();
115 gm.a2 =
in.ReadAs<
float>();
116 gm.a3 =
in.ReadAs<
float>();
117 gm.a4 =
in.ReadAs<
float>();
118 gm.minStdXY =
in.ReadAs<
float>();
119 gm.minStdPHI =
in.ReadAs<
float>();
122 motionModelConfiguration.thrunModel.nParticlesCount = i;
123 in >> motionModelConfiguration.thrunModel.alfa1_rot_rot >>
124 motionModelConfiguration.thrunModel.alfa2_rot_trans >>
125 motionModelConfiguration.thrunModel.alfa3_trans_trans >>
126 motionModelConfiguration.thrunModel.alfa4_trans_rot;
131 motionModelConfiguration.thrunModel.additional_std_XY >>
132 motionModelConfiguration.thrunModel.additional_std_phi;
136 motionModelConfiguration.thrunModel.additional_std_XY =
137 motionModelConfiguration.thrunModel.additional_std_phi =
143 rawOdometryIncrementReading, motionModelConfiguration);
156 if (hasVelocities)
in >> velocityLocal;
160 float velocityLin, velocityAng;
161 in >> velocityLin >> velocityAng;
162 velocityLocal.vx = velocityLin;
163 velocityLocal.vy = .0f;
164 velocityLocal.omega = velocityAng;
166 in >> hasEncodersInfo;
167 if (version < 7 || hasEncodersInfo)
170 encoderLeftTicks = i;
172 encoderRightTicks = i;
176 encoderLeftTicks = 0;
177 encoderRightTicks = 0;
198 if (estimationMethod == emOdometry)
201 in >> rawOdometryIncrementReading;
204 motionModelConfiguration.modelSelection =
207 float dum1, dum2, dum3;
209 in >> dum1 >> dum2 >> dum3 >>
210 motionModelConfiguration.gaussianModel.minStdXY >>
211 motionModelConfiguration.gaussianModel.minStdPHI;
215 motionModelConfiguration.thrunModel.nParticlesCount = i;
216 in >> motionModelConfiguration.thrunModel.alfa1_rot_rot;
217 in >> motionModelConfiguration.thrunModel.alfa2_rot_trans >>
218 motionModelConfiguration.thrunModel.alfa3_trans_trans >>
219 motionModelConfiguration.thrunModel.alfa4_trans_rot;
223 rawOdometryIncrementReading, motionModelConfiguration);
235 float velocityLin, velocityAng;
236 in >> velocityLin >> velocityAng;
237 velocityLocal.vx = velocityLin;
238 velocityLocal.vy = .0f;
239 velocityLocal.omega = velocityAng;
241 in >> hasEncodersInfo;
244 encoderLeftTicks = i;
246 encoderRightTicks = i;
261 if (estimationMethod == emOdometry)
264 in >> rawOdometryIncrementReading;
270 in.ReadBuffer(&dummy,
sizeof(dummy));
276 rawOdometryIncrementReading, motionModelConfiguration);
288 float velocityLin, velocityAng;
289 in >> velocityLin >> velocityAng;
290 velocityLocal.vx = velocityLin;
291 velocityLocal.vy = .0f;
292 velocityLocal.omega = velocityAng;
294 in >> hasEncodersInfo;
296 encoderLeftTicks = i;
298 encoderRightTicks = i;
316 if (estimationMethod == emOdometry)
317 poseChange->getMean(rawOdometryIncrementReading);
319 rawOdometryIncrementReading =
CPose2D(0, 0, 0);
325 float velocityLin, velocityAng;
326 in >> velocityLin >> velocityAng;
327 velocityLocal.vx = velocityLin;
328 velocityLocal.vy = .0f;
329 velocityLocal.omega = velocityAng;
331 in >> hasEncodersInfo;
333 encoderLeftTicks = i;
335 encoderRightTicks = i;
340 hasVelocities = hasEncodersInfo =
false;
341 encoderLeftTicks = encoderRightTicks = 0;
355 double K_left,
double K_right,
double D)
360 0.5 * (K_right * encoderRightTicks + K_left * encoderLeftTicks);
362 (K_right * encoderRightTicks - K_left * encoderLeftTicks) / D;
367 const double R = As / Aphi;
369 y =
R * (1 - cos(Aphi));
378 computeFromOdometry(
CPose2D(
x,
y, Aphi), motionModelConfiguration);
389 estimationMethod = emOdometry;
390 rawOdometryIncrementReading = odometryIncrement;
391 motionModelConfiguration = options;
394 computeFromOdometry_modelGaussian(odometryIncrement, options);
396 computeFromOdometry_modelThrun(odometryIncrement, options);
407 poseChange = std::make_shared<CPosePDFGaussian>();
414 double Al = odometryIncrement.
norm();
430 double cos_Aphi_2 = cos(odometryIncrement.
phi() / 2);
431 double sin_Aphi_2 = sin(odometryIncrement.
phi() / 2);
433 H(0, 0) = H(1, 1) = cos_Aphi_2;
434 H(0, 1) = -(H(1, 0) = sin_Aphi_2);
439 J(0, 2) = -sin_Aphi_2 * ODO_INCR(0, 0) - cos_Aphi_2 * ODO_INCR(1, 0);
440 J(1, 2) = cos_Aphi_2 * ODO_INCR(0, 0) - sin_Aphi_2 * ODO_INCR(1, 0);
443 aux->mean = odometryIncrement;
459 poseChange = CPosePDFParticles::Create();
473 float Arot1 = (odometryIncrement.
y() != 0 || odometryIncrement.
x() != 0)
474 ? atan2(odometryIncrement.
y(), odometryIncrement.
x())
476 float Atrans = odometryIncrement.
norm();
497 aux->m_particles[i].d.x =
498 Atrans_draw * cos(Arot1_draw) +
499 motionModelConfiguration.thrunModel.additional_std_XY *
501 aux->m_particles[i].d.y =
502 Atrans_draw * sin(Arot1_draw) +
503 motionModelConfiguration.thrunModel.additional_std_XY *
505 aux->m_particles[i].d.phi =
506 Arot1_draw + Arot2_draw +
507 motionModelConfiguration.thrunModel.additional_std_phi *
509 aux->m_particles[i].d.normalizePhi();
520 if (estimationMethod == emOdometry)
522 if (motionModelConfiguration.modelSelection == mmGaussian)
523 drawSingleSample_modelGaussian(outSample);
525 drawSingleSample_modelThrun(outSample);
530 poseChange->drawSingleSample(outSample);
542 poseChange->drawSingleSample(outSample);
559 float Arot1 = (rawOdometryIncrementReading.y() != 0 ||
560 rawOdometryIncrementReading.x() != 0)
562 rawOdometryIncrementReading.y(),
563 rawOdometryIncrementReading.x())
565 float Atrans = rawOdometryIncrementReading.norm();
566 float Arot2 =
math::wrapToPi(rawOdometryIncrementReading.phi() - Arot1);
570 (motionModelConfiguration.thrunModel.alfa1_rot_rot * fabs(Arot1) +
571 motionModelConfiguration.thrunModel.alfa2_rot_trans * Atrans) *
575 (motionModelConfiguration.thrunModel.alfa3_trans_trans * Atrans +
576 motionModelConfiguration.thrunModel.alfa4_trans_rot *
577 (fabs(Arot1) + fabs(Arot2))) *
581 (motionModelConfiguration.thrunModel.alfa1_rot_rot * fabs(Arot2) +
582 motionModelConfiguration.thrunModel.alfa2_rot_trans * Atrans) *
587 Atrans_draw * cos(Arot1_draw) +
588 motionModelConfiguration.thrunModel.additional_std_XY *
591 Atrans_draw * sin(Arot1_draw) +
592 motionModelConfiguration.thrunModel.additional_std_XY *
595 Arot1_draw + Arot2_draw +
596 motionModelConfiguration.thrunModel.additional_std_phi *
608 if (estimationMethod == emOdometry)
610 if (motionModelConfiguration.modelSelection == mmGaussian)
611 prepareFastDrawSingleSample_modelGaussian();
613 prepareFastDrawSingleSample_modelThrun();
624 if (estimationMethod == emOdometry)
626 if (motionModelConfiguration.modelSelection == mmGaussian)
627 fastDrawSingleSample_modelGaussian(outSample);
629 fastDrawSingleSample_modelThrun(outSample);
634 poseChange->drawSingleSample(outSample);
651 m_fastDrawGauss_M = gPdf->mean;
658 std::vector<double> eigvals;
665 m_fastDrawGauss_Z = m_fastDrawGauss_Z * D;
681 for (
size_t i = 0; i < 3; i++)
684 for (
size_t d = 0; d < 3; d++)
685 rndVector[d] += (m_fastDrawGauss_Z(d, i) * rnd);
689 m_fastDrawGauss_M.x() + rndVector[0],
690 m_fastDrawGauss_M.y() + rndVector[1],
691 m_fastDrawGauss_M.phi() + rndVector[2]);
700 drawSingleSample_modelThrun(outSample);
A namespace of pseudo-random numbers generators of diferent distributions.
double minStdPHI
Additional uncertainty: [degrees].
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Template for column vectors of dynamic size, compatible with Eigen.
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)
To be added to all CSerializable-classes implementation files.
double a2
Ratio of uncertainty: [meter/degree].
double minStdXY
Additional uncertainty: [meters].
This file implements miscelaneous matrix and matrix/vector operations, and internal functions in mrpt...
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...
void WriteAs(const TYPE_FROM_ACTUAL &value)
double a4
Ratio of uncertainty: [degree/degree].
The parameter to be passed to "computeFromOdometry".
void resetDeterministic(const mrpt::math::TPose2D &location, size_t particlesCount=0)
Reset the PDF to a single point: All m_particles will be set exactly to the supplied pose...
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...
bool eig_symmetric(Derived &eVecs, std::vector< Scalar > &eVals, bool sorted=true) const
Read: eig()
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
void drawSingleSample_modelGaussian(mrpt::poses::CPose2D &outSample) const
The sample generator for the model "computeFromOdometry_modelGaussian", internally called when the us...
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
T square(const T x)
Inline function for the square of a number.
#define ASSERT_(f)
Defines an assertion mechanism.
Represents a probabilistic 2D movement of the robot mobile base.
This base provides a set of functions for maths stuff.
CMatrixFixed< double, 3, 1 > CMatrixDouble31
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...
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.
#define IS_CLASS(obj, class_name)
True if the given reference to object (derived from mrpt::rtti::CObject) is of the given class...
double a1
Ratio of uncertainty: [meter/meter].
double x() const
Common members of all points & poses classes.
Declares a class that represents a Probability Density Function (PDF) over a 2D pose (x...
CMatrixDouble cov(const MATRIX &v)
Computes the covariance matrix from a list of samples in an NxM matrix, where each row is a sample...
double norm() const
Returns the euclidean norm of vector: .
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.
void fastDrawSingleSample_modelGaussian(mrpt::poses::CPose2D &outSample) const
Internal use.
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.
Virtual base class for "archives": classes abstracting I/O streams.
void prepareFastDrawSingleSample_modelGaussian() const
Internal use.
TOptions_GaussianModel gaussianModel
void prepareFastDrawSingleSample_modelThrun() const
Internal use.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
TOptions_ThrunModel thrunModel
const double & phi() const
Get the phi angle of the 2D pose (in radians)
uint32_t nParticlesCount
The default number of particles to generate in a internal representation (anyway you can draw as many...
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
double a3
Ratio of uncertainty: [degree/meter].
unsigned __int32 uint32_t
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
void setDiagonal(const std::size_t N, const Scalar value)
Resize to NxN, set all entries to zero, except the main diagonal which is set to value ...
void normalizePhi()
Forces "phi" to be in the range [-pi,pi];.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
double drawGaussian1D_normalized()
Generate a normalized (mean=0, std=1) normally distributed sample.
void multiply_HCHt(const MAT_H &H, const MAT_C &C, MAT_R &R, bool accumResultInOutput=false)
R = H * C * H^t.