Cartographer_ROS初探

Cartographer ROS版的官方地址:https://github.com/googlecartographer/cartographer_ros

程序的安装运行,参考了官方安装教程(https://google-cartographer-ros.readthedocs.io/en/latest/)。


环境: i7    ubuntu 14.04 + ROS indigo


安装步骤(参考官方教程)

#Install wstool and rosdep

sudo apt-get update

sudo apt-get install -y python-wstool python-rosdep ninja-build


#Create a new workspace

mkdir catkin_ws

cd catkin_ws

wstool init src


#Merge the cartographer_ros. rosinstall file and fetch code for dependences

wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall
wstool update -t src

#Install deb dependence.

rosdep init

rosdep update

rosdep rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y


#Build and install

catkin_make_isolated --install --use-ninja

source install_isolated/setup.bash


谷歌给提供了几个数据包,下载并试运行。

# Download the 2D backpack example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag

# Launch the 2D backpack demo.
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag

# Download the 3D backpack example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_3d/b3-2016-04-05-14-14-00.bag

# Launch the 3D backpack demo.
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:=${HOME}/Downloads/b3-2016-04-05-14-14-00.bag

# Download the Revo LDS example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/revo_lds/cartographer_paper_revo_lds.bag

# Launch the Revo LDS demo.
roslaunch cartographer_ros demo_revo_lds.launch bag_filename:=${HOME}/Downloads/cartographer_paper_revo_lds.bag

# Download the PR2 example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/pr2/2011-09-15-08-32-46.bag

# Launch the PR2 demo.
roslaunch cartographer_ros demo_pr2.launch bag_filename:=${HOME}/Downloads/2011-09-15-08-32-46.bag

# Download the Taurob Tracker example bag.
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/taurob_tracker/taurob_tracker_simulation.bag

# Launch the Taurob Tracker demo.
roslaunch cartographer_ros demo_taurob_tracker.launch bag_filename:=${HOME}/Downloads/taurob_tracker_simulation.bag


运行结果:

2D backpack example bag的效果:

实验机内存8G,随着代码的运行,内存占用越来越大,,切换界面会有明显的卡顿感。


以上主要记录了个人的操作步骤,请以官方教程为主。

### ROS2 Galactic 中 cartographer_ros 的使用指南 #### 安装与配置 在 ROS2 Galactic 下安装 `cartographer_ros` 可通过源码编译完成。以下是具体操作方法: 1. 创建一个新的工作空间并克隆仓库: ```bash mkdir -p ~/ros2_galactic_ws/src cd ~/ros2_galctic_ws/src git clone https://github.com/ros2/cartographer_ros.git -b galactic-devel ``` 2. 编译依赖项并构建项目: ```bash vcs import < cartographer_ros/cartographer_ros.repos --recursive colcon build --symlink-install --packages-up-to cartographer_ros source install/setup.bash ``` 上述命令会下载必要的依赖包,并针对银河版 (Galactic) 进行适配[^1]。 3. 验证安装成功与否可以通过运行示例文件来测试: ```bash ros2 launch cartographer_ros demo_backpack_2d.launch.py ``` 此外,也可以启动 Rviz 查看效果: ```bash ros2 run rviz2 rviz2 -d ~/ros2_galactic_ws/src/cartographer_ros/cartographer_ros/configuration_files/demo_2d.rviz ``` 以上步骤展示了如何基于官方文档设置环境以及验证功能正常运作的情况[^4]。 #### 动态地图与导航集成 对于希望直接利用由 `cartographer_ros` 所产生的 SLAM 地图来进行路径规划的应用场景而言,无需额外转换至 PGM 文件再加载到 map_server 。而是可以直接订阅 `/map` 主题消息作为输入给全局或者局部成本映射器使用[^3]。 例如,在 AMCL 或者其他粒子滤波定位算法中,只需修改参数文件中的静态地图来源即可切换为实时更新的地图数据流: ```yaml global_costmap: static_layer: map_topic: /map ``` 这样做的好处在于能够即时反映环境中变化的部分,从而提高机器人应对复杂情况的能力。 #### 示例代码展示 下面给出一段简单的 Python 脚本例子说明怎样获取来自 Cartographer 发布的地图信息: ```python import rclpy from nav_msgs.msg import OccupancyGrid def callback(msg): print(f"Received new map with resolution {msg.info.resolution}") def main(args=None): rclpy.init(args=args) node = rclpy.create_node('map_subscriber') subscription = node.create_subscription( OccupancyGrid, '/map', callback, 10) while rclpy.ok(): rclpy.spin_once(node) if __name__ == '__main__': main() ``` 此脚本创建了一个节点用来监听 `/map` 主题上的新消息到达事件,并打印其分辨率属性值[^2]。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值