Python example: rbpf_slam.py
This example shows how to build a metric map using the RBPF-SLAM algorithm:
1#!/usr/bin/env python3
2
3# ---------------------------------------------------------------------
4# Install python3-pymrpt, ros-$ROS_DISTRO-python-mrpt,
5# ros-$ROS_DISTRO-mrpt2, or test with a local build with:
6# export PYTHONPATH=$HOME/code/mrpt/build-Release/:$PYTHONPATH
7# ---------------------------------------------------------------------
8
9# RBPF-SLAM: builds a gridmap from a 2D lidar dataset.
10#
11# Usage example:
12#
13# ./rbpf_slam.py --help
14#
15# ./rbpf_slam.py -c ../share/mrpt/config_files/rbpf-slam/gridmapping_optimal_sampling.ini ../share/mrpt/datasets/2006-01ENE-21-SENA_Telecom\ Faculty_one_loop_only.rawlog
16#
17
18from mrpt.pymrpt import mrpt
19import argparse
20
21# args
22parser = argparse.ArgumentParser()
23parser.add_argument('rawlog', help='Rawlog file.')
24parser.add_argument('-c', '--config', help='Config file.')
25parser.add_argument(
26 '-o', '--output', help='Save final map as to file with this prefix name.', default='final_map')
27args = parser.parse_args()
28
29# get filenames from args
30rawlog_filename = args.rawlog
31config_filename = args.config
32output_filename = args.output
33
34# Instance SLAM app, init, and run SLAM:
35app = mrpt.apps.RBPF_SLAM_App_Rawlog()
36
37app.init(iniConfigFile=config_filename, rawlogFile=rawlog_filename)
38
39app.run()
40
41# Get last built map
42app.mapBuilder.saveCurrentMapToFile('final_map.simplemap')
43
44# Save map:
45print('saving final map to: "{}_*"'.format(output_filename))
46
47metricMap = app.mapBuilder.getCurrentlyBuiltMetricMap()
48metricMap.saveMetricMapRepresentationToFile(output_filename)