23 #include <Eigen/Dense> 40 out << i << j << m_locationMC << m_locationGauss << m_locationSOG;
50 in >> i >> j >> m_locationMC >> m_locationGauss >> m_locationSOG;
52 m_typePDF =
static_cast<TTypePDF>(j);
69 m_locationMC.getMean(
p);
72 m_locationGauss.getMean(
p);
75 m_locationSOG.getMean(
p);
89 return m_locationMC.getCovarianceAndMean();
91 return m_locationGauss.getCovarianceAndMean();
93 return m_locationSOG.getCovarianceAndMean();
105 const double minMahalanobisDistToDrop)
111 m_locationMC.bayesianFusion(p1, p2, minMahalanobisDistToDrop);
114 m_locationGauss.bayesianFusion(p1, p2, minMahalanobisDistToDrop);
117 m_locationSOG.bayesianFusion(p1, p2, minMahalanobisDistToDrop);
134 m_locationMC.drawSingleSample(outSample);
137 m_locationGauss.drawSingleSample(outSample);
140 m_locationSOG.drawSingleSample(outSample);
157 m_locationMC.copyFrom(o);
160 m_locationGauss.copyFrom(o);
163 m_locationSOG.copyFrom(o);
180 return m_locationMC.saveToTextFile(file);
183 return m_locationGauss.saveToTextFile(file);
186 return m_locationSOG.saveToTextFile(file);
203 m_locationMC.changeCoordinatesReference(newReferenceBase);
206 m_locationGauss.changeCoordinatesReference(newReferenceBase);
209 m_locationSOG.changeCoordinatesReference(newReferenceBase);
229 std::make_shared<opengl::CPointCloud>();
230 obj->setColor(1, 0, 0);
232 obj->setPointSize(2.5);
234 const size_t N = m_locationMC.m_particles.size();
237 for (
size_t i = 0; i < N; i++)
239 i, m_locationMC.m_particles[i].d->x,
240 m_locationMC.m_particles[i].d->y,
241 m_locationMC.m_particles[i].d->z);
249 std::make_shared<opengl::CEllipsoid>();
251 obj->setPose(m_locationGauss.mean);
252 obj->setLineWidth(3);
255 if (C(2, 2) == 0) C.
setSize(2, 2);
256 obj->setCovMatrix(C);
258 obj->setQuantiles(3);
259 obj->enableDrawSolid3D(
false);
261 obj->setColor(1, 0, 0, 0.85);
267 m_locationSOG.getAs3DObject(outObj);
275 obj2->setString(
format(
"#%d", static_cast<int>(m_ID)));
278 this->getMean(meanP);
279 obj2->setLocation(meanP.
x() + 0.10, meanP.
y() + 0.10, meanP.z());
280 outObj->insert(obj2);
302 size_t i, N = m_locationMC.m_particles.size();
307 for (i = 0; i < N; i++)
310 auxStr,
sizeof(auxStr),
"%.3f%c",
311 m_locationMC.m_particles[i].d->x, (i == N - 1) ?
' ' :
',');
314 auxStr,
sizeof(auxStr),
"%.3f%c",
315 m_locationMC.m_particles[i].d->y, (i == N - 1) ?
' ' :
',');
320 out_Str.emplace_back(sx);
321 out_Str.emplace_back(sy);
322 out_Str.emplace_back(
"plot(xs,ys,'k.','MarkerSize',4);");
332 auxStr,
sizeof(auxStr),
"m=[%.3f %.3f];",
333 m_locationGauss.mean.x(), m_locationGauss.mean.y());
334 out_Str.emplace_back(auxStr);
336 auxStr,
sizeof(auxStr),
"C=[%e %e;%e %e];",
337 m_locationGauss.cov(0, 0), m_locationGauss.cov(0, 1),
338 m_locationGauss.cov(1, 0), m_locationGauss.cov(1, 1));
339 out_Str.emplace_back(auxStr);
341 out_Str.emplace_back(
342 "error_ellipse(C,m,'conf',0.997,'style','k');");
347 for (
const auto& it : m_locationSOG)
350 auxStr,
sizeof(auxStr),
"m=[%.3f %.3f];", it.val.mean.x(),
352 out_Str.emplace_back(auxStr);
354 auxStr,
sizeof(auxStr),
"C=[%e %e;%e %e];",
355 it.val.cov(0, 0), it.val.cov(0, 1), it.val.cov(1, 0),
357 out_Str.emplace_back(auxStr);
358 out_Str.emplace_back(
359 "error_ellipse(C,m,'conf',0.997,'style','k');");
372 auxStr,
sizeof(auxStr),
"text(%f,%f,'#%i');", meanP.
x(), meanP.
y(),
373 static_cast<int>(m_ID));
374 out_Str.emplace_back(auxStr);
399 const CPoint3D& centerPoint,
const float& maxDistanceFromCenter)
const 405 if (m_typePDF == pdfGauss)
410 new_beaconPos->get(0).log_w = 0;
411 new_beaconPos->get(0).val = m_locationGauss;
412 beaconPos = new_beaconPos;
417 beaconPos =
static_cast<const CPointPDFSOG*
>(&m_locationSOG);
422 for (
const auto& beaconPo : *beaconPos)
426 beaconPo.val.mean.x() - sensorPntOnRobot.
x(),
427 beaconPo.val.mean.y() - sensorPntOnRobot.
y(),
428 beaconPo.val.mean.z() - sensorPntOnRobot.z());
430 size_t startIdx = outPDF.
size();
442 maxDistanceFromCenter
446 for (
size_t k = startIdx; k < outPDF.
size(); k++)
447 outPDF.
get(k).
log_w = beaconPo.log_w;
450 if (m_typePDF == pdfGauss)
delete beaconPos;
462 bool clearPreviousContentsOutPDF,
const CPoint3D& centerPoint,
463 const float& maxDistanceFromCenter)
476 double el, th, A_ang;
477 const float maxDistBetweenGaussians =
481 size_t B = (size_t)(
M_2PIf *
R / maxDistBetweenGaussians) + 1;
484 B = max(B, (
size_t)30);
496 S(1, 1) = S(2, 2) =
square(
505 if (clearPreviousContentsOutPDF)
514 modeIdx = outPDF.
size();
520 for (idxEl = 0; idxEl <= (1 + B / 2); idxEl++)
522 el = minEl + idxEl * A_ang;
523 if (el > (maxEl + 0.5 * A_ang))
continue;
527 if (fabs(cos(el)) < 1e-4)
532 for (idxTh = 0; idxTh < nThSteps; idxTh++)
537 dir.x((sensorPnt.
x() +
R * cos(th) * cos(el)));
538 dir.y((sensorPnt.
y() +
R * sin(th) * cos(el)));
539 dir.z((sensorPnt.z() +
R * sin(el)));
543 bool reallyCreateIt =
true;
544 if (maxDistanceFromCenter > 0)
546 dir.distanceTo(centerPoint) < maxDistanceFromCenter;
565 if (std::abs(minEl - maxEl) < 1e-6)
569 C33(0, 2) = C33(2, 0) = C33(1, 2) = C33(2, 1) = C33(2, 2) =
574 if (covarianceCompositionToAdd)
575 outPDF.
get(modeIdx).
val.
cov += *covarianceCompositionToAdd;
std::tuple< cov_mat_t, type_value > getCovarianceAndMean() const override
Returns an estimate of the pose covariance matrix (STATE_LENxSTATE_LEN cov matrix) and the mean...
#define THROW_EXCEPTION(msg)
void copyFrom(const mrpt::poses::CPointPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
void getAsMatlabDrawCommands(std::vector< std::string > &out_Str) const
Gets a set of MATLAB commands which draw the current state of the beacon:
CPoint3D mean
The mean value.
double DEG2RAD(const double x)
Degrees to radians.
void resize(const size_t N)
Resize the number of SOG modes.
void changeCoordinatesReference(const mrpt::poses::CPose3D &newReferenceBase) override
this = p (+) this.
Declares a class that represents a Probability Density function (PDF) of a 3D point ...
The struct for each mode:
void clear()
Clear all the gaussian modes.
This file implements miscelaneous matrix and matrix/vector operations, and internal functions in mrpt...
GLsizei GLsizei GLuint * obj
double maxElevation_deg
Minimum and maximum elevation angles (in degrees) for inserting new beacons at the first observation:...
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
T square(const T x)
Inline function for the square of a number.
#define ASSERT_(f)
Defines an assertion mechanism.
This base provides a set of functions for maths stuff.
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
float SOG_maxDistBetweenGaussians
A parameter for initializing 2D/3D SOGs.
This namespace contains representation of robot actions and observations.
A class for storing a map of 3D probabilistic beacons, using a Montecarlo, Gaussian, or Sum of Gaussians (SOG) representation (for range-only SLAM).
float SOG_separationConstant
Constant used to compute the std.
const TGaussianMode & get(size_t i) const
Access to individual beacons.
double x() const
Common members of all points & poses classes.
GLsizei const GLchar ** string
A class used to store a 3D point.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
bool saveToTextFile(const std::string &file) const override
Save PDF's particles to a text file.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
void bayesianFusion(const CPointPDF &p1, const CPointPDF &p2, const double minMahalanobisDistToDrop=0) override
Bayesian fusion of two point distributions (product of two distributions->new distribution), then save the result in this object (WARNING: See implementing classes to see classes that can and cannot be mixtured!)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
OPENGL_SETOFOBJECTSPTR getAs3DObject() const
Returns a 3D representation of this PDF.
double rangeStd
The standard deviation used for Beacon ranges likelihood (default=0.08m).
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
size_t size() const
Return the number of Gaussian modes.
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.
CMatrixDouble33 generateAxisBaseFromDirection(double dx, double dy, double dz)
Computes an axis base (a set of three 3D normal vectors) with the given vector being the first of the...
mrpt::maps::CBeaconMap::TLikelihoodOptions likelihoodOptions
double log_w
The log-weight.
void drawSingleSample(mrpt::poses::CPoint3D &outSample) const override
Draw a sample from the pdf.
static void generateRingSOG(const float &sensedRange, mrpt::poses::CPointPDFSOG &outPDF, const CBeaconMap *myBeaconMap, const mrpt::poses::CPoint3D &sensorPnt, const mrpt::math::CMatrixDouble33 *covarianceCompositionToAdd=nullptr, bool clearPreviousContentsOutPDF=true, const mrpt::poses::CPoint3D ¢erPoint=mrpt::poses::CPoint3D(0, 0, 0), const float &maxDistanceFromCenter=0)
This static method returns a SOG with ring-shape (or as a 3D sphere) that can be used to initialize a...
mrpt::maps::CBeaconMap::TInsertionOptions insertionOptions
unsigned __int32 uint32_t
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x...
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
The class for storing individual "beacon landmarks" under a variety of 3D position PDF distributions...
void generateObservationModelDistribution(const float &sensedRange, mrpt::poses::CPointPDFSOG &outPDF, const CBeaconMap *myBeaconMap, const mrpt::poses::CPoint3D &sensorPntOnRobot, const mrpt::poses::CPoint3D ¢erPoint=mrpt::poses::CPoint3D(0, 0, 0), const float &maxDistanceFromCenter=0) const
Compute the observation model p(z_t|x_t) for a given observation (range value), and return it as an a...
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
void getMean(mrpt::poses::CPoint3D &mean_point) const override
CMatrixDynamic< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
void multiply_HCHt(const MAT_H &H, const MAT_C &C, MAT_R &R, bool accumResultInOutput=false)
R = H * C * H^t.