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