openEuler 24.03 安装 Cartographer 教程
标签
ROS2
cartographer
ROS2-humble
openEuler
字数
824 字
阅读时间
4 分钟
本教程将指导您在 openEuler 24.03 LTS SP2 + ROS2 humble 环境中安装和配置 Cartographer SLAM 系统。
方法一:使用二进制包安装
这是最简单快捷的安装方法,适合大多数用户。
WARNING
目前 openEuler-ROS 源里的 cartographer 还存在一些问题,请使用从源码编译安装教程
1. 更新系统
bash
sudo dnf update2. 安装 Cartographer
对于 ROS2 Humble:
bash
sudo dnf install ros-humble-cartographer ros-humble-cartographer-ros3. 配置环境
将以下内容添加到您的 ~/.bashrc 文件中:
bash
source /opt/ros/humble/setup.bash然后刷新环境:
bash
source ~/.bashrc4. 验证安装
检查 Cartographer 是否正确安装:
bash
ros2 pkg list | grep cartographer您应该看到类似以下输出:
cartographer_ros
cartographer_ros_msgs方法二:从源码编译安装
如果您需要最新功能或需要自定义修改,可以选择从源码编译。
1. 安装依赖工具
安装colcon:
bash
pip3 install -U pytest colcon-common-extensions安装后可能需要添加环境变量才能使用colcon命令
bash
export PATH=$PATH:/home/openeuler/.local/bin2. 创建工作空间
bash
mkdir -p ~/cartographer_ws/src
cd ~/cartographer_ws3. 下载源码
bash
cd ~/cartographer_ws/src
git clone -b oe-fix https://github.com/discodyer/cartographer.git
git clone -b oe-fix https://github.com/discodyer/cartographer_ros.git4. 安装依赖
安装一些 cartographer 相关依赖
bash
sudo dnf update
sudo dnf install boost-devel eigen3-devel abseil-cpp-devel cairo-devel ceres-solver-devel gflags-devel glog-devel lua-devel protobuf-devel git gmock-devel gtest-devel python3-sphinx cmake5. 编译
bash
cd ~/cartographer_ws
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=ReleaseTIP
如果编译过程中遇到内存不足的问题,可以限制并行编译任务数:
bash
colcon build --symlink-install --parallel-workers 1 --cmake-args -DCMAKE_BUILD_TYPE=Release6. 配置环境
将工作空间添加到 ~/.bashrc:
bash
echo "source ~/cartographer_ws/install/setup.bash" >> ~/.bashrc
source ~/.bashrc或者仅在当前终端中加载:
bash
source ~/cartographer_ws/install/setup.bash安装验证和测试
1. 下载测试数据
下载示例 bag 文件:
bash
mkdir -p ~/Downloads
cd ~/Downloads
wget https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag2. 转换 ROS1 bag 到 ROS2(如需要)
如果您下载的是 ROS1 格式的 bag 文件,需要转换:
bash
# 安装转换工具
sudo apt install ros-${ROS_DISTRO}-rosbag2-bag-v2-plugins
# 转换 bag 文件
ros2 bag convert --input cartographer_paper_deutsches_museum.bag --output-options output.yaml3. 运行 Cartographer
创建一个简单的启动文件 demo_2d.launch.py:
python
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
DeclareLaunchArgument('use_sim_time', default_value='true'),
Node(
package='cartographer_ros',
executable='cartographer_node',
name='cartographer_node',
output='screen',
parameters=[{'use_sim_time': LaunchConfiguration('use_sim_time')}],
arguments=[
'-configuration_directory', '/opt/ros/${ROS_DISTRO}/share/cartographer_ros/configuration_files',
'-configuration_basename', 'backpack_2d.lua'
]
),
Node(
package='cartographer_ros',
executable='cartographer_occupancy_grid_node',
name='cartographer_occupancy_grid_node',
output='screen',
parameters=[{'use_sim_time': LaunchConfiguration('use_sim_time')}]
),
])下一步
安装完成后,您可以:
- 阅读 参数实战调优 - 基于实战经验的参数调优指南,包含传感器配置、前端/后端参数调整、常见问题解决方案。
- 查看 在演示包上运行 Cartographer ROS - 学习基本使用
- 参考 算法调优指南 - 深入讲解 Cartographer 的系统架构、局部/全局 SLAM 原理、扫描匹配和优化机制。
- 参考 调优方法论 - 系统化的调优方法,通过实际案例讲解如何调优局部 SLAM、降低延迟、配置纯定位模式。
Cody Gu