Main MRPT website > C++ reference for MRPT 1.9.9
CParameterizedTrajectoryGenerator.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 #pragma once
10 
11 #include <mrpt/math/wrap2pi.h>
13 #include <mrpt/utils/round.h>
16 #include <mrpt/math/CPolygon.h>
17 #include <cstdint>
19 #include <mrpt/poses/CPose2D.h>
21 
22 namespace mrpt
23 {
24 namespace opengl
25 {
26 class CSetOfLines;
27 }
28 }
29 
30 namespace mrpt
31 {
32 namespace nav
33 {
34 /** Defines behaviors for where there is an obstacle *inside* the robot shape
35  *right at the beginning of a PTG trajectory.
36  *\ingroup nav_tpspace
37  * \sa Used in CParameterizedTrajectoryGenerator::COLLISION_BEHAVIOR
38  */
40 {
41  /** Favor getting back from too-close (almost collision) obstacles. */
43  /** Totally dissallow any movement if there is any too-close (almost
44  collision) obstacles. */
46 };
47 
48 /** \defgroup nav_tpspace TP-Space and PTG classes
49  * \ingroup mrpt_nav_grp
50  */
51 
52 /** This is the base class for any user-defined PTG.
53  * There is a class factory interface in
54  *CParameterizedTrajectoryGenerator::CreatePTG.
55  *
56  * Papers:
57  * - J.L. Blanco, J. Gonzalez-Jimenez, J.A. Fernandez-Madrigal, "Extending
58  *Obstacle Avoidance Methods through Multiple Parameter-Space Transformations",
59  *Autonomous Robots, vol. 24, no. 1, 2008.
60  *http://ingmec.ual.es/~jlblanco/papers/blanco2008eoa_DRAFT.pdf
61  *
62  * Changes history:
63  * - 30/JUN/2004: Creation (JLBC)
64  * - 16/SEP/2004: Totally redesigned.
65  * - 15/SEP/2005: Totally rewritten again, for integration into MRPT
66  *Applications Repository.
67  * - 19/JUL/2009: Simplified to use only STL data types, and created the class
68  *factory interface.
69  * - MAY/2016: Refactored into CParameterizedTrajectoryGenerator,
70  *CPTG_DiffDrive_CollisionGridBased, PTG classes renamed.
71  * - 2016-2017: Many features added to support "PTG continuation", dynamic
72  *paths depending on vehicle speeds, etc.
73  *
74  * \ingroup nav_tpspace
75  */
78 {
80  public:
81  /** Default ctor. Must call `loadFromConfigFile()` before initialization */
83  /** Destructor */
85  /** The class factory for creating a PTG from a list of parameters in a
86  *section of a given config file (physical file or in memory).
87  * Possible parameters are:
88  * - Those explained in
89  *CParameterizedTrajectoryGenerator::loadFromConfigFile()
90  * - Those explained in the specific PTG being created (see list of
91  *derived classes)
92  *
93  * `ptgClassName` can be any PTG class name which has been registered as
94  *any other
95  * mrpt::utils::CSerializable class.
96  *
97  * \exception std::logic_error On invalid or missing parameters.
98  */
100  const std::string& ptgClassName,
101  const mrpt::utils::CConfigFileBase& cfg, const std::string& sSection,
102  const std::string& sKeyPrefix);
103 
104  /** @name Virtual interface of each PTG implementation
105  * @{ */
106  /** Gets a short textual description of the PTG and its parameters */
107  virtual std::string getDescription() const = 0;
108 
109  protected:
110  /** Must be called after setting all PTG parameters and before requesting
111  * converting obstacles to TP-Space, inverseMap_WS2TP(), etc. */
112  virtual void internal_initialize(
113  const std::string& cacheFilename = std::string(),
114  const bool verbose = true) = 0;
115  /** This must be called to de-initialize the PTG if some parameter is to be
116  * changed. After changing it, call initialize again */
117  virtual void internal_deinitialize() = 0;
118 
119  public:
120  /** Computes the closest (alpha,d) TP coordinates of the trajectory point
121  * closest to the Workspace (WS)
122  * Cartesian coordinates (x,y), relative to the current robot frame.
123  * \param[in] x X coordinate of the query point, relative to the robot
124  * frame.
125  * \param[in] y Y coordinate of the query point, relative to the robot
126  * frame.
127  * \param[out] out_k Trajectory parameter index (discretized alpha value,
128  * 0-based index).
129  * \param[out] out_d Trajectory distance, normalized such that D_max
130  * becomes 1.
131  *
132  * \return true if the distance between (x,y) and the actual trajectory
133  * point is below the given tolerance (in meters).
134  */
135  virtual bool inverseMap_WS2TP(
136  double x, double y, int& out_k, double& out_normalized_d,
137  double tolerance_dist = 0.10) const = 0;
138 
139  /** Returns the same than inverseMap_WS2TP() but without any additional
140  * cost. The default implementation
141  * just calls inverseMap_WS2TP() and discards (k,d). */
142  virtual bool PTG_IsIntoDomain(double x, double y) const
143  {
144  int k;
145  double d;
146  return inverseMap_WS2TP(x, y, k, d);
147  }
148 
149  /** Returns true if a given TP-Space point maps to a unique point in
150  * Workspace, and viceversa. Default implementation returns `true`. */
151  virtual bool isBijectiveAt(uint16_t k, uint32_t step) const { return true; }
152  /** Converts a discretized "alpha" value into a feasible motion command or
153  * action. See derived classes for the meaning of these actions */
155  uint16_t k) const = 0;
156 
157  /** Returns an empty kinematic velocity command object of the type supported
158  * by this PTG.
159  * Can be queried to determine the expected kinematic interface of the PTG.
160  */
163 
164  /** Dynamic state that may affect the PTG path parameterization. \ingroup
165  * nav_reactive */
167  {
168  /** Current vehicle velocity (local frame of reference) */
170  /** Current relative target location */
172  /** Desired relative speed [0,1] at target. Default=0 */
174 
176  bool operator==(const TNavDynamicState& o) const;
177  inline bool operator!=(const TNavDynamicState& o) const
178  {
179  return !(*this == o);
180  }
181  void writeToStream(mrpt::utils::CStream& out) const;
183  };
184 
185  protected:
186  /** Invoked when `m_nav_dyn_state` has changed; gives the PTG the
187  * opportunity to react and parameterize paths depending on the
188  * instantaneous conditions */
189  virtual void onNewNavDynamicState() = 0;
190 
191  public:
192  virtual void setRefDistance(const double refDist) { refDistance = refDist; }
193  /** Access path `k` ([0,N-1]=>[-pi,pi] in alpha): number of discrete "steps"
194  * along the trajectory.
195  * May be actual steps from a numerical integration or an arbitrary small
196  * length for analytical PTGs.
197  * \sa getAlphaValuesCount() */
198  virtual size_t getPathStepCount(uint16_t k) const = 0;
199 
200  /** Access path `k` ([0,N-1]=>[-pi,pi] in alpha): pose of the vehicle at
201  * discrete step `step`.
202  * \sa getPathStepCount(), getAlphaValuesCount() */
203  virtual void getPathPose(
204  uint16_t k, uint32_t step, mrpt::math::TPose2D& p) const = 0;
205 
206  /** Access path `k` ([0,N-1]=>[-pi,pi] in alpha): traversed distance at
207  * discrete step `step`.
208  * \return Distance in pseudometers (real distance, NOT normalized to [0,1]
209  * for [0,refDist])
210  * \sa getPathStepCount(), getAlphaValuesCount() */
211  virtual double getPathDist(uint16_t k, uint32_t step) const = 0;
212 
213  /** Returns the duration (in seconds) of each "step"
214  * \sa getPathStepCount() */
215  virtual double getPathStepDuration() const = 0;
216 
217  /** Returns the maximum linear velocity expected from this PTG [m/s] */
218  virtual double getMaxLinVel() const = 0;
219  /** Returns the maximum angular velocity expected from this PTG [rad/s] */
220  virtual double getMaxAngVel() const = 0;
221 
222  /** Access path `k` ([0,N-1]=>[-pi,pi] in alpha): largest step count for
223  * which the traversed distance is < `dist`
224  * \param[in] dist Distance in pseudometers (real distance, NOT normalized
225  * to [0,1] for [0,refDist])
226  * \return false if no step fulfills the condition for the given trajectory
227  * `k` (e.g. out of reference distance).
228  * Note that, anyway, the maximum distance (closest point) is returned in
229  * `out_step`.
230  * \sa getPathStepCount(), getAlphaValuesCount() */
231  virtual bool getPathStepForDist(
232  uint16_t k, double dist, uint32_t& out_step) const = 0;
233 
234  /** Updates the radial map of closest TP-Obstacles given a single obstacle
235  * point at (ox,oy)
236  * \param [in,out] tp_obstacles A vector of length `getAlphaValuesCount()`,
237  * initialized with `initTPObstacles()` (collision-free ranges, in
238  * "pseudometers", un-normalized).
239  * \param [in] ox Obstacle point (X), relative coordinates wrt origin of
240  * the PTG.
241  * \param [in] oy Obstacle point (Y), relative coordinates wrt origin of
242  * the PTG.
243  * \note The length of tp_obstacles is not checked for efficiency since
244  * this method is potentially called thousands of times per
245  * navigation timestap, so it is left to the user responsibility to
246  * provide a valid buffer.
247  * \note `tp_obstacles` must be initialized with initTPObstacle() before
248  * call.
249  */
250  virtual void updateTPObstacle(
251  double ox, double oy, std::vector<double>& tp_obstacles) const = 0;
252 
253  /** Like updateTPObstacle() but for one direction only (`k`) in TP-Space.
254  * `tp_obstacle_k` must be initialized with initTPObstacleSingle() before
255  * call (collision-free ranges, in "pseudometers", un-normalized). */
256  virtual void updateTPObstacleSingle(
257  double ox, double oy, uint16_t k, double& tp_obstacle_k) const = 0;
258 
259  /** Loads a set of default parameters into the PTG. Users normally will call
260  * `loadFromConfigFile()` instead, this method is provided
261  * exclusively for the PTG-configurator tool. */
262  virtual void loadDefaultParams();
263 
264  /** Returns true if it is possible to stop sending velocity commands to the
265  * robot and, still, the
266  * robot controller will be able to keep following the last sent trajectory
267  * ("NOP" velocity commands).
268  * Default implementation returns "false". */
269  virtual bool supportVelCmdNOP() const;
270 
271  /** Returns true if this PTG takes into account the desired velocity at
272  * target. \sa updateNavDynamicState() */
273  virtual bool supportSpeedAtTarget() const { return false; }
274  /** Only for PTGs supporting supportVelCmdNOP(): this is the maximum time
275  * (in seconds) for which the path
276  * can be followed without re-issuing a new velcmd. Note that this is only
277  * an absolute maximum duration,
278  * navigation implementations will check for many other conditions. Default
279  * method in the base virtual class returns 0.
280  * \param path_k Queried path `k` index [0,N-1] */
281  virtual double maxTimeInVelCmdNOP(int path_k) const;
282 
283  /** Returns the actual distance (in meters) of the path, discounting
284  * possible circular loops of the path (e.g. if it comes back to the
285  * origin).
286  * Default: refDistance */
287  virtual double getActualUnloopedPathLength(uint16_t k) const
288  {
289  return this->refDistance;
290  }
291 
292  /** Query the PTG for the relative priority factor (0,1) of this PTG, in
293  * comparison to others, if the k-th path is to be selected. */
294  virtual double evalPathRelativePriority(
295  uint16_t k, double target_distance) const
296  {
297  return 1.0;
298  }
299 
300  /** Returns an approximation of the robot radius. */
301  virtual double getMaxRobotRadius() const = 0;
302  /** Returns true if the point lies within the robot shape. */
303  virtual bool isPointInsideRobotShape(
304  const double x, const double y) const = 0;
305 
306  /** Evals the clearance from an obstacle (ox,oy) in coordinates relative to
307  * the robot center. Zero or negative means collision. */
308  virtual double evalClearanceToRobotShape(
309  const double ox, const double oy) const = 0;
310 
311  /** @} */ // --- end of virtual methods
312 
313  /** To be invoked by the navigator *before* each navigation step, to let the
314  * PTG to react to changing dynamic conditions. * \sa
315  * onNewNavDynamicState(), m_nav_dyn_state */
317  const TNavDynamicState& newState, const bool force_update = false);
319  {
320  return m_nav_dyn_state;
321  }
322 
323  /** The path used as defaul output in, for example, debugDumpInFiles.
324  * (Default="./reactivenav.logs/") */
326 
327  /** Must be called after setting all PTG parameters and before requesting
328  * converting obstacles to TP-Space, inverseMap_WS2TP(), etc. */
329  void initialize(
330  const std::string& cacheFilename = std::string(),
331  const bool verbose = true);
332  /** This must be called to de-initialize the PTG if some parameter is to be
333  * changed. After changing it, call initialize again */
334  void deinitialize();
335  /** Returns true if `initialize()` has been called and there was no errors,
336  * so the PTG is ready to be queried for paths, obstacles, etc. */
337  bool isInitialized() const;
338 
339  /** Get the number of different, discrete paths in this family */
341  /** Get the number of different, discrete paths in this family */
343  /** Alpha value for the discrete corresponding value \sa alpha2index */
344  double index2alpha(uint16_t k) const;
345  static double index2alpha(uint16_t k, const unsigned int num_paths);
346 
347  /** Discrete index value for the corresponding alpha value \sa index2alpha
348  */
349  uint16_t alpha2index(double alpha) const;
350  static uint16_t alpha2index(double alpha, const unsigned int num_paths);
351 
352  inline double getRefDistance() const { return refDistance; }
353  /** Resizes and populates the initial appropriate contents in a vector of
354  * tp-obstacles (collision-free ranges, in "pseudometers", un-normalized).
355  * \sa updateTPObstacle() */
356  void initTPObstacles(std::vector<double>& TP_Obstacles) const;
357  void initTPObstacleSingle(uint16_t k, double& TP_Obstacle_k) const;
358 
359  /** When used in path planning, a multiplying factor (default=1.0) for the
360  * scores for this PTG. Assign values <1 to PTGs with low priority. */
361  double getScorePriority() const { return m_score_priority; }
362  void setScorePriorty(double prior) { m_score_priority = prior; }
363  unsigned getClearanceStepCount() const { return m_clearance_num_points; }
364  void setClearanceStepCount(const unsigned res)
365  {
367  }
368 
369  unsigned getClearanceDecimatedPaths() const
370  {
372  }
373  void setClearanceDecimatedPaths(const unsigned num)
374  {
376  }
377 
378  /** Returns the representation of one trajectory of this PTG as a 3D OpenGL
379  * object (a simple curved line).
380  * \param[in] k The 0-based index of the selected trajectory (discrete
381  * "alpha" parameter).
382  * \param[out] gl_obj Output object.
383  * \param[in] decimate_distance Minimum distance between path points (in
384  * meters).
385  * \param[in] max_path_distance If >=0, cut the path at this distance (in
386  * meters).
387  */
388  virtual void renderPathAsSimpleLine(
389  const uint16_t k, mrpt::opengl::CSetOfLines& gl_obj,
390  const double decimate_distance = 0.1,
391  const double max_path_distance = -1.0) const;
392 
393  /** Dump PTG trajectories in four text files:
394  * `./reactivenav.logs/PTGs/PTG%i_{x,y,phi,d}.txt`
395  * Text files are loadable from MATLAB/Octave, and can be visualized with
396  * the script `[MRPT_DIR]/scripts/viewPTG.m`
397  * \note The directory "./reactivenav.logs/PTGs" will be created if doesn't
398  * exist.
399  * \return false on any error writing to disk.
400  * \sa OUTPUT_DEBUG_PATH_PREFIX
401  */
402  bool debugDumpInFiles(const std::string& ptg_name) const;
403 
404  /** Parameters accepted by this base class:
405  * - `${sKeyPrefix}num_paths`: The number of different paths in this
406  * family (number of discrete `alpha` values).
407  * - `${sKeyPrefix}ref_distance`: The maximum distance in PTGs [meters]
408  * - `${sKeyPrefix}score_priority`: When used in path planning, a
409  * multiplying factor (default=1.0) for the scores for this PTG. Assign
410  * values <1 to PTGs with low priority.
411  */
412  virtual void loadFromConfigFile(
413  const mrpt::utils::CConfigFileBase& cfg,
414  const std::string& sSection) override;
415  virtual void saveToConfigFile(
417  const std::string& sSection) const override;
418 
419  /** Auxiliary function for rendering */
420  virtual void add_robotShape_to_setOfLines(
421  mrpt::opengl::CSetOfLines& gl_shape,
422  const mrpt::poses::CPose2D& origin = mrpt::poses::CPose2D()) const = 0;
423 
424  /** Defines the behavior when there is an obstacle *inside* the robot shape
425  * right at the beginning of a PTG trajectory.
426  * Default value: COLL_BEH_BACK_AWAY
427  */
429 
430  /** Must be called to resize a CD to its correct size, before calling
431  * updateClearance() */
432  void initClearanceDiagram(ClearanceDiagram& cd) const;
433 
434  /** Updates the clearance diagram given one (ox,oy) obstacle point, in
435  * coordinates relative
436  * to the PTG path origin.
437  * \param[in,out] cd The clearance will be updated here.
438  * \sa m_clearance_dist_resolution
439  */
440  void updateClearance(
441  const double ox, const double oy, ClearanceDiagram& cd) const;
442  void updateClearancePost(
443  ClearanceDiagram& cd, const std::vector<double>& TP_obstacles) const;
444 
445  protected:
446  double refDistance;
447  /** The number of discrete values for "alpha" between -PI and +PI. */
450  /** Number of steps for the piecewise-constant approximation of clearance
451  * from TPS distances [0,1] (Default=5) \sa updateClearance() */
453  /** Number of paths for the decimated paths analysis of clearance */
455  /** Updated before each nav step by */
457  /** Update in updateNavDynamicState(), contains the path index (k) for the
458  * target. */
460 
461  static const uint16_t INVALID_PTG_PATH_INDEX = static_cast<uint16_t>(-1);
462 
464 
465  /** To be called by implementors of updateTPObstacle() and
466  * updateTPObstacleSingle() to
467  * honor the user settings regarding COLLISION_BEHAVIOR.
468  * \param new_tp_obs_dist The newly determiend collision-free ranges, in
469  * "pseudometers", un-normalized, for some "k" direction.
470  * \param inout_tp_obs The target where to store the new TP-Obs distance,
471  * if it fulfills the criteria determined by the collision behavior.
472  */
474  const double ox, const double oy, const double new_tp_obs_dist,
475  double& inout_tp_obs) const;
476 
478  virtual void internal_writeToStream(mrpt::utils::CStream& out) const;
479 
480  public:
481  /** Evals the robot clearance for each robot pose along path `k`, for the
482  * real distances in
483  * the key of the map<>, then keep in the map value the minimum of its
484  * current stored clearance,
485  * or the computed clearance. In case of collision, clearance is zero.
486  * \param treat_as_obstacle true: normal use for obstacles; false: compute
487  * shortest distances to a target point (no collision)
488  */
489  virtual void evalClearanceSingleObstacle(
490  const double ox, const double oy, const uint16_t k,
491  ClearanceDiagram::dist2clearance_t& inout_realdist2clearance,
492  bool treat_as_obstacle = true) const;
493 
494 }; // end of class
495 
496 /** A list of PTGs (smart pointers) */
497 using TListPTGPtr =
498  std::vector<mrpt::nav::CParameterizedTrajectoryGenerator::Ptr>;
499 
500 /** Base class for all PTGs using a 2D polygonal robot shape model.
501  * \ingroup nav_tpspace
502  */
504 {
505  public:
507  virtual ~CPTG_RobotShape_Polygonal();
508 
509  /** @name Robot shape
510  * @{ **/
511  /** Robot shape must be set before initialization, either from ctor params
512  * or via this method. */
513  void setRobotShape(const mrpt::math::CPolygon& robotShape);
515  double getMaxRobotRadius() const override;
516  virtual double evalClearanceToRobotShape(
517  const double ox, const double oy) const override;
518  /** @} */
519  bool isPointInsideRobotShape(const double x, const double y) const override;
521  mrpt::opengl::CSetOfLines& gl_shape,
522  const mrpt::poses::CPose2D& origin =
523  mrpt::poses::CPose2D()) const override;
524 
525  protected:
526  /** Will be called whenever the robot shape is set / updated */
527  virtual void internal_processNewRobotShape() = 0;
531  const mrpt::utils::CConfigFileBase& source, const std::string& section);
532  void saveToConfigFile(
534  const std::string& sSection) const override;
537  /** Loads a set of default parameters; provided exclusively for the
538  * PTG-configurator tool. */
539  void loadDefaultParams() override;
540 };
541 
542 /** Base class for all PTGs using a 2D circular robot shape model.
543  * \ingroup nav_tpspace
544  */
546 {
547  public:
549  virtual ~CPTG_RobotShape_Circular();
550 
551  /** @name Robot shape
552  * @{ **/
553  /** Robot shape must be set before initialization, either from ctor params
554  * or via this method. */
555  void setRobotShapeRadius(const double robot_radius);
556  double getRobotShapeRadius() const { return m_robotRadius; }
557  double getMaxRobotRadius() const override;
558  virtual double evalClearanceToRobotShape(
559  const double ox, const double oy) const override;
560  /** @} */
562  mrpt::opengl::CSetOfLines& gl_shape,
563  const mrpt::poses::CPose2D& origin =
564  mrpt::poses::CPose2D()) const override;
565  bool isPointInsideRobotShape(const double x, const double y) const override;
566 
567  protected:
568  /** Will be called whenever the robot shape is set / updated */
569  virtual void internal_processNewRobotShape() = 0;
572  const mrpt::utils::CConfigFileBase& source, const std::string& section);
573  void saveToConfigFile(
575  const std::string& sSection) const override;
578  /** Loads a set of default parameters; provided exclusively for the
579  * PTG-configurator tool. */
580  void loadDefaultParams() override;
581 };
582 }
583 }
double index2alpha(uint16_t k) const
Alpha value for the discrete corresponding value.
virtual bool supportSpeedAtTarget() const
Returns true if this PTG takes into account the desired velocity at target.
void internal_shape_saveToStream(mrpt::utils::CStream &out) const
void initialize(const std::string &cacheFilename=std::string(), const bool verbose=true)
Must be called after setting all PTG parameters and before requesting converting obstacles to TP-Spac...
virtual bool getPathStepForDist(uint16_t k, double dist, uint32_t &out_step) const =0
Access path k ([0,N-1]=>[-pi,pi] in alpha): largest step count for which the traversed distance is < ...
virtual bool supportVelCmdNOP() const
Returns true if it is possible to stop sending velocity commands to the robot and, still, the robot controller will be able to keep following the last sent trajectory ("NOP" velocity commands).
GLclampf GLclampf GLclampf alpha
Definition: glext.h:3525
void loadDefaultParams() override
Loads a set of default parameters; provided exclusively for the PTG-configurator tool.
virtual void internal_initialize(const std::string &cacheFilename=std::string(), const bool verbose=true)=0
Must be called after setting all PTG parameters and before requesting converting obstacles to TP-Spac...
virtual void updateTPObstacleSingle(double ox, double oy, uint16_t k, double &tp_obstacle_k) const =0
Like updateTPObstacle() but for one direction only (k) in TP-Space.
unsigned __int16 uint16_t
Definition: rptypes.h:44
void loadShapeFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &section)
virtual double getPathStepDuration() const =0
Returns the duration (in seconds) of each "step".
void saveToConfigFile(mrpt::utils::CConfigFileBase &cfg, const std::string &sSection) const override
This method saves the options to a ".ini"-like file or memory-stored string list. ...
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:44
Base class for all PTGs using a 2D circular robot shape model.
virtual void renderPathAsSimpleLine(const uint16_t k, mrpt::opengl::CSetOfLines &gl_obj, const double decimate_distance=0.1, const double max_path_distance=-1.0) const
Returns the representation of one trajectory of this PTG as a 3D OpenGL object (a simple curved line)...
virtual void saveToConfigFile(mrpt::utils::CConfigFileBase &cfg, const std::string &sSection) const override
This method saves the options to a ".ini"-like file or memory-stored string list. ...
virtual bool isPointInsideRobotShape(const double x, const double y) const =0
Returns true if the point lies within the robot shape.
virtual bool isBijectiveAt(uint16_t k, uint32_t step) const
Returns true if a given TP-Space point maps to a unique point in Workspace, and viceversa.
virtual void internal_processNewRobotShape()=0
Will be called whenever the robot shape is set / updated.
void initTPObstacles(std::vector< double > &TP_Obstacles) const
Resizes and populates the initial appropriate contents in a vector of tp-obstacles (collision-free ra...
void loadDefaultParams() override
Loads a set of default parameters; provided exclusively for the PTG-configurator tool.
Favor getting back from too-close (almost collision) obstacles.
virtual double maxTimeInVelCmdNOP(int path_k) const
Only for PTGs supporting supportVelCmdNOP(): this is the maximum time (in seconds) for which the path...
virtual double getMaxAngVel() const =0
Returns the maximum angular velocity expected from this PTG [rad/s].
A wrapper of a TPolygon2D class, implementing CSerializable.
Definition: CPolygon.h:22
void updateClearancePost(ClearanceDiagram &cd, const std::vector< double > &TP_obstacles) const
void updateNavDynamicState(const TNavDynamicState &newState, const bool force_update=false)
To be invoked by the navigator before each navigation step, to let the PTG to react to changing dynam...
uint16_t m_nav_dyn_state_target_k
Update in updateNavDynamicState(), contains the path index (k) for the target.
Clearance information for one particular PTG and one set of obstacles.
virtual size_t getPathStepCount(uint16_t k) const =0
Access path k ([0,N-1]=>[-pi,pi] in alpha): number of discrete "steps" along the trajectory.
uint16_t getPathCount() const
Get the number of different, discrete paths in this family.
void add_robotShape_to_setOfLines(mrpt::opengl::CSetOfLines &gl_shape, const mrpt::poses::CPose2D &origin=mrpt::poses::CPose2D()) const override
Auxiliary function for rendering.
virtual double getPathDist(uint16_t k, uint32_t step) const =0
Access path k ([0,N-1]=>[-pi,pi] in alpha): traversed distance at discrete step step.
virtual void getPathPose(uint16_t k, uint32_t step, mrpt::math::TPose2D &p) const =0
Access path k ([0,N-1]=>[-pi,pi] in alpha): pose of the vehicle at discrete step step.
void loadShapeFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &section)
GLuint GLuint num
Definition: glext.h:7278
bool debugDumpInFiles(const std::string &ptg_name) const
Dump PTG trajectories in four text files: `.
virtual void internal_writeToStream(mrpt::utils::CStream &out) const
This class allows loading and storing values and vectors of different types from a configuration text...
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
void internal_TPObsDistancePostprocess(const double ox, const double oy, const double new_tp_obs_dist, double &inout_tp_obs) const
To be called by implementors of updateTPObstacle() and updateTPObstacleSingle() to honor the user set...
void initTPObstacleSingle(uint16_t k, double &TP_Obstacle_k) const
virtual void loadFromConfigFile(const mrpt::utils::CConfigFileBase &cfg, const std::string &sSection) override
Parameters accepted by this base class:
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
virtual void loadDefaultParams()
Loads a set of default parameters into the PTG.
std::vector< mrpt::nav::CParameterizedTrajectoryGenerator::Ptr > TListPTGPtr
A list of PTGs (smart pointers)
const mrpt::math::CPolygon & getRobotShape() const
virtual mrpt::kinematics::CVehicleVelCmd::Ptr directionToMotionCommand(uint16_t k) const =0
Converts a discretized "alpha" value into a feasible motion command or action.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This is the base class for any user-defined PTG.
static std::string OUTPUT_DEBUG_PATH_PREFIX
The path used as defaul output in, for example, debugDumpInFiles.
virtual double evalClearanceToRobotShape(const double ox, const double oy) const override
Evals the clearance from an obstacle (ox,oy) in coordinates relative to the robot center...
virtual void internal_readFromStream(mrpt::utils::CStream &in)
double getMaxRobotRadius() const override
Returns an approximation of the robot radius.
std::map< double, double > dist2clearance_t
[TPS_distance] => normalized_clearance_for_exactly_that_robot_pose
virtual void internal_processNewRobotShape()=0
Will be called whenever the robot shape is set / updated.
void internal_shape_saveToStream(mrpt::utils::CStream &out) const
void internal_shape_loadFromStream(mrpt::utils::CStream &in)
virtual double evalPathRelativePriority(uint16_t k, double target_distance) const
Query the PTG for the relative priority factor (0,1) of this PTG, in comparison to others...
bool isInitialized() const
Returns true if initialize() has been called and there was no errors, so the PTG is ready to be queri...
Base class for all PTGs using a 2D polygonal robot shape model.
mrpt::math::TTwist2D curVelLocal
Current vehicle velocity (local frame of reference)
virtual void onNewNavDynamicState()=0
Invoked when m_nav_dyn_state has changed; gives the PTG the opportunity to react and parameterize pat...
void setRobotShapeRadius(const double robot_radius)
Robot shape must be set before initialization, either from ctor params or via this method...
PTG_collision_behavior_t
Defines behaviors for where there is an obstacle inside the robot shape right at the beginning of a P...
void initClearanceDiagram(ClearanceDiagram &cd) const
Must be called to resize a CD to its correct size, before calling updateClearance() ...
mrpt::math::TPose2D relTarget
Current relative target location.
virtual mrpt::kinematics::CVehicleVelCmd::Ptr getSupportedKinematicVelocityCommand() const =0
Returns an empty kinematic velocity command object of the type supported by this PTG.
void internal_shape_loadFromStream(mrpt::utils::CStream &in)
GLsizei const GLchar ** string
Definition: glext.h:4101
virtual double evalClearanceToRobotShape(const double ox, const double oy) const override
Evals the clearance from an obstacle (ox,oy) in coordinates relative to the robot center...
uint16_t m_clearance_num_points
Number of steps for the piecewise-constant approximation of clearance from TPS distances [0...
uint16_t getAlphaValuesCount() const
Get the number of different, discrete paths in this family.
virtual double getActualUnloopedPathLength(uint16_t k) const
Returns the actual distance (in meters) of the path, discounting possible circular loops of the path ...
static PTG_collision_behavior_t COLLISION_BEHAVIOR
Defines the behavior when there is an obstacle inside the robot shape right at the beginning of a PTG...
Totally dissallow any movement if there is any too-close (almost collision) obstacles.
void updateClearance(const double ox, const double oy, ClearanceDiagram &cd) const
Updates the clearance diagram given one (ox,oy) obstacle point, in coordinates relative to the PTG pa...
void setRobotShape(const mrpt::math::CPolygon &robotShape)
Robot shape must be set before initialization, either from ctor params or via this method...
void deinitialize()
This must be called to de-initialize the PTG if some parameter is to be changed.
virtual void updateTPObstacle(double ox, double oy, std::vector< double > &tp_obstacles) const =0
Updates the radial map of closest TP-Obstacles given a single obstacle point at (ox,oy)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double getScorePriority() const
When used in path planning, a multiplying factor (default=1.0) for the scores for this PTG...
bool isPointInsideRobotShape(const double x, const double y) const override
Returns true if the point lies within the robot shape.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
uint16_t m_clearance_decimated_paths
Number of paths for the decimated paths analysis of clearance.
virtual double getMaxLinVel() const =0
Returns the maximum linear velocity expected from this PTG [m/s].
virtual void evalClearanceSingleObstacle(const double ox, const double oy, const uint16_t k, ClearanceDiagram::dist2clearance_t &inout_realdist2clearance, bool treat_as_obstacle=true) const
Evals the robot clearance for each robot pose along path k, for the real distances in the key of the ...
GLuint in
Definition: glext.h:7274
Lightweight 2D pose.
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
virtual void add_robotShape_to_setOfLines(mrpt::opengl::CSetOfLines &gl_shape, const mrpt::poses::CPose2D &origin=mrpt::poses::CPose2D()) const =0
Auxiliary function for rendering.
GLenum GLint GLint y
Definition: glext.h:3538
virtual double evalClearanceToRobotShape(const double ox, const double oy) const =0
Evals the clearance from an obstacle (ox,oy) in coordinates relative to the robot center...
bool isPointInsideRobotShape(const double x, const double y) const override
Returns true if the point lies within the robot shape.
GLuint res
Definition: glext.h:7268
GLenum GLint x
Definition: glext.h:3538
std::shared_ptr< CVehicleVelCmd > Ptr
A set of independent lines (or segments), one line with its own start and end positions (X...
Definition: CSetOfLines.h:35
unsigned __int32 uint32_t
Definition: rptypes.h:47
TNavDynamicState m_nav_dyn_state
Updated before each nav step by.
Dynamic state that may affect the PTG path parameterization.
GLfloat GLfloat p
Definition: glext.h:6305
void saveToConfigFile(mrpt::utils::CConfigFileBase &cfg, const std::string &sSection) const override
This method saves the options to a ".ini"-like file or memory-stored string list. ...
virtual void internal_deinitialize()=0
This must be called to de-initialize the PTG if some parameter is to be changed.
This is a virtual base class for sets of options than can be loaded from and/or saved to configuratio...
uint16_t m_alphaValuesCount
The number of discrete values for "alpha" between -PI and +PI.
virtual double getMaxRobotRadius() const =0
Returns an approximation of the robot radius.
void add_robotShape_to_setOfLines(mrpt::opengl::CSetOfLines &gl_shape, const mrpt::poses::CPose2D &origin=mrpt::poses::CPose2D()) const override
Auxiliary function for rendering.
virtual bool PTG_IsIntoDomain(double x, double y) const
Returns the same than inverseMap_WS2TP() but without any additional cost.
virtual bool inverseMap_WS2TP(double x, double y, int &out_k, double &out_normalized_d, double tolerance_dist=0.10) const =0
Computes the closest (alpha,d) TP coordinates of the trajectory point closest to the Workspace (WS) C...
uint16_t alpha2index(double alpha) const
Discrete index value for the corresponding alpha value.
static CParameterizedTrajectoryGenerator * CreatePTG(const std::string &ptgClassName, const mrpt::utils::CConfigFileBase &cfg, const std::string &sSection, const std::string &sKeyPrefix)
The class factory for creating a PTG from a list of parameters in a section of a given config file (p...
double getMaxRobotRadius() const override
Returns an approximation of the robot radius.
virtual std::string getDescription() const =0
Gets a short textual description of the PTG and its parameters.



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