Main MRPT website > C++ reference for MRPT 1.9.9
CHMTSLAM_LOG.cpp
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 
10 #include "hmtslam-precomp.h" // Precomp header
11 
12 #include <mrpt/system/os.h>
15 #include <mrpt/system/os.h>
16 #include <mrpt/utils/CTicTac.h>
17 
18 using namespace mrpt::slam;
19 using namespace mrpt::hmtslam;
20 using namespace mrpt::opengl;
21 using namespace mrpt::poses;
22 using namespace mrpt::utils;
23 using namespace mrpt::system;
24 using namespace std;
25 
26 /*---------------------------------------------------------------
27 
28  CHMTSLAM_LOG
29 
30  Implements a 2D local SLAM method based on scan matching
31  between near observations and an EKF. A part of HMT-SLAM
32 
33 \param LMH The local metric hypothesis which must be updated by this SLAM
34 algorithm.
35 \param act The action to process (or nullptr).
36 \param sf The observations to process (or nullptr).
37 
38 --------------------------------------------------------------- */
39 void CHMTSLAM::generateLogFiles(unsigned int nIteration)
40 {
42 
43  // Speed up the storage of images (in opengl::CTexturedPlane's):
44  // CImage::DISABLE_ZIP_COMPRESSION = true;
45 
46  static CTicTac tictac;
47 
48  tictac.Tic();
49 
50  THypothesisID bestHypoID;
51  CLocalMetricHypothesis* bestLMH = nullptr;
52  {
53  std::lock_guard<std::mutex> lock(m_LMHs_cs);
54 
55  MRPT_LOG_INFO_STREAM("[LOG] Number of LMHs: " << m_LMHs.size());
56 
57  // Generate 3D view of local areas:
58  {
59  string filLocalAreas = format(
60  "%s/LSLAM_3D/mostLikelyLMH_LSLAM_%05u.3Dscene",
61  m_options.LOG_OUTPUT_DIR.c_str(), nIteration);
62  COpenGLScene::Ptr sceneLSLAM =
63  mrpt::make_aligned_shared<COpenGLScene>();
64 
65  // Look for the most likely LMH:
68  for (it = m_LMHs.begin(); it != m_LMHs.end(); it++)
69  {
70  if (!bestLMH)
71  {
72  bestLMH = &it->second;
73  }
74  else if (it->second.m_log_w > bestLMH->m_log_w)
75  {
76  bestLMH = &it->second;
77  }
78  }
79  ASSERT_(bestLMH != nullptr)
80 
81  bestHypoID = bestLMH->m_ID;
82 
83  {
84  std::lock_guard<std::mutex> lockerLMH(
85  bestLMH->threadLocks.m_lock);
86 
87  {
88  // Generate the metric maps 3D view...
90  mrpt::make_aligned_shared<opengl::CSetOfObjects>();
91  maps3D->setName("metric-maps");
93  ->d->metricMaps.getAs3DObject(maps3D);
94  sceneLSLAM->insert(maps3D);
95 
96  // ...and the robot poses, areas, etc:
98  mrpt::make_aligned_shared<opengl::CSetOfObjects>();
99  LSLAM_3D->setName("LSLAM_3D");
100  bestLMH->getAs3DScene(LSLAM_3D);
101  sceneLSLAM->insert(LSLAM_3D);
102 
103  sceneLSLAM->enableFollowCamera(true);
104 
105  MRPT_LOG_INFO_STREAM("[LOG] Saving " << filLocalAreas);
106  CFileGZOutputStream(filLocalAreas) << *sceneLSLAM;
107  }
108 
109 // Save the SSO matrix:
110 #if 0
111  {
112  std::lock_guard<std::mutex> lock(bestLMH->m_robotPosesGraph.lock );
113  string filSSO = format("%s/ASSO/mostLikelyLMH_ASSO_%05u.3Dscene", m_options.LOG_OUTPUT_DIR.c_str(), nIteration );
114  COpenGLScene sceneSSO;
115  opengl::CSetOfObjects::Ptr sso3D = mrpt::make_aligned_shared<opengl::CSetOfObjects>();
117  sceneSSO.insert(sso3D);
118  CFileGZOutputStream(filSSO) << sceneSSO;
119 
120  if (1)
121  {
122  CMatrix A;
124  if (A.getColCount()>0)
125  {
126  A.adjustRange();
127  A.saveToTextFile( format("%s/ASSO/mostLikelyLMH_ASSO_%05u.txt", m_options.LOG_OUTPUT_DIR.c_str(), nIteration ) );
128  CImage(A,true).saveToFile( format("%s/ASSO/mostLikelyLMH_ASSO_%05u.png", m_options.LOG_OUTPUT_DIR.c_str(), nIteration ) );
129  }
130  }
131  } // end lock partitioner's CS
132 #endif
133 
134  } // end LMH's lock
135  }
136 
137  } // end of lock on LMHs_cs
138 
139 #if 1
140  {
141  // Save the whole HMT-SLAM state to a dump file
142  static int CNT = 0;
143  if ((CNT++ % 20) == 0)
144  {
145  string hmtmap_file(
146  format(
147  "%s/HMTSLAM_state/state_%05u.hmtslam",
148  m_options.LOG_OUTPUT_DIR.c_str(), nIteration));
149  MRPT_LOG_INFO_STREAM("[LOG] Saving: " << hmtmap_file.c_str());
150  CFileGZOutputStream(hmtmap_file) << *this;
151  }
152  }
153 #endif
154 
155 #if 1
156  {
157  // Update the poses-graph in the HMT-map from the LMH to draw it:
158  static int CNT = 0;
159  if ((CNT++ % 5) == 0)
160  {
161  std::lock_guard<std::mutex> lockerLMH(bestLMH->threadLocks.m_lock);
162 
163  for (TNodeIDSet::const_iterator n = bestLMH->m_neighbors.begin();
164  n != bestLMH->m_neighbors.end(); ++n)
165  bestLMH->updateAreaFromLMH(*n);
166 
167  // Save global map for most likely hypothesis:
168  COpenGLScene sceneGlobalHMTMAP;
169  {
170  std::lock_guard<std::mutex> lock(m_map_cs);
172  "[LOG] HMT-map: " << m_map.nodeCount() << " nodes/ "
173  << m_map.arcCount() << " arcs");
174 
175  m_map.getAs3DScene(
176  sceneGlobalHMTMAP, // Scene
177  m_map.getFirstNode()->getID(), // Reference node
178  bestHypoID, // Hypothesis to get
179  3 // iterations
180  );
181  }
182 
183  string hmtmap_file(
184  format(
185  "%s/HMAP_3D/mostLikelyHMT_MAP_%05u.3Dscene",
186  m_options.LOG_OUTPUT_DIR.c_str(), nIteration));
187  MRPT_LOG_INFO_STREAM("[LOG] Saving " << hmtmap_file);
188  CFileGZOutputStream(hmtmap_file) << sceneGlobalHMTMAP;
189  }
190  }
191 #endif
192 
193  // Save the memory usage:
194  unsigned long memUsage = mrpt::system::getMemoryUsage();
195 
196  FILE* f = os::fopen(
197  format("%s/log_MemoryUsage.txt", m_options.LOG_OUTPUT_DIR.c_str())
198  .c_str(),
199  "at");
200  if (f)
201  {
202  os::fprintf(f, "%u\t%f\n", nIteration, memUsage / (1024.0 * 1024.0));
203  os::fclose(f);
204  }
205 
206  double t_log = tictac.Tac();
208  "[LOG] Time for logging: " << mrpt::system::formatTimeInterval(t_log));
209 
210  MRPT_END
211 }
void getAdjacencyMatrix(MATRIX &outMatrix) const
Return a copy of the internal adjacency matrix.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
THypothesisID m_ID
The unique ID of the hypothesis (Used for accessing mrpt::slam::CHierarchicalMHMap).
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Definition: math_frwds.h:30
int void fclose(FILE *f)
An OS-independent version of fclose.
Definition: os.cpp:272
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:118
Classes related to the implementation of Hybrid Metric Topological (HMT) SLAM.
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...
GLenum GLsizei n
Definition: glext.h:5074
Scalar * iterator
Definition: eigen_plugins.h:26
const CParticleData * getMostLikelyParticle() const
Returns the particle with the highest weight.
double m_log_w
Log-weight of this hypothesis.
STL namespace.
const Scalar * const_iterator
Definition: eigen_plugins.h:27
std::string formatTimeInterval(const double timeSeconds)
Returns a formated string with the given time difference (passed as the number of seconds)...
Definition: datetime.cpp:231
void Tic()
Starts the stopwatch.
Definition: CTicTac.cpp:82
Helper types for STL containers with Eigen memory allocators.
int64_t THypothesisID
An integer number uniquely identifying each of the concurrent hypotheses for the robot topological pa...
std::map< uint32_t, TPoseID > idx2pose
For the poses in "partitioner".
#define MRPT_END
This class implements a high-performance stopwatch.
Definition: CTicTac.h:23
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:32
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:19
void getAs3DScene(mrpt::opengl::CSetOfObjects::Ptr &objs, const std::map< uint32_t, int64_t > *renameIndexes=NULL) const
Return a 3D representation of the current state: poses & links between them.
This class is used in HMT-SLAM to represent each of the Local Metric Hypotheses (LMHs).
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
struct mrpt::hmtslam::CLocalMetricHypothesis::TRobotPosesPartitioning m_robotPosesGraph
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
Definition: os.cpp:405
#define MRPT_START
#define MRPT_LOG_INFO_STREAM(__CONTENTS)
#define CFileGZOutputStream
Saves data to a file and transparently compress the data using the given compression level...
unsigned long getMemoryUsage()
Returns the memory occupied by this process, in bytes.
Definition: memory.cpp:185
std::shared_ptr< COpenGLScene > Ptr
Definition: COpenGLScene.h:62
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
mrpt::utils::copy_ptr< T > d
The data associated with this particle.
This class allows the user to create, load, save, and render 3D scenes using OpenGL primitives...
Definition: COpenGLScene.h:60
#define ASSERT_(f)
bool saveToFile(const std::string &fileName, int jpeg_quality=95) const
Save the image to a file, whose format is determined from the extension (internally uses OpenCV)...
Definition: CImage.cpp:301
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...
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
Definition: os.cpp:254
CLSLAMParticleDataParticles m_poseParticles
TNodeIDSet m_neighbors
The list of all areas sourronding the current one (this includes the current area itself)...



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