ROS cartographer的安装

ROS cartographer的安装与一些坑

安装前先检查是否安装过了proto,执行

protoc --version

看看有没有,有的话可能会报错

根据官方文档开始安装

# Install wstool and rosdep.
sudo apt-get update
sudo apt-get install -y python-wstool python-rosdep ninja-build

# Create a new workspace in 'catkin_ws'.
mkdir catkin_ws
cd catkin_ws
wstool init src

这两步一般都没什么问题

这一步可能会因为网络不行报错,建议翻一下

# Merge the cartographer_ros.rosinstall file and fetch code for dependencies.
wstool merge -t src https://raw.githubusercontent.com/googlecartographer/cartographer_ros/master/cartographer_ros.rosinstall
wstool update -t src
# Install proto3.
src/cartographer/scripts/install_proto3.sh

如果前面检查发现安装了protoc2,请对proto3建立一个软连接。

sudo mv /usr/bin/protoc  /usr/bin/protoc.bk 
sudo ln -s /usr/local/bin/protoc /usr/bin/protoc

下面的老问题选手了,可以不执行

# Install deb dependencies.
# The command 'sudo rosdep init' will print an error if you have already
# executed it since installing ROS. This error can be ignored.
sudo rosdep init
rosdep update
# Build and install.
catkin_make_isolated --install --use-ninja
source install_isolated/setup.bash

这一步可能会提示找不到absl,报错如下

-- Found GMock: gmock_main;-lpthread
CMake Error at CMakeLists.txt:32 (find_package):
By not providing "Findabsl.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "absl", but
CMake did not find one.

Could not find a package configuration file provided by "absl" with any of
the following names:

abslConfig.cmake
absl-config.cmake

Add the installation prefix of "absl" to CMAKE_PREFIX_PATH or set
"absl_DIR" to a directory containing one of the above files. If "absl"
provides a separate development package or SDK, be sure it has been
installed.

碰到了可以按如下方式解决

sudo apt-get install stow
sudo chmod +x ~/carto_ws/src/cartographer/scripts/install_abseil.sh
cd ~/carto_ws/src/cartographer/scripts
./install_abseil.sh

然后再执行剩下的命令

最后是跑示例

# 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/with_intensities/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

可能会报错Error reading from file: wanted 4 bytes, read 0 bytes

原因是录制bag包后可能没有正确结束掉程序,回放出现错误,解决办法如下,修复包就行了

rosbag reindex xxx-xxx-xxx.bag
<think>好的,我现在需要帮助用户解决如何使用ROSCartographer进行建图的问题。首先,我得回忆一下用户提供的引用内容,看看有没有相关的信息可以整合进去。引用[1]提到,cartographer_ros依赖于cartographer,所以安装cartographer_ros应该会自动安装cartographer。用户可能已经遇到了安装的问题,但引用中的解释说明可能他们需要正确安装cartographer_ros。 接下来,引用[3]给出了启动建图的命令,这应该是在安装完成后的步骤。用户需要知道具体的安装步骤和启动流程。另外,引用[2]提到用户成功连接了激光雷达并显示在RVIZ中,但还没有进行调参。所以教程中可能需要包括如何配置激光雷达的数据输入,以及基本的启动步骤,可能还需要提到调参的部分作为后续工作。 用户的问题是关于ROS Cartographer SLAM的建图教程,特别是鱼香ROS的相关内容。根据引用[1],鱼香ROS可能有安装cartographer的指导,所以需要引导用户按照他们的安装步骤。可能需要分步骤说明安装、配置、启动建图以及保存地图的过程。 另外,要注意用户提到的ROS2,因为引用[3]中的命令是ros2 launch,所以需要确保教程是基于ROS2的,而不是ROS1。这可能涉及到不同的包名称和命令,比如使用ros2而不是ros,以及包名可能带有ros2的特定后缀。 接下来,我需要整理一个结构清晰的步骤指南,包括安装cartographer_ros、配置激光雷达、启动建图节点、实时显示、保存地图等。每个步骤需要给出具体的命令和可能的注意事项,比如设置TURTLEBOT3_MODEL环境变量,或者处理use_sim_time参数。 还需要考虑用户可能遇到的常见问题,比如为什么找不到cartographer包,这时候引用[1]的解释就可以用上,说明cartographer_ros的依赖关系,确保用户不会在这里卡住。 此外,用户可能需要知道如何验证安装是否成功,比如运行启动命令后是否出现错误,或者如何在RVIZ中查看点云数据。如果出现问题,可能需要检查激光雷达的话题是否匹配,或者参数配置是否正确。 最后,生成相关问题时要围绕安装、配置、调参、与其他传感器的集成以及建图后的处理步骤,这样用户可以有进一步的学习方向。 总结一下,回答的结构应该是步骤式的,每个步骤包含必要的命令和解释,引用相关的引用内容来支持关键点,比如安装说明和启动命令,最后列出相关问题引导用户深入。</think>### ROS Cartographer SLAM 建图教程 #### 1. 环境安装与配置 - **安装Cartographer ROS** 在ROS2环境中,需安装`cartographer_ros`包。由于Cartographer的编译类型限制,直接安装`cartographer_ros`时会自动包含依赖的`cartographer`核心库[^1]: ```bash sudo apt install ros-${ROS_DISTRO}-cartographer-ros ``` - **配置激光雷达数据接口** 确保激光雷达数据通过正确的ROS话题发布。默认情况下,Cartographer订阅`/scan`话题。若硬件驱动发布的话题名称不同,需在配置文件中修改映射: ```yaml # cartographer_ros/configuration_files/turtlebot3_lds_2d.lua topics = { "实际激光话题名称" } ``` #### 2. 启动建图节点 - **基础启动命令** 使用TurtleBot3示例配置启动建图(非仿真环境需移除`use_sim_time`参数)[^3]: ```bash export TURTLEBOT3_MODEL=burger # 设置机器人模型 ros2 launch turtlebot3_cartographer cartographer.launch.py ``` - **实时建图可视化** 启动RVIZ查看实时地图: ```bash ros2 run rviz2 rviz2 -d $(ros2 pkg prefix turtlebot3_cartographer)/share/turtlebot3_cartographer/config/mapping.rviz ``` #### 3. 控制机器人移动采集数据 通过键盘或导航节点控制机器人运动,激光雷达数据将实时输入Cartographer,生成栅格地图: ```bash ros2 run turtlebot3_teleop teleop_keyboard ``` #### 4. 保存生成的地图 使用`map_saver`工具保存最终地图: ```bash ros2 run nav2_map_server map_saver_cli -f ~/map ``` #### 注意事项 - **时间同步问题**:若使用仿真环境,需添加`use_sim_time:=True`参数 - **性能优化**:调整`configuration_files`中的参数(如分辨率`resolution`、子图尺寸`num_subdivisions`)以平衡精度与计算资源 - **多传感器融合**:可通过修改Lua配置文件添加IMU或里程计数据融合 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值