Main MRPT website > C++ reference for MRPT 1.3.2
PlannerRRT_SE2_TPS.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-2015, 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 #pragma once
11 
16 #include <mrpt/utils/CTimeLogger.h>
17 #include <numeric>
18 
19 #include <mrpt/nav/link_pragmas.h>
20 
21 namespace mrpt
22 {
23  namespace nav
24  {
25  /** \addtogroup nav_planners Path planning
26  * \ingroup mrpt_nav_grp
27  * @{ */
28 
29  /** TP Space-based RRT path planning for SE(2) (planar) robots.
30  *
31  * This planner algorithm is described in the paper:
32  * - M. Bellone, J.L. Blanco, A. Gimenez, "TP-Space RRT: Kinematic path planning of non-holonomic any-shape vehicles", International Journal of Advanced Robotic Systems, 2015.
33  *
34  * Typical usage:
35  * \code
36  * mrpt::nav::PlannerRRT_SE2_TPS planner;
37  *
38  * // Set or load planner parameters:
39  * //planner.loadConfig( mrpt::utils::CConfigFile("config_file.cfg") );
40  * //planner.params.... // See TAlgorithmParams
41  *
42  * // Set RRT end criteria (when to stop searching for a solution)
43  * //planner.end_criteria.... // See TEndCriteria
44  *
45  * planner.initialize(); // Initialize after setting the algorithm parameters
46  *
47  * // Set up planning problem:
48  * PlannerRRT_SE2_TPS::TPlannerResult planner_result;
49  * PlannerRRT_SE2_TPS::TPlannerInput planner_input;
50  * // Start & goal:
51  * planner_input.start_pose = mrpt::math::TPose2D(XXX,XXX,XXX);
52  * planner_input.goal_pose = mrpt::math::TPose2D(XXX,XXX,XXX);
53  * // Set obtacles: (...)
54  * // planner_input.obstacles_points ...
55  * // Set workspace bounding box for picking random poses in the RRT algorithm:
56  * planner_input.world_bbox_min = mrpt::math::TPoint2D(XX,YY);
57  * planner_input.world_bbox_max = mrpt::math::TPoint2D(XX,YY);
58  * // Do path planning:
59  * planner.solve( planner_input, planner_result);
60  * // Analyze contents of planner_result...
61  * \endcode
62  *
63  * - Changes history:
64  * - 06/MAR/2014: Creation (MB)
65  * - 06/JAN/2015: Refactoring (JLBC)
66  *
67  * \todo Factorize into more generic path planner classes! //template <class POSE, class MOTIONS>...
68  */
70  {
71  public:
72  typedef mrpt::math::TPose2D node_pose_t; //!< The type of poses at nodes
73 
75  {
76  double acceptedDistToTarget; //!< Maximum distance from a pose to target to accept it as a valid solution (meters). (Both acceptedDistToTarget & acceptedAngToTarget must be satisfied)
77  double acceptedAngToTarget; //!< Maximum angle from a pose to target to accept it as a valid solution (rad). (Both acceptedDistToTarget & acceptedAngToTarget must be satisfied)
78 
79  double maxComputationTime; //!< In seconds. 0 means no limit until a solution is found.
80  double minComputationTime; //!< In seconds. 0 means the first valid path will be returned. Otherwise, the algorithm will try to refine and find a better one.
81 
83  acceptedDistToTarget ( 0.1 ),
84  acceptedAngToTarget ( mrpt::utils::DEG2RAD(180) ),
85  maxComputationTime ( 0.0 ),
86  minComputationTime ( 0.0 )
87  {
88  }
89  };
91 
93  {
94  /** The robot shape used when computing collisions; it's loaded from the
95  * config file/text as a single 2xN matrix in MATLAB format, first row are Xs, second are Ys, e.g:
96  * \code
97  * robot_shape = [-0.2 0.2 0.2 -0.2; -0.1 -0.1 0.1 0.1]
98  * \endcode
99  */
101 
102  double goalBias; //!< Probabily of picking the goal as random target (in [0,1], default=0.05)
103  double maxLength; //!< (Very sensitive parameter!) Max length of each edge path (in meters, default=1.0)
104  double minDistanceBetweenNewNodes; //!< Minimum distance [meters] to nearest node to accept creating a new one (default=0.10). (Any of minDistanceBetweenNewNodes and minAngBetweenNewNodes must be satisfied)
105  double minAngBetweenNewNodes; //!< Minimum angle [rad] to nearest node to accept creating a new one (default=15 deg) (Any of minDistanceBetweenNewNodes and minAngBetweenNewNodes must be satisfied)
106  bool ptg_verbose; //!< Display PTG construction info (default=true)
107 
108  size_t save_3d_log_freq; //!< Frequency (in iters) of saving tree state to debug log files viewable in SceneViewer3D (default=0, disabled)
109 
111  goalBias(0.05),
112  maxLength(1.0),
113  minDistanceBetweenNewNodes(0.10),
114  minAngBetweenNewNodes(mrpt::utils::DEG2RAD(15)),
115  ptg_verbose(true),
116  save_3d_log_freq(0)
117  {
118  robot_shape.push_back( mrpt::math::TPoint2D(-0.5,-0.5) );
119  robot_shape.push_back( mrpt::math::TPoint2D( 0.8,-0.4) );
120  robot_shape.push_back( mrpt::math::TPoint2D( 0.8, 0.4) );
121  robot_shape.push_back( mrpt::math::TPoint2D(-0.5, 0.5) );
122  }
123  };
124  TAlgorithmParams params; //!< Parameters specific to this path solver algorithm
125 
127  {
130 
131  mrpt::math::TPose2D world_bbox_min,world_bbox_max; //!< Bounding box of the world, used to draw uniform random pose samples
132 
133  mrpt::maps::CSimplePointsMap obstacles_points; //!< World obstacles, as a point cloud
134 
136  start_pose(0,0,0),
137  goal_pose(0,0,0),
138  world_bbox_min(-10.,-10.0,-M_PI),
139  world_bbox_max( 10., 10.0, M_PI)
140  {
141  }
142  };
143 
145  {
146  bool success; //!< Whether the target was reached or not
147  double computation_time; //!< Time spent (in secs)
148  double goal_distance; //!< Distance from best found path to goal
149  double path_cost; //!< Total cost of the best found path (cost ~~ Euclidean distance)
150  mrpt::utils::TNodeID best_goal_node_id; //!< The ID of the best target node in the tree
151  std::set<mrpt::utils::TNodeID> acceptable_goal_node_ids; //!< The set of target nodes within an acceptable distance to target (including `best_goal_node_id` and others)
152  TMoveTreeSE2_TP move_tree; //!< The generated motion tree that explores free space starting at "start"
153 
155  success(false),
156  computation_time(0),
157  goal_distance( std::numeric_limits<double>::max() ),
158  path_cost( std::numeric_limits<double>::max() ),
159  best_goal_node_id(INVALID_NODEID)
160  {
161  }
162  };
163 
164  /** Constructor */
166 
167  /** Load all params from a config file source */
168  void loadConfig(const mrpt::utils::CConfigFileBase &cfgSource, const std::string &sSectionName = std::string("PTG_CONFIG"));
169 
170  /** Must be called after setting all params (see `loadConfig()`) and before calling `solve()` */
171  void initialize();
172 
173  /** The main API entry point: tries to find a planned path from 'goal' to 'target' */
174  void solve( const TPlannerInput &pi, TPlannerResult & result );
175 
176  /** Options for renderMoveTree() */
178  {
179  mrpt::utils::TNodeID highlight_path_to_node_id; //!< Highlight the path from root towards this node (usually, the target)
180  size_t draw_shape_decimation; //!< (Default=1) Draw one out of N vehicle shapes along the highlighted path
181 
186 
187  double xyzcorners_scale; //!< A scale factor to all XYZ corners (default=0, means auto determien from vehicle shape)
188  bool highlight_last_added_edge; //!< (Default=false)
189  double ground_xy_grid_frequency; //!< (Default=10 meters) Set to 0 to disable
190 
192  mrpt::utils::TColor color_obstacles; //!< obstacles color
193  mrpt::utils::TColor color_local_obstacles; //!< local obstacles color
194  mrpt::utils::TColor color_start; //!< START indication color
195  mrpt::utils::TColor color_goal; //!< END indication color
205 
206  double vehicle_shape_z; //!< (Default=0.01) Height (Z coordinate) for the vehicle shapes. Helps making it in the "first plane"
207  double vehicle_line_width; //!< Robot line width for visualization - default 2.0
208  bool draw_obstacles; //!< (Default=true)
209 
210  std::string log_msg;
213 
215  highlight_path_to_node_id( INVALID_NODEID ),
216  draw_shape_decimation(1),
217  x_rand_pose( NULL ),
218  x_nearest_pose( NULL ),
219  local_obs_from_nearest_pose( NULL ),
220  new_state( NULL ),
221  xyzcorners_scale(0),
222  highlight_last_added_edge(false),
223  ground_xy_grid_frequency(10.0),
224  color_vehicle(0xFF,0x00,0x00,0xFF),
225  color_obstacles(0x00,0x00,0xFF,0x40),
226  color_local_obstacles(0x00,0x00,0xFF),
227  color_start(0x00, 0x00, 0x00, 0x00),
228  color_goal(0x00, 0x00, 0x00, 0x00),
229  color_ground_xy_grid(0xFF,0xFF,0xFF),
230  color_normal_edge(0x22,0x22,0x22,0x40),
231  color_last_edge(0xff,0xff,0x00),
232  color_optimal_edge(0x00,0x00,0x00),
233  width_last_edge(3.f),
234  width_normal_edge(1.f),
235  width_optimal_edge(4.f),
236  point_size_obstacles(5),
237  point_size_local_obstacles(5),
238  vehicle_shape_z(0.01),
239  vehicle_line_width(2.0),
240  draw_obstacles(true),
241  log_msg_position(0,0,0),
242  log_msg_scale(0.2)
243 
244  {
245  }
246 
248  };
249 
250  void renderMoveTree(
252  const TPlannerInput &pi,
253  const TPlannerResult &result,
254  const TRenderPlannedPathOptions &options
255  );
256 
257  void setRenderTreeVisualization();
258 
259  mrpt::utils::CTimeLogger & getProfiler() { return m_timelogger; }
260  const mrpt::nav::TListPTGPtr & getPTGs() const { return m_PTGs;}
261 
262  protected:
266  mrpt::maps::CSimplePointsMap m_local_obs; // Temporary map. Defined as a member to save realloc time between calls
267 
268  static void transformPointcloudWithSquareClipping(
269  const mrpt::maps::CPointsMap & in_map,
270  mrpt::maps::CPointsMap & out_map,
271  const mrpt::poses::CPose2D & asSeenFrom,
272  const double MAX_DIST_XY
273  );
274 
275  void spaceTransformer(
276  const mrpt::maps::CSimplePointsMap &in_obstacles,
278  const double MAX_DIST,
279  std::vector<float> &out_TPObstacles
280  );
281 
282  }; // end class PlannerRRT_SE2_TPS
283 
284  /** @} */
285  }
286 }
double vehicle_line_width
Robot line width for visualization - default 2.0.
mrpt::math::TPolygon2D robot_shape
The robot shape used when computing collisions; it&#39;s loaded from the config file/text as a single 2xN...
bool ptg_verbose
Display PTG construction info (default=true)
double maxLength
(Very sensitive parameter!) Max length of each edge path (in meters, default=1.0) ...
const mrpt::nav::TListPTGPtr & getPTGs() const
#define INVALID_NODEID
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. ...
STL namespace.
#define M_PI
Definition: bits.h:65
TMoveTreeSE2_TP move_tree
The generated motion tree that explores free space starting at "start".
double maxComputationTime
In seconds. 0 means no limit until a solution is found.
This class allows loading and storing values and vectors of different types from a configuration text...
mrpt::maps::CSimplePointsMap obstacles_points
World obstacles, as a point cloud.
double minAngBetweenNewNodes
Minimum angle [rad] to nearest node to accept creating a new one (default=15 deg) (Any of minDistance...
double vehicle_shape_z
(Default=0.01) Height (Z coordinate) for the vehicle shapes. Helps making it in the "first plane" ...
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
This is the base class for any user-defined PTG.
mrpt::nav::TListPTGPtr m_PTGs
uint64_t TNodeID
The type for node IDs in graphs of different types.
bool success
Whether the target was reached or not.
double xyzcorners_scale
A scale factor to all XYZ corners (default=0, means auto determien from vehicle shape) ...
A RGB color - 8bit.
Definition: TColor.h:25
double minDistanceBetweenNewNodes
Minimum distance [meters] to nearest node to accept creating a new one (default=0.10). (Any of minDistanceBetweenNewNodes and minAngBetweenNewNodes must be satisfied)
size_t save_3d_log_freq
Frequency (in iters) of saving tree state to debug log files viewable in SceneViewer3D (default=0...
double acceptedAngToTarget
Maximum angle from a pose to target to accept it as a valid solution (rad). (Both acceptedDistToTarge...
#define DEG2RAD
double goalBias
Probabily of picking the goal as random target (in [0,1], default=0.05)
mrpt::utils::TColor color_local_obstacles
local obstacles color
mrpt::utils::CTimeLogger m_timelogger
size_t draw_shape_decimation
(Default=1) Draw one out of N vehicle shapes along the highlighted path
mrpt::utils::CTimeLogger & getProfiler()
mrpt::utils::TColor color_start
START indication color.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double minComputationTime
In seconds. 0 means the first valid path will be returned. Otherwise, the algorithm will try to refin...
mrpt::utils::TColor color_goal
END indication color.
mrpt::utils::TNodeID highlight_path_to_node_id
Highlight the path from root towards this node (usually, the target)
A class used to store a 2D pose.
Definition: CPose2D.h:36
mrpt::math::TPose2D node_pose_t
The type of poses at nodes.
Lightweight 2D pose.
double path_cost
Total cost of the best found path (cost ~~ Euclidean distance)
This class allows the user to create, load, save, and render 3D scenes using OpenGL primitives...
Definition: COpenGLScene.h:49
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X), among other stats.
Definition: CTimeLogger.h:35
mrpt::maps::CSimplePointsMap m_local_obs
TAlgorithmParams params
Parameters specific to this path solver algorithm.
std::vector< mrpt::nav::CParameterizedTrajectoryGeneratorPtr > TListPTGPtr
A list of PTGs (smart pointers)
Lightweight 3D point.
double acceptedDistToTarget
Maximum distance from a pose to target to accept it as a valid solution (meters). (Both acceptedDistT...
Lightweight 2D point.
mrpt::utils::TNodeID best_goal_node_id
The ID of the best target node in the tree.
TP Space-based RRT path planning for SE(2) (planar) robots.
double goal_distance
Distance from best found path to goal.
std::set< mrpt::utils::TNodeID > acceptable_goal_node_ids
The set of target nodes within an acceptable distance to target (including best_goal_node_id and othe...
2D polygon, inheriting from std::vector<TPoint2D>.
double ground_xy_grid_frequency
(Default=10 meters) Set to 0 to disable



Page generated by Doxygen 1.8.11 for MRPT 1.3.2 SVN:Unversioned directory at Sun May 1 08:45:24 UTC 2016