Main MRPT website > C++ reference for MRPT 1.9.9
CFixedIntervalsNRD_impl.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 
10 #ifndef CFIXEDINTERVALSNRD_IMPL_H
11 #define CFIXEDINTERVALSNRD_IMPL_H
12 
13 namespace mrpt
14 {
15 namespace graphslam
16 {
17 namespace deciders
18 {
19 // Ctors, Dtors
20 //////////////////////////////////////////////////////////////
21 
22 template <class GRAPH_T>
24 {
25  using namespace mrpt::utils;
26  this->initializeLoggers("CFixedIntervalsNRD");
27 
28  this->logFmt(LVL_DEBUG, "IntervalsNRD: Initialized class object");
29 }
30 template <class GRAPH_T>
32 {
33 }
34 
35 // Member function implementations
36 //////////////////////////////////////////////////////////////
37 
38 template <class GRAPH_T>
41  mrpt::obs::CSensoryFrame::Ptr observations,
42  mrpt::obs::CObservation::Ptr observation)
43 {
44  MRPT_START;
45  using namespace mrpt::obs;
46  using namespace mrpt::math;
47  using namespace mrpt::utils;
48  using namespace mrpt::poses;
49 
50  // don't use the measurements in this implementation
51  MRPT_UNUSED_PARAM(observations);
52 
53  if (observation)
54  { // FORMAT #2 - observation-only format
55  m_observation_only_rawlog = true;
56 
57  if (IS_CLASS(observation, CObservationOdometry))
58  {
59  CObservationOdometry::Ptr obs_odometry =
60  std::dynamic_pointer_cast<CObservationOdometry>(observation);
61  // not incremental - gives the absolute odometry reading
62  m_curr_odometry_only_pose = pose_t(obs_odometry->odometry);
63  this->logFmt(
64  LVL_DEBUG, "Current odometry-only pose: %s",
65  m_curr_odometry_only_pose.asString().c_str());
66 
67  // I don't have any information about the covariane of the move in
68  // observation-only format
69  this->m_since_prev_node_PDF.mean =
70  m_curr_odometry_only_pose - m_last_odometry_only_pose;
71  }
72  }
73  else
74  { // FORMAT #1 - action-observation format
75  m_observation_only_rawlog = false;
76 
78  bool found = action->getFirstMovementEstimation(move_pdf);
79  if (found)
80  {
81  // update the relative PDF of the path since the LAST node was
82  // inserted
83  constraint_t incr_constraint;
84  incr_constraint.copyFrom(move_pdf);
85  this->m_since_prev_node_PDF += incr_constraint;
86  }
87  } // ELSE - FORMAT #1
88 
89  bool registered = this->checkRegistrationCondition();
90 
91  if (registered)
92  {
93  if (m_observation_only_rawlog)
94  {
95  // keep track of the odometry-only pose_t at the last inserted graph
96  // node
97  m_last_odometry_only_pose = m_curr_odometry_only_pose;
98  }
99  }
100 
101  return registered;
102 
103  MRPT_END;
104 } // end of updateState
105 
106 template <class GRAPH_T>
108 {
109  MRPT_START;
110 
111  // check that a node has already been registered - if not, default to
112  // (0,0,0)
113  pose_t last_pose_inserted =
114  this->m_prev_registered_nodeID != INVALID_NODEID
115  ? this->m_graph->nodes.at(this->m_prev_registered_nodeID)
116  : pose_t();
117 
118  // odometry criterion
119  bool registered = false;
120 
121  if (this->checkRegistrationCondition(
122  last_pose_inserted, this->getCurrentRobotPosEstimation()))
123  {
124  registered = this->registerNewNodeAtEnd();
125  }
126 
127  return registered;
128  MRPT_END;
129 } // end of checkRegistrationCondition
130 
131 template <class GRAPH_T>
133  const mrpt::poses::CPose2D& p1, const mrpt::poses::CPose2D& p2) const
134 {
135  using namespace mrpt::math;
136 
137  bool res = false;
138  if ((p1.distanceTo(p2) > params.registration_max_distance) ||
139  (fabs(wrapToPi(p1.phi() - p2.phi())) > params.registration_max_angle))
140  {
141  res = true;
142  }
143 
144  return res;
145 } // end of checkRegistrationCondition2D
146 
147 template <class GRAPH_T>
149  const mrpt::poses::CPose3D& p1, const mrpt::poses::CPose3D& p2) const
150 {
151  using namespace mrpt::math;
152 
153  bool res = false;
154  if ((p1.distanceTo(p2) > params.registration_max_distance) ||
155  (fabs(wrapToPi(p1.roll() - p2.roll())) >
156  params.registration_max_angle) ||
157  (fabs(wrapToPi(p1.pitch() - p2.pitch())) >
158  params.registration_max_angle) ||
159  (fabs(wrapToPi(p1.yaw() - p2.yaw())) > params.registration_max_angle))
160  {
161  res = true;
162  }
163 
164  return res;
165 } // end of checkRegistrationCondition3D
166 
167 template <class GRAPH_T>
169 {
170  MRPT_START;
171  using namespace mrpt::utils;
172  parent_t::loadParams(source_fname);
173 
174  params.loadFromConfigFileName(
175  source_fname, "NodeRegistrationDeciderParameters");
176 
177  // set the logging level if given by the user
178  CConfigFile source(source_fname);
179  int min_verbosity_level = source.read_int(
180  "NodeRegistrationDeciderParameters", "class_verbosity", 1, false);
181  this->setMinLoggingLevel(VerbosityLevel(min_verbosity_level));
182 
183  this->logFmt(LVL_DEBUG, "Successfully loaded parameters.");
184  MRPT_END;
185 }
186 
187 template <class GRAPH_T>
189 {
190  MRPT_START;
191  parent_t::printParams();
192  params.dumpToConsole();
193 
194  MRPT_END;
195 }
196 
197 template <class GRAPH_T>
199  std::string* report_str) const
200 {
201  MRPT_START;
202  using namespace std;
203 
204  const std::string report_sep(2, '\n');
205  const std::string header_sep(80, '#');
206 
207  // Report on graph
208  stringstream class_props_ss;
209  class_props_ss << "Strategy: "
210  << "Fixed Odometry-based Intervals" << std::endl;
211  class_props_ss << header_sep << std::endl;
212 
213  // time and output logging
214  const std::string time_res = this->m_time_logger.getStatsAsText();
215  const std::string output_res = this->getLogAsString();
216 
217  // merge the individual reports
218  report_str->clear();
219  parent_t::getDescriptiveReport(report_str);
220 
221  *report_str += class_props_ss.str();
222  *report_str += report_sep;
223 
224  // configuration parameters
225  *report_str += params.getAsString();
226  *report_str += report_sep;
227 
228  // loggers results
229  *report_str += time_res;
230  *report_str += report_sep;
231 
232  *report_str += output_res;
233  *report_str += report_sep;
234 
235  MRPT_END;
236 }
237 
238 // TParams
239 //////////////////////////////////////////////////////////////
240 template <class GRAPH_T>
242 {
243 }
244 template <class GRAPH_T>
246 {
247 }
248 template <class GRAPH_T>
250  mrpt::utils::CStream& out) const
251 {
252  MRPT_START;
253  out.printf("%s", this->getAsString().c_str());
254  MRPT_END;
255 }
256 template <class GRAPH_T>
258  const mrpt::utils::CConfigFileBase& source, const std::string& section)
259 {
260  MRPT_START;
261  using namespace mrpt::math;
262  using namespace mrpt::utils;
263 
264  registration_max_distance = source.read_double(
265  section, "registration_max_distance", 0.5 /* meter */, false);
266  registration_max_angle = source.read_double(
267  section, "registration_max_angle", 60 /* degrees */, false);
268  registration_max_angle = DEG2RAD(registration_max_angle);
269 
270  MRPT_END;
271 }
272 
273 template <class GRAPH_T>
275  std::string* params_out) const
276 {
277  MRPT_START;
278  using namespace mrpt::math;
279  using namespace mrpt::utils;
280 
281  double max_angle_deg = RAD2DEG(registration_max_angle);
282  params_out->clear();
283 
284  *params_out +=
285  "------------------[ Fixed Intervals Node Registration "
286  "]------------------\n";
287  *params_out += mrpt::format(
288  "Max distance for registration = %.2f m\n", registration_max_distance);
289  *params_out += mrpt::format(
290  "Max angle for registration = %.2f deg\n", max_angle_deg);
291 
292  MRPT_END;
293 }
294 template <class GRAPH_T>
296 {
297  MRPT_START;
298 
299  std::string str;
300  this->getAsString(&str);
301  return str;
302 
303  MRPT_END;
304 }
305 }
306 }
307 } // end of namespaces
308 
309 #endif /* end of include guard: CFIXEDINTERVALSNRD_IMPL_H */
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of t...
Definition: CObject.h:103
#define RAD2DEG
Definition: bits.h:115
#define DEG2RAD
Definition: bits.h:112
void getDescriptiveReport(std::string *report_str) const
Fill the provided string with a detailed report of the decider/optimizer state.
void loadParams(const std::string &source_fname)
Load the necessary for the decider/optimizer configuration parameters.
bool updateState(mrpt::obs::CActionCollection::Ptr action, mrpt::obs::CSensoryFrame::Ptr observations, mrpt::obs::CObservation::Ptr observation)
Method makes use of the CActionCollection/CObservation to update the odometry estimation from the las...
GRAPH_T::constraint_t::type_value pose_t
type of underlying poses (2D/3D).
GRAPH_T::constraint_t constraint_t
type of graph constraints
void printParams() const
Print the problem parameters - relevant to the decider/optimizer to the screen in a unified/compact w...
bool checkRegistrationCondition()
If estimated position surpasses the registration max values since the previous registered node,...
std::shared_ptr< CActionCollection > Ptr
std::shared_ptr< CObservation > Ptr
Definition: CObservation.h:43
An observation of the current (cumulative) odometry for a wheeled robot.
std::shared_ptr< CObservationOdometry > Ptr
std::shared_ptr< CSensoryFrame > Ptr
Definition: CSensoryFrame.h:56
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:41
const double & phi() const
Get the phi angle of the 2D pose (in radians)
Definition: CPose2D.h:91
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:89
double pitch() const
Get the PITCH angle (in radians)
Definition: CPose3D.h:539
double roll() const
Get the ROLL angle (in radians)
Definition: CPose3D.h:545
double yaw() const
Get the YAW angle (in radians)
Definition: CPose3D.h:533
Declares a class that represents a Probability Density function (PDF) of a 3D pose .
void copyFrom(const CPose3DPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations)
double distanceTo(const CPoseOrPoint< OTHERCLASS > &b) const
Returns the Euclidean distance to another pose/point:
Definition: CPoseOrPoint.h:206
This class allows loading and storing values and vectors of different types from a configuration text...
This class allows loading and storing values and vectors of different types from "....
Definition: CConfigFile.h:36
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:42
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
Definition: CStream.cpp:597
GLuint res
Definition: glext.h:7268
GLenum const GLfloat * params
Definition: glext.h:3534
GLsizei const GLchar ** string
Definition: glext.h:4101
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
Definition: wrap2pi.h:53
#define INVALID_NODEID
Definition: types_simple.h:52
#define MRPT_START
Definition: mrpt_macros.h:425
#define MRPT_END
Definition: mrpt_macros.h:429
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
Definition: mrpt_macros.h:365
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:20
This namespace contains representation of robot actions and observations.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:18
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 format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:19
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &section)
This method load the options from a ".ini"-like file or memory-stored string list.
void dumpToTextStream(mrpt::utils::CStream &out) const
This method should clearly display all the contents of the structure in textual form,...



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 63ea9d1f1 Thu Nov 23 00:06:53 2017 +0100 at mar 26 may 2026 12:19:29 CEST