Main MRPT website > C++ reference for MRPT 1.9.9
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-2017, 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 
19 
20 #include <list>
21 
22 namespace mrpt
23 {
24 namespace bayes
25 {
26 class CParticleFilter;
27 }
28 namespace poses
29 {
30 class CPose3DPDFParticles;
31 }
32 
33 namespace hmtslam
34 {
37 
38 class CHMTSLAM;
40 
41 /** Auxiliary class used in mrpt::slam::CLocalMetricHypothesis for HMT-SLAM;
42  * this class keeps the data relative to each local metric particle ("a robot
43  * metric path hypothesis" and its associated metric map).
44  * \ingroup mrpt_hmtslam_grp
45  */
47 {
49 
50  public:
52  const mrpt::maps::TSetOfMetricMapInitializers* mapsInitializers =
53  nullptr)
54  : metricMaps(mapsInitializers), robotPoses()
55  {
56  }
57 
60 };
61 
63  : public mrpt::bayes::CParticleFilterData<CLSLAMParticleData>,
65  mrpt::bayes::CParticleFilterData<CLSLAMParticleData>,
66  mrpt::bayes::CParticleFilterData<CLSLAMParticleData>::CParticleList>
67 {
68 };
69 
70 /** This class is used in HMT-SLAM to represent each of the Local Metric
71  * Hypotheses (LMHs).
72  * It has a set of particles representing the robot path in nearby poses.
73  * \sa CHMTSLAM, CLSLAM_RBPF_2DLASER
74  */
76 {
77  friend class CLSLAM_RBPF_2DLASER;
78 
80 
81  public:
83  using CParticleList =
86  /** Constructor (Default param only used from STL classes)
87  */
88  CLocalMetricHypothesis(CHMTSLAM* parent = nullptr);
89 
90  /** Destructor
91  */
93 
95  "Separate the serializable class from this code, so we don't have to "
96  "worry about copying locks")
97  struct ThreadLocks
98  {
99  // Don't really copy mutexes
100  ThreadLocks() {}
101  ThreadLocks(const ThreadLocks&) {}
102  mutable std::mutex m_lock;
104  /** The unique ID of the hypothesis (Used for accessing
105  * mrpt::slam::CHierarchicalMHMap). */
107  /** For quick access to our parent object. */
109  /** The current robot pose (its global unique ID) for this hypothesis. */
111  // TNodeIDList m_neighbors; //!< The
112  // list of all areas sourronding
113  // the current one (this includes the current area itself).
114  /** The list of all areas sourronding the current one (this includes the
115  * current area itself). */
117  /** The hybrid map node membership for each robot pose. */
118  std::map<TPoseID, CHMHMapNode::TNodeID> m_nodeIDmemberships;
119  /** The SF gathered at each robot pose. */
120  std::map<TPoseID, mrpt::obs::CSensoryFrame> m_SFs;
121  /** The list of poseIDs waiting to be added to the graph partitioner, what
122  * happens in the LSLAM thread main loop. */
124  /** The list of area IDs waiting to be processed by the TBI (topological
125  * bayesian inference) engines to search for potential loop-closures. Set in
126  * CHMTSLAM::LSLAM_process_message_from_AA, read in */
128 
129  /** Log-weight of this hypothesis. */
130  double m_log_w;
131  /** The historic log-weights of the metric observations inserted in this
132  * LMH, for each particle. */
133  std::vector<std::map<TPoseID, double>> m_log_w_metric_history;
134  // std::map<TPoseID,double> m_log_w_topol_history; //!< The historic
135  // log-weights of the topological observations inserted in this LMH.
136 
137  /** Used in CLSLAM_RBPF_2DLASER */
139  /** Used in CLSLAM_RBPF_2DLASER */
141 
142  /** Used by AA thread */
144  {
148  {
149  }
150  /** CS to access the entire struct. */
151  mutable std::mutex lock;
153  /** For the poses in "partitioner". */
154  std::map<uint32_t, TPoseID> idx2pose;
155 
156  /** Uses idx2pose to perform inverse searches. */
157  unsigned int pose2idx(const TPoseID& id) const;
158 
160 
161  /** Returns a 3D representation of the the current robot pose, all the poses
162  * in the auxiliary graph, and each of the areas they belong to.
163  * The metric maps are *not* included here for convenience, call
164  * m_metricMaps.getAs3DScene().
165  * The previous contents of "objs" will be discarded
166  */
168 
169  /** Returns the mean of each robot pose in this LMH, as computed from the
170  * set of particles.
171  * \sa getPathParticles, getRelativePose
172  */
173  void getMeans(TMapPoseID2Pose3D& outList) const;
174 
175  /** Returns the mean and covariance of each robot pose in this LMH, as
176  * computed from the set of particles.
177  * \sa getMeans, getPoseParticles
178  */
179  void getPathParticles(
180  std::map<TPoseID, mrpt::poses::CPose3DPDFParticles>& outList) const;
181 
182  /** Returns the mean and covariance of each robot pose in this LMH, as
183  * computed from the set of particles.
184  * \sa getMeans, getPathParticles
185  */
186  void getPoseParticles(
187  const TPoseID& poseID, mrpt::poses::CPose3DPDFParticles& outPDF) const;
188 
189  /** Returns the pose PDF of some pose relative to some other pose ID (both
190  * must be part of the the LMH).
191  * \sa getMeans, getPoseParticles
192  */
193  void getRelativePose(
194  const TPoseID& reference, const TPoseID& pose,
195  mrpt::poses::CPose3DPDFParticles& outPDF) const;
196 
197  /** Describes the LMH in text.
198  */
199  void dumpAsText(utils::CStringList& st) const;
200 
201  /** Change all coordinates to set a given robot pose as the new coordinate
202  * origin, and rebuild metric maps and change coords in the partitioning
203  * subsystem as well.
204  */
205  void changeCoordinateOrigin(const TPoseID& newOrigin);
206 
207  /** Rebuild the metric maps of all particles from the observations and their
208  * estimated poses. */
209  void rebuildMetricMaps();
210 
211  /** Rebuild the auxiliary metric maps in "m_robotPosesGraph" from the
212  * observations "m_SFs" and their estimated poses. */
213  // void rebuildSSOMatrix();
214 
215  /** Sets the number of particles to the initial number according to the PF
216  * options, and initialize them with no robot poses & empty metric maps.
217  */
218  void clearRobotPoses();
219 
220  /** Returns the i'th particle hypothesis for the current robot pose. */
221  const mrpt::poses::CPose3D* getCurrentPose(const size_t& particleIdx) const;
222 
223  /** Returns the i'th particle hypothesis for the current robot pose. */
224  mrpt::poses::CPose3D* getCurrentPose(const size_t& particleIdx);
225 
226  /** Removes a given area from the LMH:
227  * - The corresponding node in the HMT map is updated with the robot poses
228  *& SFs in the LMH.
229  * - Robot poses belonging to that area are removed from:
230  * - the particles.
231  * - the graph partitioner.
232  * - the list of SFs.
233  * - the list m_nodeIDmemberships.
234  * - m_neighbors is updated.
235  * - The weights of all particles are changed to remove the effects of the
236  *removed metric observations.
237  * - After calling this the metric maps should be updated.
238  * - This method internally calls updateAreaFromLMH
239  */
240  void removeAreaFromLMH(const CHMHMapNode::TNodeID areaID);
241 
242  /** The corresponding node in the HMT map is updated with the robot poses &
243  * SFs in the LMH: the poses are referenced to the area's reference poseID,
244  * such as that reference is at the origin.
245  * If eraseSFsFromLMH=true, the sensoryframes are moved rather than copied
246  * to the area, and removed from the LMH.
247  * \note The critical section m_map_cs is locked internally, unlock it
248  * before calling this.
249  */
250  void updateAreaFromLMH(
251  const CHMHMapNode::TNodeID areaID, bool eraseSFsFromLMH = false);
252 
253  /** @name Virtual methods for Particle Filter implementation (just a wrapper
254  interface, actually implemented in CHMTSLAM::m_LSLAM_method)
255  @{
256  */
257 
258  /** The PF algorithm implementation.
259  */
260  template <class PF_ALGORITHM>
262  const mrpt::obs::CActionCollection* action,
263  const mrpt::obs::CSensoryFrame* observation,
265 
266  /** Auxiliary function used in "prediction_and_update_pfAuxiliaryPFOptimal"
267  */
270  size_t index, const mrpt::obs::CSensoryFrame* observation);
271 
272  /** Auxiliary function that evaluates the likelihood of an observation,
273  * given a robot pose, and according to the options in
274  * "CPosePDFParticles::options".
275  */
278  size_t particleIndexForMap, const mrpt::obs::CSensoryFrame* observation,
279  const mrpt::poses::CPose2D* x);
280 
281  void executeOn(
283  const mrpt::obs::CSensoryFrame* observation,
286 
287 
288  protected:
289  /** @}
290  */
291 
292  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
293  */
295 
296  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
297  */
298  std::vector<double> m_maxLikelihood;
299 
300  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm. */
301  unsigned int m_movementDrawsIdx;
302 
303  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm. */
305 
306  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm. */
308 
309 }; // End of class def.
310 
311 } // namespace hmtslam
312 } // namespace mrpt
313 
314 #endif
std::map< TPoseID, CHMHMapNode::TNodeID > m_nodeIDmemberships
The hybrid map node membership for each robot pose.
Implements a 2D local SLAM method based on a RBPF over an occupancy grid map.
Definition: CHMTSLAM.h:548
THypothesisID m_ID
The unique ID of the hypothesis (Used for accessing mrpt::slam::CHierarchicalMHMap).
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:44
double particlesEvaluator_AuxPFOptimal(const mrpt::bayes::CParticleFilter::TParticleFilterOptions &PF_options, size_t index, const mrpt::obs::CSensoryFrame *observation)
Auxiliary function used in "prediction_and_update_pfAuxiliaryPFOptimal".
std::vector< double > m_maxLikelihood
Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
void dumpAsText(utils::CStringList &st) const
Describes the LMH in text.
void getAs3DScene(mrpt::opengl::CSetOfObjects::Ptr &objs) const
Returns a 3D representation of the the current robot pose, all the poses in the auxiliary graph...
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:42
void getPathParticles(std::map< TPoseID, mrpt::poses::CPose3DPDFParticles > &outList) const
Returns the mean and covariance of each robot pose in this LMH, as computed from the set of particles...
double m_log_w
Log-weight of this hypothesis.
uint64_t TPoseID
An integer number uniquely identifying each robot pose stored in HMT-SLAM.
CLocalMetricHypothesis(CHMTSLAM *parent=nullptr)
Constructor (Default param only used from STL classes)
Statistics for being returned from the "execute" method.
A set of TMetricMapInitializer structures, passed to the constructor CMultiMetricMap::CMultiMetricMap...
An implementation of Hybrid Metric Topological SLAM (HMT-SLAM).
Definition: CHMTSLAM.h:65
void executeOn(mrpt::bayes::CParticleFilter &pf, const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, mrpt::bayes::CParticleFilter::TParticleFilterStats *stats, mrpt::bayes::CParticleFilter::TParticleFilterAlgorithm PF_algorithm)
Declares a class for storing a collection of robot actions.
mrpt::obs::CActionRobotMovement2D m_accumRobotMovement
Used in CLSLAM_RBPF_2DLASER.
int64_t THypothesisID
An integer number uniquely identifying each of the concurrent hypotheses for the robot topological pa...
mrpt::poses::StdVector_CPose2D m_movementDraws
Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
Represents a probabilistic 2D movement of the robot mobile base.
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...
A class for storing a list of text lines.
Definition: CStringList.h:32
mrpt::aligned_containers< TPoseID, mrpt::poses::CPose3D >::map_t TMapPoseID2Pose3D
std::map< uint32_t, TPoseID > idx2pose
For the poses in "partitioner".
TPoseIDList m_posesPendingAddPartitioner
The list of poseIDs waiting to be added to the graph partitioner, what happens in the LSLAM thread ma...
mrpt::bayes::CParticleFilterData< CLSLAMParticleData >::CParticleList CParticleList
GLuint index
Definition: glext.h:4054
CProbabilityParticle< CLSLAMParticleData > CParticleData
Use this to refer to each element in the m_particles array.
mrpt::utils::safe_ptr< CHMTSLAM > m_parent
For quick access to our parent object.
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:32
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:54
mrpt::math::CVectorDouble m_pfAuxiliaryPFOptimal_estimatedProb
Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
unsigned int m_movementDrawsIdx
Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
This class acts as a common interface to the different interfaces (see CParticleFilter::TParticleFilt...
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...
struct mrpt::hmtslam::CLocalMetricHypothesis::TRobotPosesPartitioning m_robotPosesGraph
std::vector< TPoseID > TPoseIDList
void prediction_and_update(const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, const bayes::CParticleFilter::TParticleFilterOptions &PF_options)
The PF algorithm implementation.
std::map< TPoseID, mrpt::obs::CSensoryFrame > m_SFs
The SF gathered at each robot pose.
Auxiliary class used in mrpt::slam::CLocalMetricHypothesis for HMT-SLAM; this class keeps the data re...
void getRelativePose(const TPoseID &reference, const TPoseID &pose, mrpt::poses::CPose3DPDFParticles &outPDF) const
Returns the pose PDF of some pose relative to some other pose ID (both must be part of the the LMH)...
mrpt::poses::StdVector_CPose2D m_movementDrawMaximumLikelihood
Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
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...
double auxiliarComputeObservationLikelihood(const mrpt::bayes::CParticleFilter::TParticleFilterOptions &PF_options, size_t particleIndexForMap, const mrpt::obs::CSensoryFrame *observation, const mrpt::poses::CPose2D *x)
Auxiliary function that evaluates the likelihood of an observation, given a robot pose...
bool m_accumRobotMovementIsValid
Used in CLSLAM_RBPF_2DLASER.
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.
TParticleFilterAlgorithm
Defines different types of particle filter algorithms.
A template class for holding a the data and the weight of a particle.
void getMeans(TMapPoseID2Pose3D &outList) const
Returns the mean of each robot pose in this LMH, as computed from the set of particles.
void removeAreaFromLMH(const CHMHMapNode::TNodeID areaID)
Removes a given area from the LMH:
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
void rebuildMetricMaps()
Rebuild the metric maps of all particles from the observations and their estimated poses...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
The configuration of a particle filter.
void changeCoordinateOrigin(const TPoseID &newOrigin)
Change all coordinates to set a given robot pose as the new coordinate origin, and rebuild metric map...
std::set< CHMHMapNode::TNodeID > TNodeIDSet
Definition: CHMHMapNode.h:146
void clearRobotPoses()
Rebuild the auxiliary metric maps in "m_robotPosesGraph" from the observations "m_SFs" and their esti...
unsigned int pose2idx(const TPoseID &id) const
Uses idx2pose to perform inverse searches.
void updateAreaFromLMH(const CHMHMapNode::TNodeID areaID, bool eraseSFsFromLMH=false)
The corresponding node in the HMT map is updated with the robot poses & SFs in the LMH: the poses are ref...
std::map< TYPE1, TYPE2, std::less< TYPE1 >, Eigen::aligned_allocator< std::pair< const TYPE1, TYPE2 > > > map_t
GLenum GLint x
Definition: glext.h:3538
This class stores any customizable set of metric maps.
CLSLAMParticleDataParticles m_poseParticles
TNodeIDList m_areasPendingTBI
The list of area IDs waiting to be processed by the TBI (topological bayesian inference) engines to s...
const mrpt::poses::CPose3D * getCurrentPose(const size_t &particleIdx) const
Returns the i&#39;th particle hypothesis for the current robot pose.
void getPoseParticles(const TPoseID &poseID, mrpt::poses::CPose3DPDFParticles &outPDF) const
Returns the mean and covariance of each robot pose in this LMH, as computed from the set of particles...
TNodeIDSet m_neighbors
The list of all areas sourronding the current one (this includes the current area itself)...
mrpt::aligned_containers< CPose2D >::vector_t StdVector_CPose2D
Eigen aligment-compatible container.
Definition: CPose2D.h:374
A wrapper class for pointers that can be safely copied with "=" operator without problems.
Definition: safe_pointers.h:75
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...
CLSLAMParticleData(const mrpt::maps::TSetOfMetricMapInitializers *mapsInitializers=nullptr)
mrpt::utils::TNodeID TNodeID
The type of the IDs of nodes.
Definition: CHMHMapNode.h:47
TPoseID m_currentRobotPose
The current robot pose (its global unique ID) for this hypothesis.
MRPT_TODO("Separate the serializable class from this code, so we don't have to " "worry about copying locks") struct ThreadLocks
mrpt::maps::CMultiMetricMap metricMaps



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019