7 #include <mrpt/version.h> 8 #include <mrpt_bridge/utils.h> 11 #if MRPT_VERSION >= 0x199 12 #include <mrpt/serialization/CArchive.h> 18 std::string sOutMap =
"mrpt_rbpfslam_";
19 mrpt::system::TTimeParts parts;
20 mrpt::system::timestampToParts(mrpt::system::now(), parts,
true);
22 mrpt::format(
"%04u-%02u-%02u_%02uh%02um%02us", (
unsigned int)parts.year,
23 (
unsigned int)parts.month, (
unsigned int)parts.day,
24 (
unsigned int)parts.hour, (
unsigned int)parts.minute,
25 (
unsigned int)parts.second);
26 sOutMap +=
".simplemap";
28 sOutMap = mrpt::system::fileNameStripInvalidChars(sOutMap);
33 <<
" doesn't exist, cannot save simplemap there! Default " 34 "'~/.ros/' path will be used.\n";
36 std::cout <<
"Saving built map " << sOutMap <<
"\n";
38 }
catch (
const std::exception &e) {
39 std::cerr <<
"Exception: " << e.what() <<
"\n";
44 #if MRPT_VERSION >= 0x199 45 mrpt::config::CConfigFile iniFile(ini_filename);
47 mrpt::utils::CConfigFile iniFile(ini_filename);
50 "MappingApplication");
55 const std::string &rawlog_filename,
56 std::vector<std::pair<mrpt::obs::CActionCollection,
57 mrpt::obs::CSensoryFrame>> &data) {
58 size_t rawlogEntry = 0;
59 #if MRPT_VERSION >= 0x199 60 mrpt::io::CFileGZInputStream rawlog_stream(rawlog_filename);
61 auto rawlogFile = mrpt::serialization::archiveFrom(rawlog_stream);
63 mrpt::utils::CFileGZInputStream rawlogFile(rawlog_filename);
65 mrpt::obs::CActionCollection::Ptr
action;
66 mrpt::obs::CSensoryFrame::Ptr observations;
69 if (mrpt::system::os::kbhit()) {
70 char c = mrpt::system::os::getch();
77 if (!mrpt::obs::CRawlog::readActionObservationPair(
78 rawlogFile, action, observations, rawlogEntry)) {
81 data.emplace_back(*action, *observations);
86 const mrpt::obs::CSensoryFrame::ConstPtr sensory_frame,
87 const mrpt::obs::CObservationOdometry::ConstPtr odometry) {
88 action_ = mrpt::obs::CActionCollection::Create();
89 mrpt::obs::CActionRobotMovement2D odom_move;
90 odom_move.timestamp = sensory_frame->getObservationByIndex(0)->timestamp;
105 log4cxx::LoggerPtr ros_logger =
108 mrpt_bridge::rosLoggerLvlToMRPTLoggerLvl(ros_logger->getLevel()));
110 #if MRPT_VERSION < 0x199 111 mapBuilder_.logRegisterCallback(static_cast<output_logger_callback_t>(
112 &mrpt_bridge::mrptToROSLoggerCallback_mrpt_15));
114 mapBuilder_.logRegisterCallback(static_cast<output_logger_callback_t>(
115 &mrpt_bridge::mrptToROSLoggerCallback));
120 #if MRPT_VERSION >= 0x199 121 mrpt::random::getRandomGenerator().randomize();
123 mrpt::random::randomGenerator.randomize();
151 #if MRPT_HAS_WXWIDGETS 153 win3D_ = mrpt::gui::CDisplayWindow3D::Create(
156 win3D_->setCameraZoom(40);
157 win3D_->setCameraAzimuthDeg(-50);
158 win3D_->setCameraElevationDeg(70);
168 mrpt::opengl::COpenGLScene::Ptr scene;
169 scene = mrpt::opengl::COpenGLScene::Create();
172 mrpt::opengl::CGridPlaneXY::Ptr groundPlane =
173 mrpt::opengl::CGridPlaneXY::Create(-200, 200, -200, 200, 0, 5);
174 groundPlane->setColor(0.4, 0.4, 0.4);
175 scene->insert(groundPlane);
179 mrpt::opengl::CCamera::Ptr objCam = mrpt::opengl::CCamera::Create();
180 mrpt::poses::CPose3D robotPose;
181 curPDF.getMean(robotPose);
183 objCam->setPointingAt(robotPose);
184 objCam->setAzimuthDegrees(-30);
185 objCam->setElevationDegrees(30);
186 scene->insert(objCam);
189 mrpt::opengl::CSetOfObjects::Ptr objs =
190 mrpt::opengl::CSetOfObjects::Create();
196 mrpt::opengl::CSetOfLines::Ptr objLines =
197 mrpt::opengl::CSetOfLines::Create();
198 objLines->setColor(0, 1, 1);
199 for (
size_t i = 0; i < M; i++) {
200 std::deque<mrpt::math::TPose3D> path;
203 float x0 = 0, y0 = 0, z0 = 0;
204 for (
size_t k = 0; k < path.size(); k++) {
205 objLines->appendLine(x0, y0, z0 + 0.001, path[k].
x, path[k].
y,
212 scene->insert(objLines);
215 mrpt::poses::CPose3D lastMeanPose;
216 float minDistBtwPoses = -1;
217 std::deque<mrpt::math::TPose3D> dummyPath;
219 for (
int k = (
int)dummyPath.size() - 1; k >= 0; k--) {
220 mrpt::poses::CPose3DPDFParticles poseParts;
221 mapBuilder_.mapPDF.getEstimatedPosePDFAtTime(k, poseParts);
223 #if MRPT_VERSION >= 0x199 224 const auto [COV, meanPose] = poseParts.getCovarianceAndMean();
226 mrpt::poses::CPose3D meanPose;
227 mrpt::math::CMatrixDouble66 COV;
228 poseParts.getCovarianceAndMean(COV, meanPose);
231 if (meanPose.distanceTo(lastMeanPose) > minDistBtwPoses) {
232 mrpt::math::CMatrixDouble33 COV3 =
233 #if MRPT_VERSION >= 0x199 234 COV.blockCopy<3, 3>(0, 0);
236 COV.block(0, 0, 3, 3);
239 minDistBtwPoses = 6 * sqrt(COV3(0, 0) + COV3(1, 1));
241 mrpt::opengl::CEllipsoid::Ptr objEllip =
242 mrpt::opengl::CEllipsoid::Create();
243 objEllip->setLocation(meanPose.x(), meanPose.y(), meanPose.z() + 0.001);
244 objEllip->setCovMatrix(COV3, COV3(2, 2) == 0 ? 2 : 3);
246 objEllip->setColor(0, 0, 1);
247 objEllip->enableDrawSolid3D(
false);
248 scene->insert(objEllip);
250 lastMeanPose = meanPose;
254 mrpt::opengl::COpenGLScene::Ptr &scenePtr =
win3D_->get3DSceneAndLock();
256 win3D_->unlockAccess3DScene();
mrpt::slam::CMetricMapBuilderRBPF::TConstructionOptions rbpfMappingOptions_
options for SLAM from ini file
void observation(const mrpt::obs::CSensoryFrame::ConstPtr sensory_frame, const mrpt::obs::CObservationOdometry::ConstPtr odometry)
Calculate the actions from odometry model for current observation.
int PROGRESS_WINDOW_WIDTH_
mrpt::poses::CPose3DPDFParticles curPDF
current robot pose
TFSIMD_FORCE_INLINE const tfScalar & y() const
int PROGRESS_WINDOW_HEIGHT_
mrpt::gui::CDisplayWindow3D::Ptr win3D_
MRPT window.
struct mrpt_rbpf_slam::PFslam::Options options_
void readIniFile(const std::string &ini_filename)
Read ini file.
mrpt::slam::CMetricMapBuilderRBPF mapBuilder_
map builder
void initSlam(Options options)
initialize the SLAM
mrpt::obs::CActionCollection::Ptr action_
actions
TFSIMD_FORCE_INLINE const tfScalar & x() const
void readRawlog(const std::string &rawlog_filename, std::vector< std::pair< mrpt::obs::CActionCollection, mrpt::obs::CSensoryFrame >> &data)
Read pairs of actions and observations from rawlog file.
const mrpt::maps::CMultiMetricMap * metric_map_
receive map after iteration of SLAM to metric map
TFSIMD_FORCE_INLINE const tfScalar & z() const
bool SHOW_PROGRESS_IN_WINDOW_
mrpt::poses::CPose2D odomLastObservation_
last observation of odometry
std::string simplemap_path_prefix
bool CAMERA_3DSCENE_FOLLOWS_ROBOT_
#define ROSCONSOLE_DEFAULT_NAME
mrpt::obs::CActionRobotMovement2D::TMotionModelOptions motion_model_options_