Main MRPT website > C++ reference for MRPT 1.9.9
TWaypoint.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 "nav-precomp.h" // Precomp header
11 
14 #include <mrpt/opengl/CDisk.h>
15 #include <mrpt/opengl/CArrow.h>
16 #include <limits>
17 
18 using namespace mrpt::nav;
19 using namespace std;
20 
21 // TWaypoint ==========
23  : target(INVALID_NUM, INVALID_NUM),
24  target_heading(INVALID_NUM),
25  target_frame_id("map"),
26  allowed_distance(INVALID_NUM),
27  allow_skip(true)
28 {
29 }
30 
32  double target_x, double target_y, double allowed_distance_,
33  bool allow_skip_, double target_heading_)
34  : target(target_x, target_y),
35  target_heading(target_heading_),
36  target_frame_id("map"),
37  allowed_distance(allowed_distance_),
38  allow_skip(allow_skip_)
39 {
40 }
41 
42 bool TWaypoint::isValid() const
43 {
44  return (target.x != INVALID_NUM) && (target.y != INVALID_NUM) &&
46 }
47 
49 {
50  std::string s;
51  if (target.x != INVALID_NUM && target.y != INVALID_NUM)
52  s += mrpt::format("target=(%8.03f,%8.03f) ", target.x, target.y);
53  else
54  s += "target=(**Coordinates not set!!**) ";
55 
57  s += mrpt::format(
58  "phi=%8.03f deg ", mrpt::utils::RAD2DEG(target_heading));
59  else
60  s += " (heading: any) ";
61 
63  s += mrpt::format("allowed_dist=%8.03f ", allowed_distance);
64  else
65  s += " (**allowed_distance not set!!**) ";
66 
67  s += (allow_skip ? " allow_skip: YES" : " allow_skip: NO ");
68 
69  return s;
70 }
71 
72 // TWaypointSequence ==========
74 // Gets navigation params as a human-readable format:
76 {
77  string s;
78  s += mrpt::format(
79  "List of %u waypoints:\n", static_cast<unsigned int>(waypoints.size()));
80  unsigned int i = 0;
81  for (const auto& wp : waypoints)
82  {
83  s += mrpt::format(" #%3u: ", i++);
84  s += wp.getAsText();
85  s += "\n";
86  }
87  return s;
88 }
89 
90 // TWaypointStatus ==========
92  : reached(false),
93  skipped(false),
94  timestamp_reach(INVALID_TIMESTAMP),
95  counter_seen_reachable(0)
96 {
97 }
99 {
100  TWaypoint::operator=(wp);
101  return *this;
102 }
104 {
106  s += mrpt::format(" reached=%s", (reached ? "YES" : "NO "));
107  ;
108  return s;
109 }
110 
111 // TWaypointStatusSequence ======
113  : waypoints(),
114  timestamp_nav_started(INVALID_TIMESTAMP),
115  final_goal_reached(false),
116  waypoint_index_current_goal(-1),
117  last_robot_pose(
118  TWaypoint::INVALID_NUM, TWaypoint::INVALID_NUM,
119  TWaypoint::INVALID_NUM)
120 {
121 }
122 
124 {
125  string s;
126  s += mrpt::format(
127  "Status for %u waypoints:\n",
128  static_cast<unsigned int>(waypoints.size()));
129  unsigned int i = 0;
130  for (const auto& wp : waypoints)
131  {
132  s += mrpt::format(" #%3u: ", i++);
133  s += wp.getAsText();
134  s += "\n";
135  }
136  s += mrpt::format(
137  " final_goal_reached:%s waypoint_index_current_goal=%d\n",
139  return s;
140 }
141 
143  : outter_radius(.3),
144  inner_radius(.2),
145  outter_radius_non_skippable(.3),
146  inner_radius_non_skippable(.0),
147  outter_radius_reached(.2),
148  inner_radius_reached(.1),
149  heading_arrow_len(1.0),
150  color_regular(mrpt::utils::TColor(0x00, 0x00, 0xff)),
151  color_current_goal(mrpt::utils::TColor(0xff, 0x00, 0x20)),
152  color_reached(mrpt::utils::TColor(0x00, 0x00, 0xc0, 0xd0)),
153  show_labels(true)
154 {
155 }
156 
160 {
161  obj.clear();
162  unsigned int idx = 0;
163  for (const auto& p : waypoints)
164  {
165  auto gl_pt = mrpt::make_aligned_shared<mrpt::opengl::CDisk>(
166  p.allow_skip ? params.outter_radius
167  : params.outter_radius_non_skippable,
168  p.allow_skip ? params.inner_radius
169  : params.inner_radius_non_skippable,
170  15);
171  gl_pt->setLocation(p.target.x, p.target.y, 0.01);
172  gl_pt->setColor_u8(params.color_regular);
173  if (params.show_labels)
174  {
175  gl_pt->setName(mrpt::format("WayPt #%2u", idx));
176  gl_pt->enableShowName(true);
177  }
178  obj.insert(gl_pt);
179 
180  if (p.target_heading != TWaypoint::INVALID_NUM)
181  {
182  auto o = mrpt::make_aligned_shared<mrpt::opengl::CArrow>(
183  0, 0, 0, params.heading_arrow_len, 0.0f, 0.0f);
184  o->setPose(
186  p.target.x, p.target.y, 0.02, p.target_heading, 0, 0));
187  obj.insert(o);
188  }
189  ++idx;
190  }
191 }
192 
196 {
197  obj.clear();
198  {
199  unsigned int idx = 0;
200  for (const auto& p : waypoints)
201  {
202  const bool is_cur_goal = (int(idx) == waypoint_index_current_goal);
203 
205  mrpt::make_aligned_shared<mrpt::opengl::CDisk>(
206  p.reached
207  ? params.outter_radius_reached
208  : (p.allow_skip ? params.outter_radius
209  : params.outter_radius_non_skippable),
210  p.reached
211  ? params.inner_radius_reached
212  : (p.allow_skip ? params.inner_radius
213  : params.inner_radius_non_skippable),
214  15);
215  gl_pt->setLocation(p.target.x, p.target.y, 0.01);
216  if (params.show_labels)
217  {
218  gl_pt->setName(
219  mrpt::format(
220  "WayPt #%2u Reach:%s", idx, p.reached ? "YES" : "NO"));
221  gl_pt->enableShowName(true);
222  }
223  gl_pt->setColor_u8(
224  is_cur_goal ? params.color_current_goal
225  : (p.reached ? params.color_reached
226  : params.color_regular));
227  obj.insert(gl_pt);
228 
229  if (p.target_heading != TWaypoint::INVALID_NUM)
230  {
231  auto o = mrpt::make_aligned_shared<mrpt::opengl::CArrow>(
232  0, 0, 0, params.heading_arrow_len, 0.0f, 0.0f);
233  o->setPose(
235  p.target.x, p.target.y, 0.02, p.target_heading, 0, 0));
236  obj.insert(o);
237  }
238  ++idx;
239  }
240  }
241 }
242 
245 {
246  const unsigned int N = waypoints.size();
247  c.write(s, "waypoint_count", N);
248 
249  const int NP = 27; // name padding
250 
251  for (unsigned int i = 0; i < N; i++)
252  {
253  const auto& wp = waypoints[i];
254 
255  c.write(
256  s, mrpt::format("wp%03u_allowed_distance", i), wp.allowed_distance,
257  NP);
258  c.write(s, mrpt::format("wp%03u_allow_skip", i), wp.allow_skip, NP);
259  c.write(s, mrpt::format("wp%03u_target_x", i), wp.target.x, NP);
260  c.write(s, mrpt::format("wp%03u_target_y", i), wp.target.y, NP);
261  c.write(
262  s, mrpt::format("wp%03u_target_frame_id", i), wp.target_frame_id,
263  NP);
264  c.write(
265  s, mrpt::format("wp%03u_target_heading", i), wp.target_heading, NP);
266  }
267 }
268 
271 {
272  this->clear();
273 
274  const unsigned int N = c.read_int(s, "waypoint_count", 0, true);
275  waypoints.resize(N);
276 
277  for (unsigned int i = 0; i < N; i++)
278  {
279  auto& wp = waypoints[i];
280 
281  wp.allowed_distance = c.read_double(
282  s, mrpt::format("wp%03u_allowed_distance", i), 0, true);
283  wp.allow_skip =
284  c.read_bool(s, mrpt::format("wp%03u_allow_skip", i), true, true);
285  wp.target.x =
286  c.read_double(s, mrpt::format("wp%03u_target_x", i), 0, true);
287  wp.target.y =
288  c.read_double(s, mrpt::format("wp%03u_target_y", i), 0, true);
289  wp.target_frame_id = c.read_string(
290  s, mrpt::format("wp%03u_target_frame_id", i), "map", false);
291  double hd = c.read_double(
292  s, mrpt::format("wp%03u_target_heading", i),
294  wp.target_heading = (hd > 100) ? mrpt::nav::TWaypoint::INVALID_NUM : hd;
295  }
296 }
void load(const mrpt::utils::CConfigFileBase &c, const std::string &s)
Loads waypoints to a config file section.
Definition: TWaypoint.cpp:269
bool allow_skip
[Default=true] Whether it is allowed to the navigator to proceed to a more advanced waypoint in the s...
Definition: TWaypoint.h:52
std::string getAsText() const
Gets navigation params as a human-readable format.
Definition: TWaypoint.cpp:103
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
double x
X,Y coordinates.
A set of object, which are referenced to the coordinates framework established in this object...
Definition: CSetOfObjects.h:30
bool isValid() const
Check whether all the minimum mandatory fields have been filled by the user.
Definition: TWaypoint.cpp:42
TWaypointSequence()
Ctor with default values.
Definition: TWaypoint.cpp:73
void save(mrpt::utils::CConfigFileBase &c, const std::string &s) const
Saves waypoints to a config file section.
Definition: TWaypoint.cpp:243
std::string getAsText() const
get in human-readable format
Definition: TWaypoint.cpp:48
used in getAsOpenglVisualization()
Definition: TWaypoint.h:70
void getAsOpenglVisualization(mrpt::opengl::CSetOfObjects &obj, const mrpt::nav::TWaypointsRenderingParams &params=mrpt::nav::TWaypointsRenderingParams()) const
Renders the sequence of waypoints (previous contents of obj are cleared)
Definition: TWaypoint.cpp:193
std::vector< TWaypoint > waypoints
Definition: TWaypoint.h:89
A single waypoint within TWaypointSequence.
Definition: TWaypoint.h:23
STL namespace.
GLdouble s
Definition: glext.h:3676
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
This class allows loading and storing values and vectors of different types from a configuration text...
bool reached
Whether this waypoint has been reached already (to within the allowed distance as per user specificat...
Definition: TWaypoint.h:113
double RAD2DEG(const double x)
Radians to degrees.
TWaypoint()
Ctor with default values.
Definition: TWaypoint.cpp:22
const GLubyte * c
Definition: glext.h:6313
A waypoint with an execution status.
Definition: TWaypoint.h:109
bool final_goal_reached
Whether the final waypoint has been reached successfuly.
Definition: TWaypoint.h:141
GLsizei const GLchar ** string
Definition: glext.h:4101
void getAsOpenglVisualization(mrpt::opengl::CSetOfObjects &obj, const mrpt::nav::TWaypointsRenderingParams &params=mrpt::nav::TWaypointsRenderingParams()) const
Renders the sequence of waypoints (previous contents of obj are cleared)
Definition: TWaypoint.cpp:157
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
Definition: datetime.h:16
TWaypointStatus & operator=(const TWaypoint &wp)
Definition: TWaypoint.cpp:98
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
TWaypointStatusSequence()
Ctor with default values.
Definition: TWaypoint.cpp:112
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::math::TPoint2D target
[Must be set by the user] Coordinates of desired target location (world/global coordinates).
Definition: TWaypoint.h:28
std::string getAsText() const
Gets navigation params as a human-readable format.
Definition: TWaypoint.cpp:75
double target_heading
[Default=any heading] Optionally, set to the desired orientation [radians] of the robot at this waypo...
Definition: TWaypoint.h:34
double allowed_distance
[Must be set by the user] How close should the robot get to this waypoint for it to be considered rea...
Definition: TWaypoint.h:42
std::shared_ptr< CDisk > Ptr
Definition: CDisk.h:35
std::string getAsText() const
Gets navigation params as a human-readable format.
Definition: TWaypoint.cpp:123
std::vector< TWaypointStatus > waypoints
Waypoints parameters and status (reached, skipped, etc.)
Definition: TWaypoint.h:137
static const int INVALID_NUM
The default value of fields (used to detect non-set values)
Definition: TWaypoint.h:66
int waypoint_index_current_goal
Index in waypoints of the waypoint the navigator is currently trying to reach.
Definition: TWaypoint.h:146
GLfloat GLfloat p
Definition: glext.h:6305
GLenum const GLfloat * params
Definition: glext.h:3534



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