30 CMetricMapBuilderICP::CMetricMapBuilderICP()
31 : ICP_options(m_min_verbosity_level)
55 : matchAgainstTheGrid(false),
56 insertionLinDistance(1.0),
57 insertionAngDistance(
DEG2RAD(30)),
58 localizationLinDistance(0.20),
59 localizationAngDistance(
DEG2RAD(30)),
60 minICPgoodnessToAccept(0.40),
61 verbosity_level(parent_verbosity_level),
90 section,
"verbosity_level", verbosity_level);
94 mapInitializers.loadFromConfigFile(
source, section);
98 std::ostream& out)
const
101 "\n----------- [CMetricMapBuilderICP::TConfigParams] ------------ "
105 "insertionLinDistance = %f m\n",
106 insertionLinDistance);
108 "insertionAngDistance = %f deg\n",
109 RAD2DEG(insertionAngDistance));
111 "localizationLinDistance = %f m\n",
112 localizationLinDistance);
114 "localizationAngDistance = %f deg\n",
115 RAD2DEG(localizationAngDistance));
117 "verbosity_level = %s\n",
122 out <<
mrpt::format(
" Now showing 'mapsInitializers':\n");
123 mapInitializers.dumpToTextStream(out);
139 throw std::runtime_error(
140 "Neither grid maps nor points map: Have you called initialize() "
141 "after setting ICP_options.mapInitializers?");
148 MRPT_LOG_DEBUG(
"processObservation(): obs is CObservationOdometry");
152 std::dynamic_pointer_cast<CObservationOdometry>(obs);
160 odo->odometry.asTPose(), odo->timestamp, odo->hasVelocities,
163 if (pose_before_valid)
170 "processObservation(): obs is CObservationOdometry, new "
180 TPose2D initialEstimatedRobotPose(0, 0, 0);
186 "processObservation(): extrapolating pose from latest pose "
187 "and new observation timestamp...");
189 initialEstimatedRobotPose, robotVelLocal,
190 robotVelGlobal, obs->timestamp))
195 "processObservation(): new pose extrapolation failed, "
196 "using last pose as is.");
202 "processObservation(): invalid observation timestamp.");
208 CPose2D previousKnownRobotPose;
214 previousKnownRobotPose);
220 const bool we_skip_ICP_pose_correction =
230 "processObservation(): skipping ICP pose correction due to small "
231 "odometric displacement? : "
232 << (we_skip_ICP_pose_correction ?
"YES" :
"NO"));
235 bool can_do_icp =
false;
242 MRPT_LOG_DEBUG(
"processObservation(): matching against gridmap.");
248 "No points map in multi-metric map.");
251 MRPT_LOG_DEBUG(
"processObservation(): matching against point map.");
255 if (!we_skip_ICP_pose_correction)
280 std::dynamic_pointer_cast<CObservation2DRangeScan>(obs);
283 ->insertionOptions.mapAltitude -
284 obsLaser->sensorPose.z()) < 0.01)
313 initialEstimatedRobotPose),
334 "processObservation: previousPose="
335 << previousKnownRobotPose <<
"-> currentPose="
338 "[CMetricMapBuilderICP] Fit:%.1f%% Itr:%i In "
341 1000 * runningTime));
346 "Ignoring ICP of low quality: "
347 << icpReturn.
goodness * 100 << std::endl);
355 currentKnownRobotPose);
362 "Cannot do ICP: empty pointmap or not suitable "
374 const bool firstTimeForThisSensor =
378 firstTimeForThisSensor ||
395 if (matchWith && matchWith->
isEmpty()) update =
true;
398 "update map: " << (update ?
"YES" :
"NO")
399 <<
" options.enableMapUpdating: "
414 currentKnownRobotPose;
421 "Updating map from pose %s\n",
422 currentKnownRobotPose.
asString().c_str()));
424 CPose3D estimatedPose3D(currentKnownRobotPose);
425 const bool anymap_update =
429 "**No map was updated** after inserting an observation of "
431 << obs->GetRuntimeClass()->className <<
"`");
444 "Map updated OK. Done in "
477 mrpt::make_aligned_shared<CObservationOdometry>();
478 obs->timestamp = movEstimation->timestamp;
513 mrpt::make_aligned_shared<CPose3DPDFGaussian>();
514 pdf3D->copyFrom(pdf2D);
577 posePDF->getMean(estimatedPose3D);
580 SF->insertObservationsInto(&
metricMap, &estimatedPose3D);
592 std::vector<float>&
x, std::vector<float>&
y)
651 unsigned int imgHeight =
img.getHeight();
662 for (
size_t j = 0; j < nPoses; j++)
674 x1, imgHeight - 1 - y1, x2, imgHeight - 1 - y2, TColor::black());
698 ang = std::abs(Ap.
phi());
703 this->last_update =
p;
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...
#define IS_DERIVED(ptrObj, class_name)
Evaluates to true if a pointer to an object (derived from mrpt::rtti::CObject) is an instance of the ...
static time_point now() noexcept
Returns the current time, with the highest resolution available.
This class allows loading and storing values and vectors of different types from a configuration text...
A class for storing images as grayscale or RGB bitmaps.
Declares a virtual base class for all metric maps storage classes.
bool insertObservationPtr(const mrpt::obs::CObservation::Ptr &obs, const mrpt::poses::CPose3D *robotPose=NULL)
A wrapper for smart pointers, just calls the non-smart pointer version.
virtual bool isEmpty() const =0
Returns true if the map is empty/no observation has been inserted.
This class stores any customizable set of metric maps.
ProxyFilterContainerByClass< mrpt::maps::CSimplePointsMap::Ptr, TListMaps > m_pointsMaps
STL-like proxy to access this kind of maps in maps.
void setListOfMaps(const mrpt::maps::TSetOfMetricMapInitializers *initializers)
Sets the list of internal map according to the passed list of map initializers (Current maps' content...
ProxyFilterContainerByClass< mrpt::maps::COccupancyGridMap2D::Ptr, TListMaps > m_gridMaps
STL-like proxy to access this kind of maps in maps.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors.
TInsertionOptions insertionOptions
The options used when inserting observations in the map.
This class stores a sequence of <Probabilistic Pose,SensoryFrame> pairs, thus a "metric map" can be t...
void insert(const mrpt::poses::CPose3DPDF *in_posePDF, const mrpt::obs::CSensoryFrame &in_SF)
Add a new pair to the sequence.
void get(size_t index, mrpt::poses::CPose3DPDF::Ptr &out_posePDF, mrpt::obs::CSensoryFrame::Ptr &out_SF) const
Access to the i'th pair, first one is index '0'.
size_t size() const
Returns the count of pairs (pose,sensory data)
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans.
TDATA getMeanVal() const
Returns the mean, or mathematical expectation of the probability density distribution (PDF).
Declares a class for storing a collection of robot actions.
CActionRobotMovement2D::Ptr getBestMovementEstimation() const
Returns the best pose increment estimator in the collection, based on the determinant of its pose cha...
std::shared_ptr< CActionRobotMovement2D > Ptr
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
std::shared_ptr< CObservation2DRangeScan > Ptr
std::shared_ptr< CObservation > Ptr
An observation of the current (cumulative) odometry for a wheeled robot.
std::shared_ptr< CObservationOdometry > Ptr
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
const_iterator end() const
Returns a constant iterator to the end of the list of observations: this is an example of usage:
const_iterator begin() const
Returns a constant iterator to the first observation: this is an example of usage:
std::shared_ptr< CSensoryFrame > Ptr
std::deque< CObservation::Ptr >::iterator iterator
You can use CSensoryFrame::begin to get a iterator to the first element.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
mrpt::math::TPose2D asTPose() const
void asString(std::string &s) const
Returns a human-readable textual representation of the object (eg: "[x y yaw]", yaw in degrees)
void composeFrom(const CPose2D &A, const CPose2D &B)
Makes .
const double & phi() const
Get the phi angle of the 2D pose (in radians)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
std::shared_ptr< CPose3DPDFGaussian > Ptr
std::shared_ptr< CPose3DPDF > Ptr
double norm() const
Returns the euclidean norm of vector: .
Declares a class that represents a Probability Density function (PDF) of a 2D pose .
CPose2D mean
The mean value.
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
void copyFrom(const CPosePDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations)
Declares a class that represents a probability density function (pdf) of a 2D pose (x,...
std::shared_ptr< CPosePDF > Ptr
void processUpdateNewPoseLocalization(const mrpt::math::TPose2D &newPose, mrpt::Clock::time_point tim)
Updates the filter with new global-coordinates localization data from a localization or SLAM source.
bool getCurrentEstimate(mrpt::math::TPose2D &pose, mrpt::math::TTwist2D &velLocal, mrpt::math::TTwist2D &velGlobal, mrpt::Clock::time_point tim_query=mrpt::Clock::now()) const
Get the estimate for a given timestamp (defaults to now()), obtained as:
bool getLatestRobotPose(mrpt::math::TPose2D &pose) const
Get the latest known robot pose, either from odometry or localization.
void processUpdateNewOdometry(const mrpt::math::TPose2D &newGlobalOdometry, mrpt::Clock::time_point cur_tim, bool hasVelocities=false, const mrpt::math::TTwist2D &newRobotVelLocal=mrpt::math::TTwist2D())
Updates the filter with new odometry readings.
void reset()
Resets all internal state.
bool contains(const mrpt::rtti::TRuntimeClassId *id) const
Does the list contains this class?
Several implementations of ICP (Iterative closest point) algorithms for aligning two point maps or a ...
TConfigParams options
The options employed by the ICP align.
void leaveCriticalSection()
Leave critical section for map updating.
void saveCurrentMapToFile(const std::string &fileName, bool compressGZ=true) const
Save map (mrpt::maps::CSimpleMap) to a ".simplemap" file.
void loadCurrentMapFromFile(const std::string &fileName)
Load map (mrpt::maps::CSimpleMap) from a ".simplemap" file.
void enterCriticalSection()
Enter critical section for map updating.
std::mutex critZoneChangingMap
Critical zones.
void saveCurrentEstimationToImage(const std::string &file, bool formatEMF_BMP=true) override
A useful method for debugging: the current map (and/or poses) estimation is dumped to an image file.
TConfigParams ICP_options
Options for the ICP-SLAM application.
void setCurrentMapFile(const char *mapFile)
Sets the "current map file", thus that map will be loaded if it exists or a new one will be created i...
void accumulateRobotDisplacementCounters(const mrpt::poses::CPose2D &new_pose)
mrpt::math::CMatrixDouble33 m_lastPoseEst_cov
Last pose estimation (covariance)
bool m_there_has_been_an_odometry
void resetRobotDisplacementCounters(const mrpt::poses::CPose2D &new_pose)
void getCurrentlyBuiltMap(mrpt::maps::CSimpleMap &out_map) const override
Fills "out_map" with the set of "poses"-"sensory-frames", thus the so far built map.
std::deque< mrpt::math::TPose2D > m_estRobotPath
The estimated robot path:
void processActionObservation(mrpt::obs::CActionCollection &action, mrpt::obs::CSensoryFrame &in_SF) override
Appends a new action and observations to update this map: See the description of the class at the top...
unsigned int getCurrentlyBuiltMapSize() override
Returns just how many sensory-frames are stored in the currently build map.
CICP::TConfigParams ICP_params
Options for the ICP algorithm itself.
std::string currentMapFile
Current map file.
mrpt::maps::CSimpleMap SF_Poses_seq
The set of observations that leads to current map:
mrpt::poses::CRobot2DPoseEstimator m_lastPoseEst
The pose estimation by the alignment algorithm (ICP).
mrpt::poses::CPose3DPDF::Ptr getCurrentPoseEstimation() const override
Returns a copy of the current best pose estimation as a pose PDF.
void initialize(const mrpt::maps::CSimpleMap &initialMap=mrpt::maps::CSimpleMap(), const mrpt::poses::CPosePDF *x0=nullptr) override
Initialize the method, starting with a known location PDF "x0"(if supplied, set to nullptr to left un...
mrpt::aligned_std_map< std::string, TDist > m_distSinceLastInsertion
Indexed by sensor label.
mrpt::maps::CMultiMetricMap metricMap
The metric map representation as a points map:
const mrpt::maps::CMultiMetricMap * getCurrentlyBuiltMetricMap() const override
Returns the map built so far.
virtual ~CMetricMapBuilderICP()
Destructor:
mrpt::poses::CPose2D m_auxAccumOdometry
void getCurrentMapPoints(std::vector< float > &x, std::vector< float > &y)
Returns the 2D points of current local map.
void processObservation(const mrpt::obs::CObservation::Ptr &obs)
The main method of this class: Process one odometry or sensor observation.
mrpt::poses::CPosePDF::Ptr Align(const mrpt::maps::CMetricMap *m1, const mrpt::maps::CMetricMap *m2, const mrpt::poses::CPose2D &grossEst, float *runningTime=nullptr, void *info=nullptr)
The method for aligning a pair of metric maps, aligning only 2D + orientation.
void setLoggerName(const std::string &name)
Set the name of the COutputLogger instance.
A high-performance stopwatch, with typical resolution of nanoseconds.
void Tic() noexcept
Starts the stopwatch.
double Tac() noexcept
Stops the stopwatch.
#define MRPT_LOAD_CONFIG_VAR_DEGREES( variableName, configFileObject, sectionNameStr)
Loads a double variable, stored as radians but entered in the INI-file as degrees.
#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...
EIGEN_STRONG_INLINE bool empty() const
#define ASSERT_(f)
Defines an assertion mechanism.
#define THROW_EXCEPTION(msg)
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
GLsizei const GLchar ** string
GLsizei GLsizei GLchar * source
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
std::string formatTimeInterval(const double timeSeconds)
Returns a formated string with the given time difference (passed as the number of seconds),...
This base provides a set of functions for maths stuff.
This namespace contains representation of robot actions and observations.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
VerbosityLevel
Enumeration of available verbosity levels.
double RAD2DEG(const double x)
Radians to degrees.
double DEG2RAD(const double x)
Degrees to radians.
float minDistBetweenLaserPoints
The minimum distance between points (in 3D): If two points are too close, one of them is not inserted...
bool also_interpolate
If set to true, far points (<1m) are interpolated with samples at "minDistSqrBetweenLaserPoints" inte...
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
The ICP algorithm return information.
unsigned short nIterations
The number of executed iterations until convergence.
float goodness
A goodness measure for the alignment, it is a [0,1] range indicator of percentage of correspondences.
mrpt::rtti::CListOfClasses alwaysInsertByClass
A list of observation classes (derived from mrpt::obs::CObservation) which will be always inserted in...
bool enableMapUpdating
Enable map updating, default is true.
Algorithm configuration params.
mrpt::maps::TSetOfMetricMapInitializers mapInitializers
What maps to create (at least one points map and/or a grid map are needed).
double minICPgoodnessToAccept
Minimum ICP goodness (0,1) to accept the resulting corrected position (default: 0....
void dumpToTextStream(std::ostream &out) const override
This method should clearly display all the contents of the structure in textual form,...
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string §ion) override
This method load the options from a ".ini"-like file or memory-stored string list.
double insertionLinDistance
Minimum robot linear (m) displacement for a new observation to be inserted in the map.
double localizationLinDistance
Minimum robot linear (m) displacement for a new observation to be used to do ICP-based localization (...
double insertionAngDistance
Minimum robot angular (rad, deg when loaded from the .ini) displacement for a new observation to be i...
double localizationAngDistance
Minimum robot angular (rad, deg when loaded from the .ini) displacement for a new observation to be u...
bool matchAgainstTheGrid
(default:false) Match against the occupancy grid or the points map? The former is quicker but less pr...
TConfigParams & operator=(const TConfigParams &other)
TConfigParams(mrpt::system::VerbosityLevel &parent_verbosity_level)
Initializer.
void updateDistances(const mrpt::poses::CPose2D &p)
void updatePose(const mrpt::poses::CPose2D &p)
#define MRPT_LOG_WARN(_STRING)
#define MRPT_LOG_DEBUG_STREAM(__CONTENTS)
Use: MRPT_LOG_DEBUG_STREAM("Var=" << value << " foo=" << foo_var);
#define MRPT_LOG_INFO_STREAM(__CONTENTS)
#define MRPT_LOG_DEBUG(_STRING)
Use: MRPT_LOG_DEBUG("message");
#define MRPT_LOG_INFO(_STRING)
#define MRPT_LOG_WARN_STREAM(__CONTENTS)