32 CMetricMapBuilderICP::CMetricMapBuilderICP() :
33 ICP_options(m_min_verbosity_level)
35 this->setLoggerName(
"CMetricMapBuilderICP");
57 matchAgainstTheGrid( false ),
58 insertionLinDistance(1.0),
59 insertionAngDistance(
DEG2RAD(30)),
60 localizationLinDistance(0.20),
61 localizationAngDistance(
DEG2RAD(30)),
62 minICPgoodnessToAccept(0.40),
63 verbosity_level(parent_verbosity_level),
90 verbosity_level =
source.read_enum<mrpt::utils::VerbosityLevel>(section,
"verbosity_level", verbosity_level );
95 mapInitializers.loadFromConfigFile(
source,section);
100 out.
printf(
"\n----------- [CMetricMapBuilderICP::TConfigParams] ------------ \n\n");
102 out.
printf(
"insertionLinDistance = %f m\n", insertionLinDistance );
103 out.
printf(
"insertionAngDistance = %f deg\n",
RAD2DEG(insertionAngDistance) );
104 out.
printf(
"localizationLinDistance = %f m\n", localizationLinDistance );
105 out.
printf(
"localizationAngDistance = %f deg\n",
RAD2DEG(localizationAngDistance) );
108 out.
printf(
" Now showing 'mapsInitializers':\n");
109 mapInitializers.dumpToTextStream(out);
125 throw std::runtime_error(
"Neither grid maps nor points map: Have you called initialize() after setting ICP_options.mapInitializers?");
132 MRPT_LOG_DEBUG(
"processObservation(): obs is CObservationOdometry");
135 const CObservationOdometryPtr odo = CObservationOdometryPtr(obs);
144 if (pose_before_valid)
150 MRPT_LOG_DEBUG_STREAM(
"processObservation(): obs is CObservationOdometry, new post_after=" << pose_after);
157 TPose2D initialEstimatedRobotPose(0,0,0);
162 MRPT_LOG_DEBUG(
"processObservation(): extrapolating pose from latest pose and new observation timestamp...");
166 MRPT_LOG_WARN(
"processObservation(): new pose extrapolation failed, using last pose as is.");
171 MRPT_LOG_WARN(
"processObservation(): invalid observation timestamp.");
177 CPose2D previousKnownRobotPose;
186 const bool we_skip_ICP_pose_correction =
191 MRPT_LOG_DEBUG_STREAM(
"processObservation(): skipping ICP pose correction due to small odometric displacement? : " << (we_skip_ICP_pose_correction ?
"YES":
"NO"));
194 bool can_do_icp=
false;
201 MRPT_LOG_DEBUG(
"processObservation(): matching against gridmap.");
207 MRPT_LOG_DEBUG(
"processObservation(): matching against point map.");
211 if (!we_skip_ICP_pose_correction)
233 CObservation2DRangeScanPtr obsLaser = CObservation2DRangeScanPtr(obs);
234 if ( std::abs(
metricMap.
m_gridMaps[0]->insertionOptions.mapAltitude - obsLaser->sensorPose.z())<0.01)
257 CPosePDFPtr pestPose= ICP.
Align(
282 1000*runningTime ) );
310 bool update = firstTimeForThisSensor ||
322 if (matchWith && matchWith->
isEmpty())
346 CPose3D estimatedPose3D(currentKnownRobotPose);
349 MRPT_LOG_WARN_STREAM(
"**No map was updated** after inserting an observation of type `"<< obs->GetRuntimeClass()->className <<
"`");
353 CPose3DPDFPtr pose3D = CPose3DPDFPtr( CPose3DPDF::createFrom2D( posePDF ) );
392 obs->timestamp = movEstimation->timestamp;
430 CPose3DPDFGaussianPtr pdf3D = CPose3DPDFGaussian::Create();
431 pdf3D->copyFrom(pdf2D);
482 CPose3DPDFPtr posePDF;
489 posePDF->getMean(estimatedPose3D);
492 SF->insertObservationsInto( &
metricMap, &estimatedPose3D );
504 std::vector<float> &
x,
505 std::vector<float> &
y)
566 unsigned int imgHeight =
img.getHeight();
577 for (
size_t j=0;j<nPoses;j++)
603 it->second.updateDistances(new_pose);
611 it->second.updatePose(new_pose);
618 ang = std::abs( Ap.
phi() );
623 this->last_update =
p;
void saveCurrentMapToFile(const std::string &fileName, bool compressGZ=true) const
Save map (mrpt::maps::CSimpleMap) to a ".simplemap" file.
void processObservation(const mrpt::obs::CObservationPtr &obs)
The main method of this class: Process one odometry or sensor observation.
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
EIGEN_STRONG_INLINE bool empty() const
double localizationAngDistance
Minimum robot angular (rad, deg when loaded from the .ini) displacement for a new observation to be u...
bool insertObservationPtr(const mrpt::obs::CObservationPtr &obs, const mrpt::poses::CPose3D *robotPose=NULL)
A wrapper for smart pointers, just calls the non-smart pointer version.
void updatePose(const mrpt::poses::CPose2D &p)
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
CPose2D mean
The mean value.
void asString(std::string &s) const
Returns a human-readable textual representation of the object (eg: "[x y yaw]", yaw in degrees) ...
mrpt::maps::TSetOfMetricMapInitializers mapInitializers
What maps to create (at least one points map and/or a grid map are needed).
mrpt::maps::CMultiMetricMap metricMap
The metric map representation as a points map:
mrpt::poses::CPosePDFPtr Align(const mrpt::maps::CMetricMap *m1, const mrpt::maps::CMetricMap *m2, const mrpt::poses::CPose2D &grossEst, float *runningTime=NULL, void *info=NULL)
The method for aligning a pair of metric maps, aligning only 2D + orientation.
mrpt::poses::CPose2D m_auxAccumOdometry
double minICPgoodnessToAccept
Minimum ICP goodness (0,1) to accept the resulting corrected position (default: 0.40)
void getCurrentMapPoints(std::vector< float > &x, std::vector< float > &y)
Returns the 2D points of current local map.
This class stores a sequence of <Probabilistic Pose,SensoryFrame> pairs, thus a "metric map" can be t...
A class for storing images as grayscale or RGB bitmaps.
Several implementations of ICP (Iterative closest point) algorithms for aligning two point maps or a ...
#define THROW_EXCEPTION(msg)
bool contains(const mrpt::utils::TRuntimeClassId *id) const
Does the list contains this class?
TDATA getMeanVal() const
Returns the mean, or mathematical expectation of the probability density distribution (PDF)...
std::deque< mrpt::math::TPose2D > m_estRobotPath
The estimated robot path:
void leaveCriticalSection()
Leave critical section for map updating.
virtual ~CMetricMapBuilderICP()
Destructor:
mrpt::aligned_containers< std::string, TDist >::map_t m_distSinceLastInsertion
Indexed by sensor label.
bool getLatestRobotPose(mrpt::math::TPose2D &pose) const
Get the latest known robot pose, either from odometry or localization.
bool enableMapUpdating
Enable map updating, default is true.
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
void initialize(const mrpt::maps::CSimpleMap &initialMap=mrpt::maps::CSimpleMap(), mrpt::poses::CPosePDF *x0=NULL) MRPT_OVERRIDE
Initialize the method, starting with a known location PDF "x0"(if supplied, set to NULL to left unmod...
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. ...
unsigned int getCurrentlyBuiltMapSize() MRPT_OVERRIDE
Returns just how many sensory-frames are stored in the currently build map.
std::string BASE_IMPEXP formatTimeInterval(const double timeSeconds)
Returns a formated string with the given time difference (passed as the number of seconds)...
const mrpt::maps::CMultiMetricMap * getCurrentlyBuiltMetricMap() const MRPT_OVERRIDE
Returns the map built so far.
mrpt::maps::CSimpleMap SF_Poses_seq
The set of observations that leads to current map:
ProxyFilterContainerByClass< mrpt::maps::COccupancyGridMap2DPtr, TListMaps > m_gridMaps
STL-like proxy to access this kind of maps in maps.
mrpt::poses::CPose3DPDFPtr getCurrentPoseEstimation() const MRPT_OVERRIDE
Returns a copy of the current best pose estimation as a pose PDF.
TConfigParams options
The options employed by the ICP align.
void Tic()
Starts the stopwatch.
TConfigParams ICP_options
Options for the ICP-SLAM application.
double insertionAngDistance
Minimum robot angular (rad, deg when loaded from the .ini) displacement for a new observation to be i...
Helper types for STL containers with Eigen memory allocators.
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
Declares a class for storing a collection of robot actions.
void reset()
Resets all internal state.
bool matchAgainstTheGrid
(default:false) Match against the occupancy grid or the points map? The former is quicker but less pr...
void updateDistances(const mrpt::poses::CPose2D &p)
This class allows loading and storing values and vectors of different types from a configuration text...
void enterCriticalSection()
Enter critical section for map updating.
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
mrpt::synch::CCriticalSection critZoneChangingMap
Critical zones.
const_iterator begin() const
Returns a constant iterator to the first observation: this is an example of usage: ...
CICP::TConfigParams ICP_params
Options for the ICP algorithm itself.
#define IS_DERIVED(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is an i...
float goodness
A goodness measure for the alignment, it is a [0,1] range indicator of percentage of correspondences...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
This base provides a set of functions for maths stuff.
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
TConfigParams & operator=(const TConfigParams &other)
void processUpdateNewPoseLocalization(const mrpt::math::TPose2D &newPose, mrpt::system::TTimeStamp tim)
Updates the filter with new global-coordinates localization data from a localization or SLAM source...
double norm() const
Returns the euclidean norm of vector: .
#define MRPT_LOG_WARN(_STRING)
std::string currentMapFile
Current map file.
A helper class that can convert an enum value into its textual representation, and viceversa...
std::deque< CObservationPtr >::iterator iterator
You can use CSensoryFrame::begin to get a iterator to the first element.
TConfigParams(mrpt::utils::VerbosityLevel &parent_verbosity_level)
Initializer.
#define MRPT_LOG_INFO(_STRING)
This class implements a high-performance stopwatch.
mrpt::utils::CListOfClasses alwaysInsertByClass
A list of observation classes (derived from mrpt::obs::CObservation) which will be always inserted in...
This namespace contains representation of robot actions and observations.
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
void processActionObservation(mrpt::obs::CActionCollection &action, mrpt::obs::CSensoryFrame &in_SF) MRPT_OVERRIDE
Appends a new action and observations to update this map: See the description of the class at the top...
void getCurrentlyBuiltMap(mrpt::maps::CSimpleMap &out_map) const MRPT_OVERRIDE
Fills "out_map" with the set of "poses"-"sensory-frames", thus the so far built map.
#define MRPT_LOG_WARN_STREAM(__CONTENTS)
#define MRPT_LOG_DEBUG(_STRING)
void resetRobotDisplacementCounters(const mrpt::poses::CPose2D &new_pose)
size_t size() const
Returns the count of pairs (pose,sensory data)
void loadCurrentMapFromFile(const std::string &fileName)
Load map (mrpt::maps::CSimpleMap) from a ".simplemap" file.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
unsigned short nIterations
The number of executed iterations until convergence.
GLsizei const GLchar ** string
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
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 processUpdateNewOdometry(const mrpt::math::TPose2D &newGlobalOdometry, mrpt::system::TTimeStamp cur_tim, bool hasVelocities=false, const mrpt::math::TTwist2D &newRobotVelLocal=mrpt::math::TTwist2D())
Updates the filter with new odometry readings.
bool also_interpolate
If set to true, far points (<1m) are interpolated with samples at "minDistSqrBetweenLaserPoints" inte...
void get(size_t index, mrpt::poses::CPose3DPDFPtr &out_posePDF, mrpt::obs::CSensoryFramePtr &out_SF) const
Access to the i'th pair, first one is index '0'.
#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...
mrpt::poses::CRobot2DPoseEstimator m_lastPoseEst
The pose estimation by the alignment algorithm (ICP).
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
#define MRPT_LOG_INFO_STREAM(__CONTENTS)
Declares a virtual base class for all metric maps storage classes.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
#define MRPT_LOAD_CONFIG_VAR_DEGREES(variableName, configFileObject, sectionNameStr)
Loads a double variable, stored as radians but entered in the INI-file as degrees.
void setListOfMaps(const mrpt::maps::TSetOfMetricMapInitializers *initializers)
Sets the list of internal map according to the passed list of map initializers (Current maps' content...
bool getCurrentEstimate(mrpt::math::TPose2D &pose, mrpt::math::TTwist2D &velLocal, mrpt::math::TTwist2D &velGlobal, mrpt::system::TTimeStamp tim_query=mrpt::system::now()) const
Get the estimate for a given timestamp (defaults to now()), obtained as:
const double & phi() const
Get the phi angle of the 2D pose (in radians)
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of t...
void composeFrom(const CPose2D &A, const CPose2D &B)
Makes .
CActionRobotMovement2DPtr getBestMovementEstimation() const
Returns the best pose increment estimator in the collection, based on the determinant of its pose cha...
The ICP algorithm return information.
double Tac()
Stops the stopwatch.
GLsizei GLsizei GLchar * source
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string §ion) MRPT_OVERRIDE
This method load the options from a ".ini"-like file or memory-stored string list.
mrpt::math::CMatrixDouble33 m_lastPoseEst_cov
Last pose estimation (covariance)
double localizationLinDistance
Minimum robot linear (m) displacement for a new observation to be used to do ICP-based localization (...
Algorithm configuration params.
TInsertionOptions insertionOptions
The options used when inserting observations in the map.
static CSensoryFramePtr Create()
bool m_there_has_been_an_odometry
An observation of the current (cumulative) odometry for a wheeled robot.
const_iterator end() const
Returns a constant iterator to the end of the list of observations: this is an example of usage: ...
ProxyFilterContainerByClass< mrpt::maps::CSimplePointsMapPtr, TListMaps > m_pointsMaps
STL-like proxy to access this kind of maps in maps.
This class stores any customizable set of metric maps.
void saveCurrentEstimationToImage(const std::string &file, bool formatEMF_BMP=true) MRPT_OVERRIDE
A useful method for debugging: the current map (and/or poses) estimation is dumped to an image file...
void insert(const mrpt::poses::CPose3DPDF *in_posePDF, const mrpt::obs::CSensoryFrame &in_SF)
Add a new pair to the sequence.
static CObservationOdometryPtr Create()
#define MRPT_LOG_DEBUG_STREAM(__CONTENTS)
#define ASSERTMSG_(f, __ERROR_MSG)
virtual bool isEmpty() const =0
Returns true if the map is empty/no observation has been inserted.
double insertionLinDistance
Minimum robot linear (m) displacement for a new observation to be inserted in the map...
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
float minDistBetweenLaserPoints
The minimum distance between points (in 3D): If two points are too close, one of them is not inserted...
void copyFrom(const CPosePDF &o) MRPT_OVERRIDE
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
void dumpToTextStream(mrpt::utils::CStream &out) const MRPT_OVERRIDE
This method should clearly display all the contents of the structure in textual form, sending it to a CStream.
void accumulateRobotDisplacementCounters(const mrpt::poses::CPose2D &new_pose)