28 m_alphaValuesCount(0),
29 m_score_priority(1.0),
30 m_clearance_num_points(5),
31 m_clearance_decimated_paths(15),
33 m_nav_dyn_state_target_k(INVALID_PTG_PATH_INDEX),
34 m_is_initialized(false)
81 const int WN = 25, WV = 30;
83 cfg.
write(sSection,
"num_paths",
m_alphaValuesCount, WN,WV,
"Number of discrete paths (`resolution`) in the PTG");
84 cfg.
write(sSection,
"refDistance",
refDistance, WN,WV,
"Maximum distance (meters) for building trajectories (visibility range)");
85 cfg.
write(sSection,
"score_priority",
m_score_priority, WN,WV,
"When used in path planning, a multiplying factor (default=1.0) for the scores for this PTG. Assign values <1 to PTGs with low priority.");
86 cfg.
write(sSection,
"clearance_num_points",
m_clearance_num_points, WN, WV,
"Number of steps for the piecewise-constant approximation of clearance (Default=5).");
87 cfg.
write(sSection,
"clearance_decimated_paths",
m_clearance_decimated_paths, WN, WV,
"Number of decimated paths for estimation of clearance (Default=15).");
119 bool old_use_approx_clearance;
120 in >> old_use_approx_clearance;
147 return M_PI * (-1.0 + 2.0 * (k + 0.5) / num_paths);
160 if (k >=
static_cast<int>(num_paths) ) k = num_paths - 1;
172 const double decimate_distance,
173 const double max_path_distance)
const
179 double last_added_dist = 0.0;
180 for (
size_t n=0;
n<nPointsInPath;
n++)
185 if (max_path_distance>=0.0 && d>=max_path_distance)
break;
187 if (d<last_added_dist+decimate_distance &&
n!=0)
232 const string sFilTxt_x =
mrpt::format(
"%s/PTGs/PTG%s_x.txt",sPath,ptg_name.c_str() );
233 const string sFilTxt_y =
mrpt::format(
"%s/PTGs/PTG%s_y.txt",sPath,ptg_name.c_str() );
234 const string sFilTxt_phi =
mrpt::format(
"%s/PTGs/PTG%s_phi.txt",sPath,ptg_name.c_str() );
235 const string sFilTxt_t =
mrpt::format(
"%s/PTGs/PTG%s_t.txt",sPath,ptg_name.c_str() );
236 const string sFilTxt_d =
mrpt::format(
"%s/PTGs/PTG%s_d.txt",sPath,ptg_name.c_str() );
238 ofstream fx(sFilTxt_x.c_str());
if (!fx.is_open())
return false;
239 ofstream fy(sFilTxt_y.c_str());
if (!fy.is_open())
return false;
240 ofstream fp(sFilTxt_phi.c_str());
if (!fp.is_open())
return false;
241 ofstream fd(sFilTxt_d.c_str());
if (!fd.is_open())
return false;
246 fx <<
"% PTG data file for 'x'. Each row is the trajectory for a different 'alpha' parameter value." << endl;
247 fy <<
"% PTG data file for 'y'. Each row is the trajectory for a different 'alpha' parameter value." << endl;
248 fp <<
"% PTG data file for 'phi'. Each row is the trajectory for a different 'alpha' parameter value." << endl;
249 fd <<
"% PTG data file for 'd'. Each row is the trajectory for a different 'alpha' parameter value." << endl;
251 vector<size_t> path_length(nPaths);
252 for (
size_t k=0;k<nPaths;k++)
256 for (
size_t k=0;k<nPaths;k++)
257 maxPoints = max( maxPoints, path_length[k] );
259 for (
size_t k=0;k<nPaths;k++)
261 for (
size_t n=0;
n< maxPoints;
n++)
263 const size_t nn =
std::min(
n, path_length[k]-1 );
305 double target_norm_d;
308 if (target_norm_d>0.01 && target_norm_d<0.99 && target_k>=0 && target_k<
m_alphaValuesCount)
321 const std::string sCache = !cacheFilename.empty() ?
339 if (!is_obs_inside_robot_shape)
383 for (
double step_pointer_dbl = 0.0; step_pointer_dbl < numPathSteps; step_pointer_dbl += numStepsPerIncr)
386 const double dist_over_path = this->
getPathDist(real_k, step);
387 cl_path[dist_over_path] = 1.0;
413 bool had_collision =
false;
416 ASSERT_(numPathSteps > inout_realdist2clearance.size());
418 const double numStepsPerIncr = (numPathSteps - 1.0) / (inout_realdist2clearance.size());
420 double step_pointer_dbl = 0.0;
424 for (
auto &e : inout_realdist2clearance)
426 step_pointer_dbl += numStepsPerIncr;
428 const double dist_over_path = e.first;
429 double & inout_clearance = e.second;
434 inout_clearance = .0;
443 const double this_clearance = treat_as_obstacle ?
448 if (this_clearance <= .0 && treat_as_obstacle &&
452 had_collision =
true;
453 inout_clearance = .0;
458 const double this_clearance_norm = this_clearance / this->
refDistance;
487 out << curVelLocal << relTarget << targetRelSpeed;
497 in >>curVelLocal >> relTarget >> targetRelSpeed;
#define MRPT_LOAD_HERE_CONFIG_VAR_DEGREES(variableName, variableType, targetVariable, configFileObject, sectionNameStr)
#define MRPT_LOAD_CONFIG_VAR_NO_DEFAULT(variableName, variableType, configFileObject, sectionNameStr)
#define MRPT_LOAD_HERE_CONFIG_VAR(variableName, variableType, targetVariable, configFileObject, sectionNameStr)
#define MRPT_LOAD_HERE_CONFIG_VAR_NO_DEFAULT(variableName, variableType, targetVariable, configFileObject, sectionNameStr)
#define IMPLEMENTS_VIRTUAL_SERIALIZABLE(class_name, base_class_name, NameSpace)
This must be inserted as implementation of some required members for virtual CSerializable classes:
This is the base class for any user-defined PTG.
bool debugDumpInFiles(const std::string &ptg_name) const
Dump PTG trajectories in four text files: .
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)...
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...
uint16_t alpha2index(double alpha) const
Discrete index value for the corresponding alpha value.
uint16_t m_alphaValuesCount
The number of discrete values for "alpha" between -PI and +PI.
virtual void saveToConfigFile(mrpt::utils::CConfigFileBase &cfg, const std::string &sSection) const MRPT_OVERRIDE
This method saves the options to a ".ini"-like file or memory-stored string list.
virtual void internal_writeToStream(mrpt::utils::CStream &out) const
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.
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 onNewNavDynamicState()=0
Invoked when m_nav_dyn_state has changed; gives the PTG the opportunity to react and parameterize pat...
void deinitialize()
This must be called to de-initialize the PTG if some parameter is to be changed.
void initClearanceDiagram(ClearanceDiagram &cd) const
Must be called to resize a CD to its correct size, before calling updateClearance()
bool isInitialized() const
Returns true if initialize() has been called and there was no errors, so the PTG is ready to be queri...
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...
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.
virtual std::string getDescription() const =0
Gets a short textual description of the PTG and its parameters.
uint16_t m_clearance_decimated_paths
Number of paths for the decimated paths analysis of clearance.
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 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...
uint16_t m_clearance_num_points
Number of steps for the piecewise-constant approximation of clearance from TPS distances [0,...
static std::string OUTPUT_DEBUG_PATH_PREFIX
The path used as defaul output in, for example, debugDumpInFiles. (Default="./reactivenav....
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...
static const uint16_t INVALID_PTG_PATH_INDEX
void initTPObstacleSingle(uint16_t k, double &TP_Obstacle_k) const
uint16_t m_nav_dyn_state_target_k
Update in updateNavDynamicState(), contains the path index (k) for the target.
virtual bool supportSpeedAtTarget() const
Returns true if this PTG takes into account the desired velocity at target.
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 ...
TNavDynamicState m_nav_dyn_state
Updated before each nav step by.
double index2alpha(uint16_t k) const
Alpha value for the discrete corresponding value.
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 internal_deinitialize()=0
This must be called to de-initialize the PTG if some parameter is to be changed.
virtual bool supportVelCmdNOP() const
Returns true if it is possible to stop sending velocity commands to the robot and,...
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.
uint16_t getAlphaValuesCount() const
Get the number of different, discrete paths in this family.
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.
virtual bool isPointInsideRobotShape(const double x, const double y) const =0
Returns true if the point lies within the robot shape.
virtual void loadFromConfigFile(const mrpt::utils::CConfigFileBase &cfg, const std::string &sSection) MRPT_OVERRIDE
Parameters accepted by this base class:
virtual double getMaxRobotRadius() const =0
Returns an approximation of the robot radius.
virtual double maxTimeInVelCmdNOP(int path_k) const
Only for PTGs supporting supportVelCmdNOP(): this is the maximum time (in seconds) for which the path...
virtual void loadDefaultParams()
Loads a set of default parameters into the PTG.
virtual void internal_readFromStream(mrpt::utils::CStream &in)
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...
Clearance information for one particular PTG and one set of obstacles.
size_t get_decimated_num_paths() const
std::map< double, double > dist2clearance_t
[TPS_distance] => normalized_clearance_for_exactly_that_robot_pose */
size_t get_actual_num_paths() const
dist2clearance_t & get_path_clearance_decimated(size_t decim_k)
void resize(size_t actual_num_paths, size_t decimated_num_paths)
Initializes the container to allocate decimated_num_paths entries, as a decimated subset of a total o...
size_t decimated_k_to_real_k(size_t k) const
A set of independent lines (or segments), one line with its own start and end positions (X,...
void appendLine(const mrpt::math::TSegment3D &sgm)
Appends a line to the set.
void appendLineStrip(float x, float y, float z)
Appends a line whose starting point is the end point of the last line (similar to OpenGL's GL_LINE_ST...
This class allows loading and storing values and vectors of different types from a configuration text...
void write(const std::string §ion, const std::string &name, const data_t &value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
GLclampf GLclampf GLclampf alpha
GLsizei const GLchar ** string
T angDistance(T from, T to)
Computes the shortest angular increment (or distance) between two planar orientations,...
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
bool BASE_IMPEXP createDirectory(const std::string &dirName)
Creates a directory.
std::string BASE_IMPEXP fileNameStripInvalidChars(const std::string &filename, const char replacement_to_invalid_chars='_')
Replace invalid filename chars by underscores ('_') or any other user-given char.
int round(const T value)
Returns the closer integer (int) to x.
PTG_collision_behavior_t
Defines behaviors for where there is an obstacle inside the robot shape right at the beginning of a P...
@ COLL_BEH_STOP
Totally dissallow any movement if there is any too-close (almost collision) obstacles.
@ COLL_BEH_BACK_AWAY
Favor getting back from too-close (almost collision) obstacles.
#define ASSERT_BELOW_(__A, __B)
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define THROW_EXCEPTION(msg)
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
double DEG2RAD(const double x)
Degrees to radians.
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value.
double RAD2DEG(const double x)
Radians to degrees.
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
unsigned __int16 uint16_t
unsigned __int64 uint64_t
double norm() const
Point norm.
void inverseComposePoint(const TPoint2D g, TPoint2D &l) const
double phi
Orientation (rads)
double vy
Velocity components: X,Y (m/s)
double omega
Angular velocity (rad/s)
Dynamic state that may affect the PTG path parameterization.
mrpt::math::TTwist2D curVelLocal
Current vehicle velocity (local frame of reference)
void writeToStream(mrpt::utils::CStream &out) const
bool operator==(const TNavDynamicState &o) const
double targetRelSpeed
Desired relative speed [0,1] at target. Default=0.
mrpt::math::TPose2D relTarget
Current relative target location.
void readFromStream(mrpt::utils::CStream &in)