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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020