本文主要是介绍Cartographer学习,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
官方文档:Compiling Cartographer ROS — Cartographer ROS documentation
动手学ROS2
1、源码安装
git clone https://ghproxy.com/https://github.com/ros2/cartographer.git -b ros2
git clone https://ghproxy.com/https://github.com/ros2/cartographer_ros.git -b ros2
2、安装依赖
wget http://fishros.com/install -O fishros && . fishros
选择编号3,然后运行
rodepc update
3、编译
colcon build --packages-up-to cartographer_ros
4、查看安装是否成功
ros2 pkg list | grep cartographer
成功显示:
cartographer_ros
cartographer_ros_msgs
------------------------------------------------------------------------------------------------------------------------------
二进制安装
sudo apt install ros-humble-cartographer -y
sudo apt install ros-humble-cartographer-ros -y
5、配置参数
创建一个.lua
文件,根据情况配置
include "map_builder.lua"
include "trajectory_builder.lua"options = {map_builder = MAP_BUILDER,trajectory_builder = TRAJECTORY_BUILDER,map_frame = "map",tracking_frame = "base_link",-- base_link改为odom,发布map到odom之间的位姿态published_frame = "odom",odom_frame = "odom",-- true改为false,不用提供里程计数据provide_odom_frame = false,-- false改为true,仅发布2D位资publish_frame_projected_to_2d = true,-- false改为true,使用里程计数据use_odometry = true,use_nav_sat = false,use_landmarks = false,-- 0改为1,使用一个雷达num_laser_scans = 1,-- 1改为0,不使用多波雷达num_multi_echo_laser_scans = 0,-- 10改为1,1/1=1等于不分割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.,
}-- false改为true,启动2D SLAM
MAP_BUILDER.use_trajectory_builder_2d = true-- 0改成0.10,比机器人半径小的都忽略
TRAJECTORY_BUILDER_2D.min_range = 0.10
-- 30改成3.5,限制在雷达最大扫描范围内,越小一般越精确些
TRAJECTORY_BUILDER_2D.max_range = 3.5
-- 5改成3,传感器数据超出有效范围最大值
TRAJECTORY_BUILDER_2D.missing_data_ray_length = 3.
-- true改成false,不使用IMU数据,大家可以开启,然后对比下效果
TRAJECTORY_BUILDER_2D.use_imu_data = false
-- false改成true,使用实时回环检测来进行前端的扫描匹配
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
-- 1.0改成0.1,提高对运动的敏感度
TRAJECTORY_BUILDER_2D.motion_filter.max_angle_radians = math.rad(0.1)-- 0.55改成0.65,Fast csm的最低分数,高于此分数才进行优化。
POSE_GRAPH.constraint_builder.min_score = 0.65
--0.6改成0.7,全局定位最小分数,低于此分数则认为目前全局定位不准确
POSE_GRAPH.constraint_builder.global_localization_min_score = 0.7-- 设置0可关闭全局SLAM
-- POSE_GRAPH.optimize_every_n_nodes = 0return options
6、编写launch文件
import os
from launch import LaunchDescription
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageSharedef generate_launch_description():# 定位到功能包的地址pkg_share = FindPackageShare(package='fishbot_cartographer').find('fishbot_cartographer')#=====================运行节点需要的配置=======================================================================# 是否使用仿真时间,我们用gazebo,这里设置成trueuse_sim_time = LaunchConfiguration('use_sim_time', default='true')# 地图的分辨率resolution = LaunchConfiguration('resolution', default='0.05')# 地图的发布周期publish_period_sec = LaunchConfiguration('publish_period_sec', default='1.0')# 配置文件夹路径configuration_directory = LaunchConfiguration('configuration_directory',default= os.path.join(pkg_share, 'config') )# 配置文件configuration_basename = LaunchConfiguration('configuration_basename', default='fishbot_2d.lua')rviz_config_dir = os.path.join(pkg_share, 'config')+"/cartographer.rviz"print(f"rviz config in {rviz_config_dir}")#=====================声明三个节点,cartographer/occupancy_grid_node/rviz_node=================================cartographer_node = Node(package='cartographer_ros',executable='cartographer_node',name='cartographer_node',output='screen',parameters=[{'use_sim_time': use_sim_time}],arguments=['-configuration_directory', configuration_directory,'-configuration_basename', configuration_basename])cartographer_occupancy_grid_node = Node(package='cartographer_ros',executable='cartographer_occupancy_grid_node',name='cartographer_occupancy_grid_node',output='screen',parameters=[{'use_sim_time': use_sim_time}],arguments=['-resolution', resolution, '-publish_period_sec', publish_period_sec])rviz_node = Node(package='rviz2',executable='rviz2',name='rviz2',arguments=['-d', rviz_config_dir],parameters=[{'use_sim_time': use_sim_time}],output='screen')#===============================================定义启动文件========================================================ld = LaunchDescription()ld.add_action(cartographer_node)ld.add_action(cartographer_occupancy_grid_node)ld.add_action(rviz_node)return ld
7、保存地图
安装保存地图软件
sudo apt install ros-humble-nav2-map-server
保存地图命令
ros2 run nav2_map_server map_saver_cli -t /map -f mapname # -t 订阅的话题名,-f 保存地图名
这篇关于Cartographer学习的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!