Main MRPT website > C++ reference
MRPT logo
CLocalMetricHypothesis.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2014, 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 #ifndef CLocalMetricHypothesis_H
10 #define CLocalMetricHypothesis_H
11 
14 
17 
21 
22 #include <list>
23 
24 namespace mrpt
25 {
26  namespace opengl
27  {
28  struct CSetOfObjectsPtr;
29  }
30  namespace poses
31  {
32  class CPose3DPDFParticles;
33  }
34 
35  namespace hmtslam
36  {
37  using namespace mrpt::slam;
38 
41 
44 
45  /** Auxiliary class used in mrpt::slam::CLocalMetricHypothesis for HMT-SLAM; this class keeps the data relative to each local metric particle ("a robot metric path hypothesis" and its associated metric map).
46  * \ingroup mrpt_hmtslam_grp
47  */
48  class HMTSLAM_IMPEXP CLSLAMParticleData : public mrpt::utils::CSerializable
49  {
50  // This must be added to any CSerializable derived class:
52 
53  public:
54  CLSLAMParticleData( const TSetOfMetricMapInitializers *mapsInitializers = NULL ) :
55  metricMaps( mapsInitializers ),
56  robotPoses()
57  {
58  }
59 
61  {
62  robotPoses.clear();
63  }
64 
66  std::map<TPoseID,CPose3D> robotPoses;
67  };
69 
70 
71  /** This class is used in HMT-SLAM to represent each of the Local Metric Hypotheses (LMHs).
72  * It has a set of particles representing the robot path in nearby poses.
73  * \sa CHMTSLAM, CLSLAM_RBPF_2DLASER
74  */
77  public mrpt::bayes::CParticleFilterDataImpl<CLocalMetricHypothesis,mrpt::bayes::CParticleFilterData<CLSLAMParticleData>::CParticleList>,
78  public mrpt::utils::CSerializable
79  {
81 
82  // This must be added to any CSerializable derived class:
83  DEFINE_SERIALIZABLE( CLocalMetricHypothesis )
84 
85  public:
86  /** Constructor (Default param only used from STL classes)
87  */
88  CLocalMetricHypothesis( CHMTSLAM * parent = NULL );
89 
90  /** Destructor
91  */
92  ~CLocalMetricHypothesis();
93 
94  synch::CCriticalSection m_lock; //!< Critical section for threads signaling they are working with the LMH.
95  THypothesisID m_ID; //!< The unique ID of the hypothesis (Used for accessing mrpt::slam::CHierarchicalMHMap).
96  safe_ptr<CHMTSLAM> m_parent; //!< For quick access to our parent object.
97  TPoseID m_currentRobotPose; //!< The current robot pose (its global unique ID) for this hypothesis.
98  //TNodeIDList m_neighbors; //!< The list of all areas sourronding the current one (this includes the current area itself).
99  TNodeIDSet m_neighbors; //!< The list of all areas sourronding the current one (this includes the current area itself).
100  std::map<TPoseID,CHMHMapNode::TNodeID> m_nodeIDmemberships; //!< The hybrid map node membership for each robot pose.
101  std::map<TPoseID,CSensoryFrame> m_SFs; //!< The SF gathered at each robot pose.
102  TPoseIDList m_posesPendingAddPartitioner; //!< The list of poseIDs waiting to be added to the graph partitioner, what happens in the LSLAM thread main loop.
103  TNodeIDList m_areasPendingTBI; //!< The list of area IDs waiting to be processed by the TBI (topological bayesian inference) engines to search for potential loop-closures. Set in CHMTSLAM::LSLAM_process_message_from_AA, read in
104 
105  double m_log_w; //!< Log-weight of this hypothesis.
106  std::vector<std::map<TPoseID,double> > m_log_w_metric_history; //!< The historic log-weights of the metric observations inserted in this LMH, for each particle.
107  //std::map<TPoseID,double> m_log_w_topol_history; //!< The historic log-weights of the topological observations inserted in this LMH.
108 
109  CActionRobotMovement2D m_accumRobotMovement; //!< Used in CLSLAM_RBPF_2DLASER
110  bool m_accumRobotMovementIsValid; //!< Used in CLSLAM_RBPF_2DLASER
111 
112  /** Used by AA thread */
114  {
115  synch::CCriticalSection lock; //!< CS to access the entire struct.
117  std::map<uint32_t,TPoseID> idx2pose; //!< For the poses in "partitioner".
118 
119  unsigned int pose2idx(const TPoseID &id) const; //!< Uses idx2pose to perform inverse searches.
120 
121  } m_robotPosesGraph;
122 
123  /** Returns a 3D representation of the the current robot pose, all the poses in the auxiliary graph, and each of the areas they belong to.
124  * The metric maps are *not* included here for convenience, call m_metricMaps.getAs3DScene().
125  * The previous contents of "objs" will be discarded
126  */
127  void getAs3DScene( mrpt::opengl::CSetOfObjectsPtr &objs ) const;
128 
129  /** Returns the mean of each robot pose in this LMH, as computed from the set of particles.
130  * \sa getPathParticles, getRelativePose
131  */
132  void getMeans( std::map< TPoseID, CPose3D > &outList ) const;
133 
134  /** Returns the mean and covariance of each robot pose in this LMH, as computed from the set of particles.
135  * \sa getMeans, getPoseParticles
136  */
137  void getPathParticles( std::map< TPoseID, CPose3DPDFParticles > &outList ) const;
138 
139  /** Returns the mean and covariance of each robot pose in this LMH, as computed from the set of particles.
140  * \sa getMeans, getPathParticles
141  */
142  void getPoseParticles( const TPoseID &poseID, CPose3DPDFParticles &outPDF ) const;
143 
144  /** Returns the pose PDF of some pose relative to some other pose ID (both must be part of the the LMH).
145  * \sa getMeans, getPoseParticles
146  */
147  void getRelativePose(
148  const TPoseID &reference,
149  const TPoseID &pose,
150  CPose3DPDFParticles &outPDF ) const;
151 
152  /** Describes the LMH in text.
153  */
154  void dumpAsText(utils::CStringList &st) const;
155 
156  /** Change all coordinates to set a given robot pose as the new coordinate origin, and rebuild metric maps and change coords in the partitioning subsystem as well.
157  */
158  void changeCoordinateOrigin( const TPoseID &newOrigin );
159 
160  /** Rebuild the metric maps of all particles from the observations and their estimated poses. */
161  void rebuildMetricMaps();
162 
163  /** Rebuild the auxiliary metric maps in "m_robotPosesGraph" from the observations "m_SFs" and their estimated poses. */
164  //void rebuildSSOMatrix();
165 
166  /** Sets the number of particles to the initial number according to the PF options, and initialize them with no robot poses & empty metric maps.
167  */
168  void clearRobotPoses();
169 
170  /** Returns the i'th particle hypothesis for the current robot pose. */
171  const CPose3D * getCurrentPose(const size_t &particleIdx) const;
172 
173  /** Returns the i'th particle hypothesis for the current robot pose. */
174  CPose3D * getCurrentPose(const size_t &particleIdx);
175 
176  /** Removes a given area from the LMH:
177  * - The corresponding node in the HMT map is updated with the robot poses & SFs in the LMH.
178  * - Robot poses belonging to that area are removed from:
179  * - the particles.
180  * - the graph partitioner.
181  * - the list of SFs.
182  * - the list m_nodeIDmemberships.
183  * - m_neighbors is updated.
184  * - The weights of all particles are changed to remove the effects of the removed metric observations.
185  * - After calling this the metric maps should be updated.
186  * - This method internally calls updateAreaFromLMH
187  */
188  void removeAreaFromLMH( const CHMHMapNode::TNodeID areaID );
189 
190  /** The corresponding node in the HMT map is updated with the robot poses & SFs in the LMH: the poses are referenced to the area's reference poseID, such as that reference is at the origin.
191  * If eraseSFsFromLMH=true, the sensoryframes are moved rather than copied to the area, and removed from the LMH.
192  * \note The critical section m_map_cs is locked internally, unlock it before calling this.
193  */
194  void updateAreaFromLMH(
195  const CHMHMapNode::TNodeID areaID,
196  bool eraseSFsFromLMH = false );
197 
198 
199  protected:
200 
201  /** @name Virtual methods for Particle Filter implementation (just a wrapper interface, actually implemented in CHMTSLAM::m_LSLAM_method)
202  @{
203  */
204 
205  /** The PF algorithm implementation.
206  */
207  void prediction_and_update_pfAuxiliaryPFOptimal(
208  const mrpt::slam::CActionCollection * action,
209  const mrpt::slam::CSensoryFrame * observation,
211 
212  /** The PF algorithm implementation. */
213  void prediction_and_update_pfOptimalProposal(
214  const mrpt::slam::CActionCollection * action,
215  const mrpt::slam::CSensoryFrame * observation,
217  /** @}
218  */
219 
220 
221  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
222  */
223  mutable CVectorDouble m_pfAuxiliaryPFOptimal_estimatedProb;
224 
225  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
226  */
227  mutable std::vector<double> m_maxLikelihood;
228 
229  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
230  */
231  mutable std::vector<CPose2D,Eigen::aligned_allocator<CPose2D> > m_movementDraws;
232 
233  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
234  */
235  mutable unsigned int m_movementDrawsIdx;
236 
237  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
238  */
239  mutable StdVector_CPose2D m_movementDrawMaximumLikelihood;
240 
241  }; // End of class def.
243 
244  } // End of namespace
245 } // End of namespace
246 
247 #endif
#define HMTSLAM_IMPEXP
This class provides simple critical sections functionality.
Implements a 2D local SLAM method based on a RBPF over an occupancy grid map.
Definition: CHMTSLAM.h:530
This class stores any customizable set of metric maps.
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:35
uint64_t TNodeID
The type for node IDs in graphs of different types.
Definition: types_simple.h:39
STL namespace.
uint64_t TPoseID
An integer number uniquely identifying each robot pose stored in HMT-SLAM.
An implementation of Hybrid Metric Topological SLAM (HMT-SLAM).
Definition: CHMTSLAM.h:66
This namespace contains algorithms for SLAM, localization, map building, representation of robot's ac...
std::map< TPoseID, CPose3D > robotPoses
Declares a class for storing a collection of robot actions.
int64_t THypothesisID
An integer number uniquely identifying each of the concurrent hypotheses for the robot topological pa...
A class for storing a list of text lines.
Definition: CStringList.h:32
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
This class is used in HMT-SLAM to represent each of the Local Metric Hypotheses (LMHs).
This template class declares the array of particles and its internal data, managing some memory-relat...
std::map< uint32_t, TPoseID > idx2pose
For the poses in "partitioner".
std::vector< TPoseID > TPoseIDList
Auxiliary class used in mrpt::slam::CLocalMetricHypothesis for HMT-SLAM; this class keeps the data re...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Represents a probabilistic 2D movement of the robot mobile base.
This class can be used to make partitions on a map/graph build from observations taken at some poses/...
std::deque< CParticleData > CParticleList
Use this type to refer to the list of particles m_particles.
A set of TMetricMapInitializer structures, passed to the constructor CMultiMetricMap::CMultiMetricMap...
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:53
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
The configuration of a particle filter.
std::set< CHMHMapNode::TNodeID > TNodeIDSet
Definition: CHMHMapNode.h:152
dynamic_vector< double > CVectorDouble
Column vector, like Eigen::MatrixXd, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:53
synch::CCriticalSection lock
CS to access the entire struct.
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
A class for representing a node in a hierarchical, multi-hypothesis map.
Definition: CHMHMapNode.h:39
mrpt::aligned_containers< CPose2D >::vector_t StdVector_CPose2D
Eigen aligment-compatible container.
Definition: CPose2D.h:265
A wrapper class for pointers that can be safely copied with "=" operator without problems.
Definition: safe_pointers.h:67
Declares a class that represents a Probability Density function (PDF) of a 3D pose.
A curiously recurring template pattern (CRTP) approach to providing the basic functionality of any CP...
mrpt::utils::TNodeID TNodeID
The type of the IDs of nodes.
Definition: CHMHMapNode.h:51



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014