Main MRPT website > C++ reference
MRPT logo
CHolonomicND.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 #ifndef CHolonomicND_H
10 #define CHolonomicND_H
11 
14 
15 namespace mrpt
16 {
17  namespace nav
18  {
19  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(CLogFileRecord_ND, CHolonomicLogFileRecord, NAV_IMPEXP)
20 
21  /** An implementation of the holonomic reactive navigation method "Nearness-Diagram".
22  * The algorithm "Nearness-Diagram" was proposed in:
23  *
24  * Nearness diagram (ND) navigation: collision avoidance in troublesome scenarios, IEEE Transactions on
25  * Robotics and Automation, Minguez, J. and Montano, L., vol. 20, no. 1, pp. 45-59, 2004.
26  *
27  * These are the optional parameters of the method which can be set by means of a configuration file passed to the constructor or to CHolonomicND::initialize() or directly in \a CHolonomicND::options
28  *
29  * \code
30  * [ND_CONFIG]
31  * factorWeights=1.0 0.5 2.0 0.4
32  * // 1: Free space
33  * // 2: Dist. in sectors
34  * // 3: Closer to target (euclidean)
35  * // 4: Hysteresis
36  * WIDE_GAP_SIZE_PERCENT = 0.25
37  * MAX_SECTOR_DIST_FOR_D2_PERCENT = 0.25
38  * RISK_EVALUATION_SECTORS_PERCENT = 0.25
39  * RISK_EVALUATION_DISTANCE = 0.15 // In normalized ps-meters [0,1]
40  * TARGET_SLOW_APPROACHING_DISTANCE = 0.60 // For stopping gradually
41  * TOO_CLOSE_OBSTACLE = 0.02 // In normalized ps-meters
42  * \endcode
43  *
44  * \sa CAbstractHolonomicReactiveMethod,CReactiveNavigationSystem
45  * \ingroup mrpt_nav_grp
46  */
48  {
49  public:
51  public:
52  /** Initialize the parameters of the navigator, from some configuration file, or default values if set to NULL.
53  */
54  CHolonomicND( const mrpt::utils::CConfigFileBase *INI_FILE = NULL );
55 
56  /** This method performs the holonomic navigation itself.
57  * \param target [IN] The relative location (x,y) of target point.
58  * \param obstacles [IN] Distance to obstacles from robot location (0,0). First index refers to -PI direction, and last one to +PI direction. Distances can be dealed as "meters", although they are "pseudometers", see note below.
59  * \param maxRobotSpeed [IN] Maximum robot speed, in "pseudometers/sec". See note below.
60  * \param desiredDirection [OUT] The desired motion direction, in the range [-PI,PI]
61  * \param desiredSpeed [OUT] The desired motion speed in that direction, in "pseudometers"/sec. (See note below)
62  * \param logRecord [IN/OUT] A placeholder for a pointer to a log record with extra info about the execution. Set to NULL if not required. User <b>must free memory</b> using "delete logRecord" after using it.
63  *
64  * NOTE: With "pseudometers" we refer to the distance unit in TP-Space, thus:
65  * <br><center><code>pseudometer<sup>2</sup>= meter<sup>2</sup> + (rad ยท r)<sup>2</sup></code><br></center>
66  */
67  void navigate( const mrpt::math::TPoint2D &target,
68  const std::vector<float> &obstacles,
69  double maxRobotSpeed,
70  double &desiredDirection,
71  double &desiredSpeed,
72  CHolonomicLogFileRecordPtr &logRecord );
73 
74  /** The structure used to store a detected gap in obstacles.
75  */
76  struct TGap
77  {
78  unsigned int ini;
79  unsigned int end;
80  double maxDistance;
81  double minDistance;
82  unsigned int representative_sector;
83  };
84 
85  typedef std::vector<TGap> TGapArray;
86 
87  /** The set of posible situations for each trajectory. (mrpt::utils::TEnumType works with this enum)
88  */
90  {
91  SITUATION_TARGET_DIRECTLY = 1,
94  SITUATION_NO_WAY_FOUND
95  };
96 
97  /** Initialize the parameters of the navigator.
98  */
99  void initialize( const mrpt::utils::CConfigFileBase &INI_FILE )
100  {
101  options.loadFromConfigFile(INI_FILE, std::string("ND_CONFIG"));
102  }
103 
104  /** Algorithm options */
106  {
107  double TOO_CLOSE_OBSTACLE,WIDE_GAP_SIZE_PERCENT,RISK_EVALUATION_SECTORS_PERCENT;
108  double RISK_EVALUATION_DISTANCE,MAX_SECTOR_DIST_FOR_D2_PERCENT;
110  std::vector<double> factorWeights; //!< Vector of 4 weights: [0]=Free space, [1]=Dist. in sectors, [2]=Closer to target (Euclidean), [3]=Hysteresis
111 
112 
113  TOptions();
114  virtual void saveToConfigFile(mrpt::utils::CConfigFileBase &cfg ,const std::string &section) const;
115  virtual void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source,const std::string &section);
116  };
117 
118  TOptions options; //!< Parameters of the algorithm (can be set manually or loaded from CHolonomicND::initialize or options.loadFromConfigFile(), etc.)
119 
120  private:
122 
123  unsigned int direction2sector(const double a, const unsigned int N);
124 
125  /** Find gaps in the obtacles.
126  */
127  void gapsEstimator(
128  const std::vector<float> & obstacles,
129  const mrpt::math::TPoint2D & in_target,
130  TGapArray & gaps );
131 
132 
133  /** Search the best gap.
134  */
135  void searchBestGap(
136  const std::vector<float> & in_obstacles,
137  const double in_maxObsRange,
138  const TGapArray & in_gaps,
139  const mrpt::math::TPoint2D & in_target,
140  unsigned int & out_selDirection,
141  double & out_selEvaluation,
142  TSituations & out_situation,
143  double & out_riskEvaluation,
144  CLogFileRecord_NDPtr log);
145 
146  /** Fills in the representative sector field in the gap structure:
147  */
148  void calcRepresentativeSectorForGap(
149  TGap & gap,
150  const mrpt::math::TPoint2D & target,
151  const std::vector<float> & obstacles);
152 
153  /** Evaluate each gap:
154  */
155  void evaluateGaps(
156  const std::vector<float> & in_obstacles,
157  const float in_maxObsRange,
158  const TGapArray & in_gaps,
159  const unsigned int TargetSector,
160  const float TargetDist,
161  std::vector<double> & out_gaps_evaluation );
162 
163  }; // end of CHolonomicND
164 
165  /** A class for storing extra information about the execution of
166  * CHolonomicND navigation.
167  * \sa CHolonomicND, CHolonomicLogFileRecord
168  */
170  {
172 
173  public:
174  /** Member data.
175  */
177  std::vector<double> gaps_eval;
178  int32_t selectedSector;
179  double evaluation;
181  CHolonomicND::TSituations situation;
182  };
184 
185  } // end namespace
186 
187  // Specializations MUST occur at the same namespace:
188  namespace utils
189  {
190  template <>
192  {
194  static void fill(bimap<enum_t,std::string> &m_map)
195  {
196  m_map.insert(nav::CHolonomicND::SITUATION_TARGET_DIRECTLY, "SITUATION_TARGET_DIRECTLY");
197  m_map.insert(nav::CHolonomicND::SITUATION_SMALL_GAP, "SITUATION_SMALL_GAP");
198  m_map.insert(nav::CHolonomicND::SITUATION_WIDE_GAP, "SITUATION_WIDE_GAP");
199  m_map.insert(nav::CHolonomicND::SITUATION_NO_WAY_FOUND, "SITUATION_NO_WAY_FOUND");
200  }
201  };
202  } // End of namespace
203 }
204 
205 
206 #endif
207 
208 
209 
std::vector< int32_t > vector_int
Definition: types_simple.h:20
#define MRPT_MAKE_ALIGNED_OPERATOR_NEW
Definition: memory.h:112
An implementation of the holonomic reactive navigation method "Nearness-Diagram". ...
Definition: CHolonomicND.h:47
unsigned int m_last_selected_sector
Definition: CHolonomicND.h:121
A base class for holonomic reactive navigation methods.
vector_int gaps_ini
Member data.
Definition: CHolonomicND.h:176
std::vector< TGap > TGapArray
Definition: CHolonomicND.h:85
STL namespace.
CHolonomicND::TSituations situation
Definition: CHolonomicND.h:181
Only specializations of this class are defined for each enum type of interest.
Definition: TEnumType.h:23
This class allows loading and storing values and vectors of different types from a configuration text...
TOptions options
Parameters of the algorithm (can be set manually or loaded from CHolonomicND::initialize or options...
Definition: CHolonomicND.h:118
unsigned int representative_sector
Definition: CHolonomicND.h:82
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
A base class for log records for different holonomic navigation methods.
TSituations
The set of posible situations for each trajectory.
Definition: CHolonomicND.h:89
A bidirectional version of std::map, declared as bimap and which actually contains two std...
Definition: bimap.h:27
std::vector< double > factorWeights
Vector of 4 weights: [0]=Free space, [1]=Dist. in sectors, [2]=Closer to target (Euclidean), [3]=Hysteresis.
Definition: CHolonomicND.h:110
static void fill(bimap< enum_t, std::string > &m_map)
Definition: CHolonomicND.h:194
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
The structure used to store a detected gap in obstacles.
Definition: CHolonomicND.h:76
A class for storing extra information about the execution of CHolonomicND navigation.
Definition: CHolonomicND.h:169
void insert(const KEY &k, const VALUE &v)
Insert a new pair KEY<->VALUE in the bi-map.
Definition: bimap.h:68
std::vector< double > gaps_eval
Definition: CHolonomicND.h:177
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
Lightweight 2D point.
This is a virtual base class for sets of options than can be loaded from and/or saved to configuratio...
void initialize(const mrpt::utils::CConfigFileBase &INI_FILE)
Initialize the parameters of the navigator.
Definition: CHolonomicND.h:99



Page generated by Doxygen 1.8.9.1 for MRPT 1.3.0 SVN: at Sun Sep 13 03:55:12 UTC 2015