当前位置: 首页 > news >正文

ROS2安装cartographer

2. 安装Cartographer和Cartographer ROS

使用apt安装(推荐):

bash

sudo apt install ros-humble-cartographer-ros

或者,从源代码安装:

bash

sudo apt-get update
sudo apt-get install -y python3-wstool python3-rosdep ninja-build stow
mkdir -p ~/cartographer_ws/src
cd ~/cartographer_ws
wstool init src
cd src
git clone -b ros2 https://github.com/ros2/cartographer.git
git clone -b ros2 https://github.com/ros2/cartographer_ros.git
wstool update -t src
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro=humble -y
colcon build
source install/setup.bash

3. 创建ROS 2工作空间

bash

mkdir -p ~/ros2_cartographer_ws/src
cd ~/ros2_cartographer_ws/src

4. 创建启动文件

在src文件夹中,创建一个名为cartographer_ros的包(如果还没有的话):

bash

ros2 pkg create --build-type ament_cmake cartographer_ros

在cartographer_ros包中,创建launch和config文件夹:

bash

mkdir launch config

在launch文件夹中创建启动文件demo_my_robot_2d.launch.py:

python

from launch import LaunchDescription
from launch_ros.actions import Node, IncludeLaunchDescription, ExecuteProcess
import launch
import launch_ros
def generate_launch_description():use_sim_time_arg = launch.actions.DeclareLaunchArgument('use_sim_time', default_value='false')bag_filename_arg = launch.actions.DeclareLaunchArgument('bag_filename')my_robot_2d_launch = IncludeLaunchDescription(PythonLaunchDescriptionSource([launch_ros.substitutions.TextSubstitution(text='~/cartographer_ros/launch/my_robot_2d.launch.py')]),launch_arguments={'use_sim_time': 'True'}.items())rviz_node = Node(package='rviz2',executable='rviz2',arguments=['-d', '~/cartographer_ros/config/demo_2d.rviz'],parameters=[{'use_sim_time': True}],)ros2_bag_play_cmd = ExecuteProcess(cmd=['ros2', 'bag', 'play', bag_filename_arg],name='rosbag_play',)return LaunchDescription([use_sim_time_arg,bag_filename_arg,my_robot_2d_launch,rviz_node,ros2_bag_play_cmd])

5. 创建配置文件

在config文件夹中创建一个名为my_robot_2d.lua的配置文件:

lua

options = {map_frame = "map",tracking_frame = "lidar_link",published_frame = "lidar_link",odom_frame = "odom",provide_odom_frame = false,publish_frame_projected_to_2d = true,use_pose_extrapolator = true,use_odometry = false,use_nav_sat = false,use_landmarks = false,num_laser_scans = 1,num_multi_echo_laser_scans = 0,num_subdivisions_per_laser_scan = 1,num_point_clouds = 0,lookup_transform_timeout_sec = 0.2,submap_publish_period_sec = 0.3,pose_publish_period_sec = 5e-3,trajectory_publish_period_sec = 30e-3,rangefinder_sampling_ratio = 1.,odometry_sampling_ratio = 1.,fixed_frame_pose_sampling_ratio = 1.,imu_sampling_ratio = 1.,landmarks_sampling_ratio = 1.,
}
MAP_BUILDER.use_trajectory_builder_2d = true
TRAJECTORY_BUILDER_2D.min_range = 0.5
TRAJECTORY_BUILDER_2D.max_range = 30
TRAJECTORY_BUILDER_2D.missing_data_ray_length = 3.
TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
TRAJECTORY_BUILDER_2D.motion_filter.max_distance_meters = 0.05
TRAJECTORY_BUILDER_2D.motion_filter.max_angle_radians = math.rad(0.1)
TRAJECTORY_BUILDER_2D.motion_filter.max_time_seconds = 0.2
POSE_GRAPH.constraint_builder.min_score = 0.65
POSE_GRAPH.constraint_builder.global_localization_min_score = 0.7

6. 构建工作空间

回到工作空间的根目录:

bash

cd ~/ros2_cartographer_ws

安装依赖并构建:

bash

rosdep install --from-paths src --ignore-src --rosdistro=humble -y
colcon build --packages-up-to cartographer_ros
source install/setup.bash

7. 启动Cartographer进行建图

运行启动文件:

bash

ros2 launch cartographer_ros demo_my_robot_2d.launch.py bag_filename:=/path/to/your/bagfile.bag

将/path/to/your/bagfile.bag替换为您的激光雷达数据包的实际路径。

8. 使用RViz可视化

启动RViz并加载配置文件:

bash

ros2 run rviz2 rviz2 -d ~/ros2_cartographer_ws/src/cartographer_ros/config/demo_2d.rviz

9. 保存地图

生成并保存地图:

bash

ros2 run map_server map_saver -f your_map

这将生成your_map.pgm和your_map.yaml文件。

以上步骤提供了一个完整的流程,从安装到配置再到运行Cartographer进行激光建图。请根据您的具体需求调整路径和参数。

http://www.lryc.cn/news/450262.html

相关文章:

  • kafka测试
  • 总结C/C++中内存区域划分
  • 第168天:应急响应-ELK 日志分析系统Yara规则样本识别特征提取规则编写
  • MySQL 面试题及答案
  • vue仿chatGpt的AI聊天功能--大模型通义千问(阿里云)
  • 养老院管理系统(含源码+sql+视频导入教程+文档)
  • 大数据的挑战是小文件
  • 迁移学习案例-python代码
  • MCUboot 和 U-Boot区别
  • Apache OFBiz SSRF漏洞CVE-2024-45507分析
  • 计算机毕业设计 饮食营养管理信息系统的设计与实现 Java实战项目 附源码+文档+视频讲解
  • 828华为云征文|华为云Flexus云服务器X实例部署——盲盒抽奖商城系统以及编译发布小程序
  • 优化理论及应用精解【12】
  • excel 填充内容的公式
  • 这款工具在手,前端开发轻松搞定!
  • Hadoop三大组件之HDFS(一)
  • 基于Hadoop的NBA球员大数据分析及可视化系统
  • docker容器安装nginx
  • LC记录一:寻找旋转数组最小值、判断旋转数组是否存在给定元素
  • 关于 JVM 个人 NOTE
  • 网络工程和信息安全专业应该考哪些证书?
  • ASP.NET Core 创建使用异步队列
  • 从Linux系统的角度看待文件-基础IO
  • 总结之Coze 是一站式 AI Bot 开发平台——工作流使用及coze总结(三)
  • 汽车线束之故障诊断方案-TDR测试
  • 自己做个国庆75周年头像生成器
  • 2k1000LA loongnix 安装java
  • 中信银行西安分行:构建科技金融体质 做好科技金融“大文章”
  • Linux系统性能调优技巧详解
  • MFC工控项目实例之十九手动测试界面输出信号切换