48 m_log_w_metric_history()
52 m_accumRobotMovementIsValid =
false;
59 CLocalMetricHypothesis::~CLocalMetricHypothesis()
71 void CLocalMetricHypothesis::getAs3DScene( opengl::CSetOfObjectsPtr &objs )
const
80 obj->setColor(0.4,0.4,0.4);
89 std::map< TPoseID, CPose3DPDFParticles > lstPoses;
91 getPathParticles( lstPoses );
101 const CHMHMapNodePtr node = m_parent->m_map.getNodeByID( *
n );
107 lstPoses[ poseID_origin ].getMean(originPose);
110 corner->setPose(originPose);
111 objs->insert( corner );
118 const CPose3D meanCurPose = lstPoses[ m_currentRobotPose ].getMeanVal();
121 cam->setZoomDistance(85);
122 cam->setAzimuthDegrees(45 +
RAD2DEG(meanCurPose.
yaw()));
123 cam->setElevationDegrees(45);
124 cam->setPointingAt(meanCurPose);
130 map<CHMHMapNode::TNodeID,CPoint3D> areas_mean;
131 map<CHMHMapNode::TNodeID,int> areas_howmany;
133 for (it=lstPoses.begin(); it!=lstPoses.end();it++)
137 if ( m_nodeIDmemberships.find(it->first)->second == m_nodeIDmemberships.find(m_currentRobotPose)->second )
138 ellip->setColor(0,0,1);
140 ellip->setColor(1,0,0);
147 ellip->setLocation(pdf.
mean.
x(), pdf.
mean.
y(), pdf.
mean.z()+0.005);
157 ellip->setCovMatrix(C);
159 ellip->enableDrawSolid3D(
false);
162 ellip->setName(
format(
"P%u", (
unsigned int) it->first ) );
163 ellip->enableShowName();
166 objs->insert( ellip );
174 obj->setColor(1,0,0);
182 if (it->first == m_currentRobotPose )
186 robot->setPose(pdf.
mean);
189 objs->insert( robot );
195 ASSERT_( itAreaId != m_nodeIDmemberships.end() );
197 areas_howmany[ areaId ]++;
198 areas_mean[ areaId ].x_incr( pdf.
mean.
x() );
199 areas_mean[ areaId ].y_incr( pdf.
mean.
y() );
200 areas_mean[ areaId ].z_incr( pdf.
mean.z() );
207 ASSERT_( areas_howmany.size() == areas_mean.size() );
208 for ( itMeans = areas_mean.begin(), itHowMany = areas_howmany.begin(); itMeans!=areas_mean.end(); itMeans++, itHowMany++ )
210 ASSERT_( itHowMany->second >0);
212 float f = 1.0f / itHowMany->second;
213 itMeans->second *= f;
220 for (it=lstPoses.begin(); it!=lstPoses.end();it++)
222 if (it->first != m_currentRobotPose )
224 CPoint3D areaPnt( areas_mean[ m_nodeIDmemberships.find( it->first )->second ] );
225 areaPnt.z_incr( m_parent->m_options.VIEW3D_AREA_SPHERES_HEIGHT );
232 line->setColor(0.8,0.8,0.8, 0.3);
233 line->setLineWidth(2);
237 areaPnt.
x(), areaPnt.
y(), areaPnt.z() );
238 objs->insert( line );
289 for ( itMeans = areas_mean.begin(); itMeans!=areas_mean.end(); itMeans++ )
293 if (itMeans->first == m_nodeIDmemberships.find( m_currentRobotPose)->second )
295 sphere->setColor(0.1,0.1,0.7);
299 sphere->setColor(0.7,0,0);
302 sphere->setLocation(itMeans->second.x(), itMeans->second.y(), itMeans->second.z() + m_parent->m_options.VIEW3D_AREA_SPHERES_HEIGHT);
304 sphere->setRadius( m_parent->m_options.VIEW3D_AREA_SPHERES_RADIUS );
307 objs->insert( sphere );
311 txt->setColor(1,1,1);
313 const CHMHMapNodePtr node = m_parent->m_map.getNodeByID( itMeans->first );
316 txt->setLocation( itMeans->second.x(), itMeans->second.y(), itMeans->second.z() + m_parent->m_options.VIEW3D_AREA_SPHERES_HEIGHT );
319 txt->setString(
format(
"%li",(
long int)node->getID()) );
331 for ( itMeans = areas_mean.begin(); itMeans!=areas_mean.end(); itMeans++ )
334 const CHMHMapNodePtr srcArea = m_parent->m_map.getNodeByID( srcAreaID );
338 srcArea->getArcs(lstArcs);
342 if ( (*a)->getNodeFrom() == srcAreaID )
345 if ( trgAreaPoseIt != areas_mean.end() )
349 line->setColor(0.8,0.8,0);
350 line->setLineWidth(3);
353 areas_mean[srcAreaID].
x(), areas_mean[srcAreaID].
y(), areas_mean[srcAreaID].
z() + m_parent->m_options.VIEW3D_AREA_SPHERES_HEIGHT,
354 trgAreaPoseIt->second.x(), trgAreaPoseIt->second.y(), trgAreaPoseIt->second.z() + m_parent->m_options.VIEW3D_AREA_SPHERES_HEIGHT );
356 objs->insert( line );
368 void CLocalMetricHypothesis::prediction_and_update_pfAuxiliaryPFOptimal(
374 ASSERT_(m_parent->m_LSLAM_method);
375 m_parent->m_LSLAM_method->prediction_and_update_pfAuxiliaryPFOptimal(
this, action, observation,PF_options);
378 void CLocalMetricHypothesis::prediction_and_update_pfOptimalProposal(
384 ASSERT_(m_parent->m_LSLAM_method);
385 m_parent->m_LSLAM_method->prediction_and_update_pfOptimalProposal(
this, action, observation,PF_options);
401 std::map< TPoseID, CPose3DPDFParticles > parts;
402 getPathParticles( parts );
406 for (it=parts.begin();it!=parts.end();it++)
407 it->second.getMean( outList[ it->first ] );
416 void CLocalMetricHypothesis::getPathParticles( std::map< TPoseID, CPose3DPDFParticles > &outList )
const
422 if (m_particles.empty())
return;
430 for ( it = m_particles.begin(), itP = auxPDF.
m_particles.begin(); it!=m_particles.end(); it++, itP++ )
432 itP->log_w = it->log_w;
433 *itP->d = it->d->robotPoses.find( itPoseID->first )->second;
437 outList[ itPoseID->first ] = auxPDF;
456 for ( it = m_particles.begin(), itP = outPDF.
m_particles.begin(); it!=m_particles.end(); it++, itP++ )
458 itP->log_w = it->log_w;
460 ASSERT_( itPose!=it->d->robotPoses.end() );
461 *itP->d = itPose->second;
471 void CLocalMetricHypothesis::clearRobotPoses()
474 m_particles.resize( m_parent->m_options.pf_options.sampleSize );
482 it->d->robotPoses.clear();
489 const CPose3D * CLocalMetricHypothesis::getCurrentPose(
const size_t &particleIdx)
const
491 if (particleIdx>=m_particles.size())
THROW_EXCEPTION(
"Particle index out of bounds!");
494 ASSERT_( it!=m_particles[particleIdx].d->robotPoses.end() );
501 CPose3D * CLocalMetricHypothesis::getCurrentPose(
const size_t &particleIdx)
503 if (particleIdx>=m_particles.size())
THROW_EXCEPTION(
"Particle index out of bounds!");
506 ASSERT_( it!=m_particles[particleIdx].d->robotPoses.end() );
513 void CLocalMetricHypothesis::getRelativePose(
525 for ( it = m_particles.begin(), itP = outPDF.
m_particles.begin(); it!=m_particles.end(); it++, itP++ )
527 itP->log_w = it->log_w;
532 ASSERT_( srcPose != it->d->robotPoses.end() )
533 ASSERT_( trgPose != it->d->robotPoses.end() )
535 *itP->d = trgPose->second - srcPose->second;
544 void CLocalMetricHypothesis::changeCoordinateOrigin(
const TPoseID &newOrigin )
551 for ( it = m_particles.begin(), itOrgPDF=originPDF.
m_particles.begin(); it!=m_particles.end(); it++, itOrgPDF++ )
554 ASSERT_( refPoseIt != it->d->robotPoses.end() )
555 const CPose3D &refPose = refPoseIt->second;
558 *itOrgPDF->d = refPose;
559 itOrgPDF->log_w = it->log_w;
565 itP->second = itP->second - refPose;
578 CSimpleMap *SFseq = m_robotPosesGraph.partitioner.getSequenceOfFrames();
583 SFseq->
get( it->first, pdf, sf);
587 CPose3DPDFParticlesPtr pdfParts = CPose3DPDFParticlesPtr(pdf);
588 getPoseParticles( it->second, *pdfParts);
596 void CLocalMetricHypothesis::rebuildMetricMaps()
600 it->d->metricMaps.clear();
606 if ( itP->first != m_currentRobotPose )
610 SFit->second.insertObservationsInto( &it->d->metricMaps, &itP->second );
634 if (itNeig!=m_neighbors.end() )
635 m_neighbors.erase(itNeig);
641 if ( it->second==areaID )
642 lstPoseIDs.
insert(it->first);
644 ASSERT_( !lstPoseIDs.empty() );
650 updateAreaFromLMH( areaID,
true );
657 p->d->robotPoses.erase(
p->d->robotPoses.find( *it ) );
664 ASSERT_( m_log_w_metric_history.size() == m_particles.size() );
666 for ( ws_it=m_log_w_metric_history.begin(),
p = m_particles.begin();
667 p!=m_particles.end();
673 if (itW!=ws_it->end())
677 p->log_w -= itW->second;
692 indexesToRemove.reserve( lstPoseIDs.size() );
696 if (lstPoseIDs.
find(it->second)!=lstPoseIDs.end())
698 indexesToRemove.push_back( it->first );
703 m_robotPosesGraph.idx2pose.erase( it );
709 m_robotPosesGraph.partitioner.removeSetOfNodes(indexesToRemove);
713 map<uint32_t,TPoseID> newList;
715 newList[idx] = i->second;
716 m_robotPosesGraph.idx2pose = newList;
729 m_nodeIDmemberships.erase( m_nodeIDmemberships.find( *it ) );
732 double out_max_log_w ;
733 normalizeWeights( &out_max_log_w );
741 unsigned int CLocalMetricHypothesis::TRobotPosesPartitioning::pose2idx(
const TPoseID &
id)
const
744 if (it->second ==
id)
755 void CLocalMetricHypothesis::updateAreaFromLMH(
757 bool eraseSFsFromLMH )
763 if ( it->second==areaID )
764 lstPoseIDs.
insert(it->first);
766 ASSERT_( !lstPoseIDs.empty() );
771 node = m_parent->m_map.getNodeByID( areaID );
773 ASSERT_(node->m_hypotheses.has( m_ID ));
783 CRobotPosesGraphPtr posesGraph;
789 posesGraph = CRobotPosesGraph::Create();
794 posesGraph = CRobotPosesGraphPtr(annot);
801 bool pdfOrigin_ok=
false;
804 TPoseInfo &poseInfo = (*posesGraph)[*it];
805 getPoseParticles( *it, poseInfo.
pdf );
808 if (*it==poseID_origin)
814 if ( *it != m_currentRobotPose )
826 poseInfo.
sf = itSF->second;
834 pdfOrigin.
inverse(pdfOriginInv);
838 ASSERT_( it->second.pdf.size() == pdfOriginInv.
size() );
839 for ( pdfIt=it->second.pdf.m_particles.begin(), orgIt= pdfOriginInv.
m_particles.begin();orgIt!=pdfOriginInv.
m_particles.end();orgIt++,pdfIt++)
840 *pdfIt->d = *orgIt->d + *pdfIt->d;
848 posesGraph->insertIntoMetricMap( *metricMap );
858 st <<
"LIST OF POSES IN LMH";
859 st <<
"====================";
874 string s =
format(
" ID: %i \t AREA: %i \t %.03f,%.03f,%.03fdeg",
877 it->second.x(),it->second.y(),
RAD2DEG(it->second.yaw()) );
892 in >> m_ID >> m_currentRobotPose
894 >> m_nodeIDmemberships
896 >> m_posesPendingAddPartitioner
899 >> m_log_w_metric_history
900 >> m_robotPosesGraph.partitioner
901 >> m_robotPosesGraph.idx2pose;
904 readParticlesFromStream(
in);
922 out << m_ID << m_currentRobotPose
924 << m_nodeIDmemberships
926 << m_posesPendingAddPartitioner
929 << m_log_w_metric_history
930 << m_robotPosesGraph.partitioner
931 << m_robotPosesGraph.idx2pose;
934 writeParticlesToStream(out);
948 in >> metricMaps >> robotPoses;
966 out << metricMaps << robotPoses;
#define CLASS_ID(class_name)
Access to runtime class ID for a defined class name.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
#define NODE_ANNOTATION_METRIC_MAPS
#define NODE_ANNOTATION_REF_POSEID
#define NODE_ANNOTATION_POSES_GRAPH
CParticleList m_particles
The array of particles.
mrpt::utils::TNodeID TNodeID
The type of the IDs of nodes.
An implementation of Hybrid Metric Topological SLAM (HMT-SLAM).
Auxiliary class used in mrpt::slam::CLocalMetricHypothesis for HMT-SLAM; this class keeps the data re...
This class is used in HMT-SLAM to represent each of the Local Metric Hypotheses (LMHs).
A class for storing a sequence of arcs (a path).
void clear()
Erase all the contents of the map.
This class stores any customizable set of metric maps.
This class stores a sequence of <Probabilistic Pose,SensoryFrame> pairs, thus a "metric map" can be t...
void get(size_t index, mrpt::poses::CPose3DPDFPtr &out_posePDF, mrpt::obs::CSensoryFramePtr &out_SF) const
Access to the i'th pair, first one is index '0'.
Declares a class for storing a collection of robot actions.
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
void moveFrom(CSensoryFrame &sf)
Copies all the observation from another object, then erase them from the origin object (this method i...
static CArrowPtr Create()
static CCameraPtr Create()
static CEllipsoidPtr Create()
static CGridPlaneXYPtr Create()
static CSimpleLinePtr Create()
static CSpherePtr Create()
A class used to store a 3D point.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
double pitch() const
Get the PITCH angle (in radians)
double roll() const
Get the ROLL angle (in radians)
void setFromValues(const double x0, const double y0, const double z0, const double yaw=0, const double pitch=0, const double roll=0)
Set the pose from a 3D position (meters) and yaw/pitch/roll angles (radians) - This method recomputes...
double yaw() const
Get the YAW angle (in radians)
Declares a class that represents a Probability Density function (PDF) of a 3D pose .
CPose3D mean
The mean value.
void copyFrom(const CPose3DPDF &o) MRPT_OVERRIDE
Copy operator, translating if necesary (for example, between particles and gaussian representations)
mrpt::math::CMatrixDouble66 cov
The 6x6 covariance matrix.
Declares a class that represents a Probability Density function (PDF) of a 3D pose.
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.
void inverse(CPose3DPDF &o) const MRPT_OVERRIDE
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
size_t size() const
Get the m_particles count (equivalent to "particlesCount")
void copyFrom(const CPose3DPDF &o) MRPT_OVERRIDE
Copy operator, translating if necesary (for example, between m_particles and gaussian representations...
double x() const
Common members of all points & poses classes.
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
The virtual base class which provides a unified interface for all persistent objects in MRPT.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
A class for storing a list of text lines.
void clear()
Clear the whole list.
std::list< T >::iterator find(const T &i)
const Scalar * const_iterator
GLsizei GLsizei GLuint * obj
GLubyte GLubyte GLubyte a
std::vector< uint32_t > vector_uint
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define THROW_EXCEPTION(msg)
#define MRPT_CHECK_NORMAL_NUMBER(val)
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Classes related to the implementation of Hybrid Metric Topological (HMT) SLAM.
mrpt::aligned_containers< TPoseID, mrpt::poses::CPose3D >::map_t TMapPoseID2Pose3D
uint64_t TPoseID
An integer number uniquely identifying each robot pose stored in HMT-SLAM.
This base provides a set of functions for maths stuff.
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
This namespace contains representation of robot actions and observations.
CSetOfObjectsPtr OPENGL_IMPEXP RobotPioneer()
Returns a representation of a Pioneer II mobile base.
CSetOfObjectsPtr OPENGL_IMPEXP CornerXYZ(float scale=1.0)
Returns three arrows representing a X,Y,Z 3D corner.
The namespace for 3D scene representation and rendering.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
mrpt::maps::CMultiMetricMapPtr CMultiMetricMapPtr
Backward compatible typedef.
This namespace provides multitask, synchronization utilities.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
The configuration of a particle filter.
Information kept for each robot pose used in CRobotPosesGraph.
mrpt::obs::CSensoryFrame sf
The observations.
mrpt::poses::CPose3DPDFParticles pdf
The robot pose PDF.