31     : m_collisionGrid(-1, 1, -1, 1, 0.5, this)
    54         v_max_mps, 
double, 
V_MAX, cfg, sSection);
    56         w_max_dps, 
double, 
W_MAX, cfg, sSection);
    63     const int WN = 25, WV = 30;
    69         "Resolution of the collision-check look-up-table [m].");
    71         sSection, 
"v_max_mps", 
V_MAX, WN, WV,
    72         "Maximum linear velocity for trajectories [m/s].");
    75         "Maximum angular velocity for trajectories [deg/s].");
    78         "An approximate dimension of the robot (not a critical parameter) "   104     float max_time, 
float max_dist, 
unsigned int max_n, 
float diferencial_t,
   105     float min_dist, 
float* out_max_acc_v, 
float* out_max_acc_w)
   116     const float radio_max_robot = 1.0f;  
   123     float ult_dist, ult_dist1, ult_dist2;
   126     float x_min = 1e3f, x_max = -1e3;
   127     float y_min = 1e3f, y_max = -1e3;
   130     float max_acc_lin, max_acc_ang;
   132     max_acc_lin = max_acc_ang = 0;
   143             float t = .0f, dist = .0f, girado = .0f;
   144             float x = .0f, y = .0f, phi = .0f, v = .0f, w = .0f, _x = .0f,
   145                   _y = .0f, _phi = .0f;
   149             float last_vs[2] = {.0f, .0f}, last_ws[2] = {.0f, .0f};
   152             points.push_back(
TCPoint(x, y, phi, t, dist, v, w));
   155             while (t < max_time && dist < max_dist && points.size() < max_n &&
   156                    fabs(girado) < 1.95 * 
M_PI)
   162                         fabs((last_vs[0] - last_vs[1]) / diferencial_t);
   164                         fabs((last_ws[0] - last_ws[1]) / diferencial_t);
   173                 last_vs[1] = last_vs[0];
   174                 last_ws[1] = last_ws[0];
   180                 x += cos(phi) * v * diferencial_t;
   181                 y += sin(phi) * v * diferencial_t;
   182                 phi += w * diferencial_t;
   185                 girado += w * diferencial_t;
   190                 dist += v_inTPSpace * diferencial_t;
   196                 ult_dist2 = fabs(radio_max_robot * (_phi - phi));
   197                 ult_dist = std::max(ult_dist1, ult_dist2);
   199                 if (ult_dist > min_dist)
   206                     points.push_back(
TCPoint(x, y, phi, t, dist, v, w));
   215                 x_min = std::min(x_min, x);
   216                 x_max = std::max(x_max, x);
   217                 y_min = std::min(y_min, y);
   218                 y_max = std::max(y_max, y);
   224             points.push_back(
TCPoint(x, y, phi, t, dist, v, w));
   232         if (out_max_acc_v) *out_max_acc_v = max_acc_lin;
   233         if (out_max_acc_w) *out_max_acc_w = max_acc_ang;
   240             x_min - 0.5f, x_max + 0.5f, y_min - 0.5f, y_max + 0.5f, 0.25f,
   245             const auto M = 
static_cast<uint32_t
>(
m_trajectory[k].size());
   246             for (uint32_t n = 0; n < M; n++)
   263             << 
"[CPTG_DiffDrive_CollisionGridBased::simulateTrajectories] "   264                "Simulation aborted: unexpected exception!\n";
   288         const float obsX, 
const float obsY)
 const   292     return cell != 
nullptr ? *cell : emptyCell;
   300     const unsigned int icx, 
const unsigned int icy, 
const uint16_t k,
   308     auto itK = cell->end();
   309     for (
auto it = cell->begin(); it != cell->end(); ++it)
   316     if (itK == cell->end())
   318         cell->push_back(std::make_pair(k, dist));
   322         if (dist < itK->second) itK->second = dist;
   330     const std::string& filename,
   338         const uint32_t n = 1;  
   386         if (!f) 
return false;
   388         const uint8_t serialize_version =
   395         *f << computed_robotShape;
   398         *f << m_parent->getDescription() << m_parent->getAlphaValuesCount()
   399            << 
d2f(m_parent->getMax_V()) << 
d2f(m_parent->getMax_W());
   401         *f << m_x_min << m_x_max << m_y_min << m_y_max;
   405         uint32_t N = m_map.size();
   407         for (uint32_t i = 0; i < N; i++)
   409             uint32_t M = m_map[i].size();
   411             for (uint32_t k = 0; k < M; k++)
   412                 *f << m_map[i][k].first << m_map[i][k].second;
   432         if (!f) 
return false;
   442         uint8_t serialized_version;
   443         *f >> serialized_version;
   445         switch (serialized_version)
   452                 const bool shapes_match =
   453                     (stored_shape.size() == current_robotShape.size() &&
   455                          stored_shape.begin(), stored_shape.end(),
   456                          current_robotShape.begin()));
   472         const std::string expected_desc = m_parent->getDescription();
   475         if (desc != expected_desc) 
return false;
   478 #define READ_UINT16_CHECK_IT_MATCHES_STORED(_VAR) \   482         if (ff != _VAR) return false;             \   484 #define READ_FLOAT_CHECK_IT_MATCHES_STORED(_VAR)       \   488         if (std::abs(ff - _VAR) > 1e-4f) return false; \   490 #define READ_DOUBLE_CHECK_IT_MATCHES_STORED(_VAR)     \   494         if (std::abs(ff - _VAR) > 1e-6) return false; \   514         for (uint32_t i = 0; i < N; i++)
   519             for (uint32_t k = 0; k < M; k++)
   520                 *f >> m_map[i][k].first >> m_map[i][k].second;
   525     catch (
const std::exception& e)
   527         std::cerr << 
"[CCollisionGrid::loadFromFile] " << e.what();
   537     double x, 
double y, 
int& out_k, 
double& out_d, 
double tolerance_dist)
 const   543         "Have you called simulateTrajectories() first?");
   552     uint32_t n_min = 0, n_max = 0;
   553     bool at_least_one = 
false;
   560     for (
int cx = cx0 - 1; cx <= cx0 + 1; cx++)
   562         for (
int cy = cy0 - 1; cy <= cy0 + 1; cy++)
   591     float selected_d = 0;
   592     float selected_dist = std::numeric_limits<float>::max();
   597         for (
int k = k_min; k <= k_max; k++)
   600             const uint32_t n_max_this =
   601                 std::min(static_cast<uint32_t>(n_real ? n_real - 1 : 0), n_max);
   603             for (uint32_t n = n_min; n <= n_max_this; n++)
   607                 if (dist_a_punto < selected_dist)
   609                     selected_dist = dist_a_punto;
   617     if (selected_k != -1)
   621         return (selected_dist <= 
square(tolerance_dist));
   631     selected_dist = std::numeric_limits<float>::max();
   639         if (dist_a_punto < selected_dist)
   641             selected_dist = dist_a_punto;
   643             selected_d = dist_a_punto;
   647     selected_d = std::sqrt(selected_d);
   656     const float target_dist = std::sqrt(x * x + y * y);
   657     return (target_dist > target_dist);
   664         "Changing reference distance not allowed in this class after "   673         "Changing robot shape not allowed in this class after initialization!");
   682     const std::string& cacheFilename, 
const bool verbose)
   690              << 
"[CPTG_DiffDrive_CollisionGridBased::initialize] Starting... "   691                 "*** THIS MAY TAKE A WHILE, BUT MUST BE COMPUTED ONLY ONCE!! **"   697         m_robotShape.size() >= 3, 
"Robot shape must have 3 or more vertices");
   706     if (
verbose) cout << 
"Initializing PTG '" << cacheFilename << 
"'...";
   709     const float min_dist = 0.015f;
   727     ASSERTMSG_(Ki > 0, 
"The PTG seems to be not initialized!");
   732         if (
verbose) cout << 
"loaded from file OK" << endl;
   748         std::vector<mrpt::math::TPoint2D> transf_shape(
   753         for (
size_t k = 0; k < Ki; k++)
   757             for (
size_t n = 0; n < (nPoints - 1); n++)
   764                     std::numeric_limits<double>::max(),
   765                     std::numeric_limits<double>::max());
   767                     -std::numeric_limits<double>::max(),
   768                     -std::numeric_limits<double>::max());
   770                 for (
size_t m = 0; m < nVerts; m++)
   797                 for (
int ix = ix_min; ix < ix_max; ix++)
   801                     for (
int iy = iy_min; iy < iy_max; iy++)
   813                                 ix - 1, iy - 1, k, d);
   820             if (
verbose) cout << k << 
"/" << Ki << 
",";
   852     uint16_t k, uint32_t step)
 const   861     uint16_t k, 
double dist, uint32_t& out_step)
 const   868     for (
size_t n = 0; n < numPoints - 1; n++)
   877     out_step = numPoints - 1;
   882     double ox, 
double oy, std::vector<double>& tp_obstacles)
 const   887     for (
const auto& i : cell)
   889         const double dist = i.second;
   895     double ox, 
double oy, uint16_t k, 
double& tp_obstacle_k)
 const   900     for (
const auto& i : cell)
   903             const double dist = i.second;
   934     const uint8_t version = 0;
 double index2alpha(uint16_t k) const
Alpha value for the discrete corresponding value. 
 
double GetVertex_x(size_t i) const
Methods for accessing the vertices. 
 
double Tac() noexcept
Stops the stopwatch. 
 
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...
 
void setRefDistance(const double refDist) override
Launches an exception in this class: it is not allowed in numerical integration-based PTGs to change ...
 
virtual void internal_writeToStream(mrpt::serialization::CArchive &out) const
 
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &i, mrpt::nav::TCPoint &p)
 
int y2idx(double y) const
 
#define READ_DOUBLE_CHECK_IT_MATCHES_STORED(_VAR)
 
bool saveColGridsToFile(const std::string &filename, const mrpt::math::CPolygon &computed_robotShape) const
 
size_t verticesCount() const
Returns the vertices count in the polygon: 
 
bool getPathStepForDist(uint16_t k, double dist, uint32_t &out_step) const override
Access path k ([0,N-1]=>[-pi,pi] in alpha): largest step count for which the traversed distance is < ...
 
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. ...
 
void internal_initialize(const std::string &cacheFilename=std::string(), const bool verbose=true) override
Must be called after setting all PTG parameters and before requesting converting obstacles to TP-Spac...
 
Specifies the min/max values for "k" and "n", respectively. 
 
void loadFromConfigFile(const mrpt::config::CConfigFileBase &cfg, const std::string &sSection) override
Possible values in "params" (those in CParameterizedTrajectoryGenerator, which is called internally...
 
#define MRPT_LOAD_HERE_CONFIG_VAR_DEGREES_NO_DEFAULT( variableName, variableType, targetVariable, configFileObject, sectionNameStr)
 
std::string std::string format(std::string_view fmt, ARGS &&... args)
 
size_t size(const MATRIXLIKE &m, const int dim)
 
#define ASSERT_BELOW_(__A, __B)
 
const TCollisionCell & getTPObstacle(const float obsX, const float obsY) const
For an obstacle (x,y), returns a vector with all the pairs (a,d) such as the robot collides...
 
Trajectory points in C-Space for non-holonomic robots. 
 
double getResolution() const
Returns the resolution of the grid map. 
 
bool loadFromFile(mrpt::serialization::CArchive *fil, const mrpt::math::CPolygon ¤t_robotShape)
Load from file, true = OK. 
 
void internal_deinitialize() override
This must be called to de-initialize the PTG if some parameter is to be changed. 
 
void loadDefaultParams() override
Loads a set of default parameters; provided exclusively for the PTG-configurator tool. 
 
A high-performance stopwatch, with typical resolution of nanoseconds. 
 
A wrapper of a TPolygon2D class, implementing CSerializable. 
 
void internal_readFromStream(mrpt::serialization::CArchive &in) override
 
double idx2x(int cx) const
Transform a cell index into a coordinate value of the cell central point. 
 
bool contains(const TPoint2D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge). 
 
void internal_shape_saveToStream(mrpt::serialization::CArchive &out) const
 
bool fileOpenCorrectly() const
Returns true if the file was open without errors. 
 
const uint32_t COLGRID_FILE_MAGIC
 
void updateTPObstacleSingle(double ox, double oy, uint16_t k, double &tp_obstacle_k) const override
Like updateTPObstacle() but for one direction only (k) in TP-Space. 
 
#define READ_FLOAT_CHECK_IT_MATCHES_STORED(_VAR)
 
double idx2y(int cy) const
 
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...
 
mrpt::kinematics::CVehicleVelCmd::Ptr directionToMotionCommand(uint16_t k) const override
In this class, out_action_cmd contains: [0]: linear velocity (m/s), [1]: angular velocity (rad/s)...
 
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations. 
 
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream, std::istream, std::ostream, std::stringstream. 
 
void setSize(const double x_min, const double x_max, const double y_min, const double y_max, const double resolution, const T *fill_value=nullptr)
Changes the size of the grid, ERASING all previous contents. 
 
virtual void loadDefaultParams()
Loads a set of default parameters into the PTG. 
 
#define ASSERT_(f)
Defines an assertion mechanism. 
 
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &o, const mrpt::nav::TCPoint &p)
 
float d2f(const double d)
shortcut for static_cast<float>(double) 
 
void loadShapeFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string §ion)
 
This class allows loading and storing values and vectors of different types from a configuration text...
 
bool inverseMap_WS2TP(double x, double y, int &out_k, double &out_d, double tolerance_dist=0.10) const override
The default implementation in this class relies on a look-up-table. 
 
double getPathDist(uint16_t k, uint32_t step) const override
Access path k ([0,N-1]=>[-pi,pi] in alpha): traversed distance at discrete step step. 
 
constexpr double DEG2RAD(const double x)
Degrees to radians. 
 
void internal_shape_loadFromStream(mrpt::serialization::CArchive &in)
 
TCollisionCell * cellByPos(double x, double y)
Returns a pointer to the contents of a cell given by its coordinates, or nullptr if it is out of the ...
 
CPTG_DiffDrive_CollisionGridBased()
Constructor: possible values in "params": 
 
bool loadColGridsFromFile(const std::string &filename, const mrpt::math::CPolygon ¤t_robotShape)
 
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism. 
 
size_t getSizeX() const
Returns the horizontal size of grid map in cells count. 
 
double m_stepTimeDuration
 
void updateCellInfo(const unsigned int icx, const unsigned int icy, const uint16_t k, const float dist)
Updates the info into a cell: It updates the cell only if the distance d for the path k is lower than...
 
void write(const std::string §ion, const std::string &name, enum_t value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
 
size_t getSizeY() const
Returns the vertical size of grid map in cells count. 
 
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...
 
uint16_t getAlphaValuesCount() const
Get the number of different, discrete paths in this family. 
 
TCLAP::CmdLine cmd("system_control_rate_timer_example")
 
return_t square(const num_t x)
Inline function for the square of a number. 
 
size_t getPathStepCount(uint16_t k) const override
Access path k ([0,N-1]=>[-pi,pi] in alpha): number of discrete "steps" along the trajectory. 
 
#define MRPT_LOAD_CONFIG_VAR( variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
 
void internal_processNewRobotShape() override
Will be called whenever the robot shape is set / updated. 
 
bool saveToFile(mrpt::serialization::CArchive *fil, const mrpt::math::CPolygon &computed_robotShape) const
Save to file, true = OK. 
 
mrpt::containers::CDynamicGrid< TCellForLambdaFunction > m_lambdaFunctionOptimizer
This grid will contain indexes data for speeding-up the default, brute-force lambda function...
 
Virtual base class for "archives": classes abstracting I/O streams. 
 
std::vector< TCPoint > TCPointVector
 
CCollisionGrid m_collisionGrid
The collision grid. 
 
void loadFromConfigFile(const mrpt::config::CConfigFileBase &cfg, const std::string &sSection) override
Parameters accepted by this base class: 
 
mrpt::vision::TStereoCalibResults out
 
constexpr double RAD2DEG(const double x)
Radians to degrees. 
 
virtual void internal_readFromStream(mrpt::serialization::CArchive &in)
 
int x2idx(double x) const
Transform a coordinate values into cell indexes. 
 
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. ...
 
#define READ_UINT16_CHECK_IT_MATCHES_STORED(_VAR)
 
void getPathPose(uint16_t k, uint32_t step, mrpt::math::TPose2D &p) const override
Access path k ([0,N-1]=>[-pi,pi] in alpha): pose of the vehicle at discrete step step. 
 
void updateTPObstacle(double ox, double oy, std::vector< double > &tp_obstacles) const override
Updates the radial map of closest TP-Obstacles given a single obstacle point at (ox,oy) 
 
std::vector< std::pair< uint16_t, float > > TCollisionCell
A list of all the pairs (alpha,distance) such as the robot collides at that cell. ...
 
virtual void ptgDiffDriveSteeringFunction(float alpha, float t, float x, float y, float phi, float &v, float &w) const =0
The main method to be implemented in derived classes: it defines the differential-driven differential...
 
double GetVertex_y(size_t i) const
 
void loadDefaultParams() override
Loads a set of default parameters; provided exclusively for the PTG-configurator tool. 
 
Saves data to a file and transparently compress the data using the given compression level...
 
void Tic() noexcept
Starts the stopwatch. 
 
double turningRadiusReference
 
std::shared_ptr< CVehicleVelCmd > Ptr
 
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. ...
 
#define MRPT_LOAD_HERE_CONFIG_VAR_NO_DEFAULT( variableName, variableType, targetVariable, configFileObject, sectionNameStr)
 
std::vector< TCPointVector > m_trajectory
 
mrpt::kinematics::CVehicleVelCmd::Ptr getSupportedKinematicVelocityCommand() const override
Returns an empty kinematic velocity command object of the type supported by this PTG. 
 
double phi
Orientation (rads) 
 
Kinematic model for Ackermann-like or differential-driven vehicles. 
 
2D polygon, inheriting from std::vector<TPoint2D>. 
 
uint16_t m_alphaValuesCount
The number of discrete values for "alpha" between -PI and +PI. 
 
mrpt::math::CPolygon m_robotShape
 
void internal_writeToStream(mrpt::serialization::CArchive &out) const override
 
void simulateTrajectories(float max_time, float max_dist, unsigned int max_n, float diferencial_t, float min_dist, float *out_max_acc_v=nullptr, float *out_max_acc_w=nullptr)
Numerically solve the diferential equations to generate a family of trajectories. ...
 
double getPathStepDuration() const override
Returns the duration (in seconds) of each "step".