foxy 的cartographer_ros 和dashing 的兼容

cd  ~/xx__ws/src

安装源码

git clone https://ghproxy.com/https://github.com/ros2/cartographer.git -b foxy

git clone https://ghproxy.com/https://github.com/ros2/cartographer_ros.git -b dashing

安装依赖

sudo apt update
sudo apt install -y \
    clang \
    cmake \
    g++ \
    git \
    google-mock \
    libceres-dev \
    liblua5.3-dev \
    libboost-all-dev \
    libprotobuf-dev \
    protobuf-compiler \
    libeigen3-dev \
    libgflags-dev \
    libgoogle-glog-dev \
    libcairo2-dev \
    libpcl-dev \
    libsuitesparse-dev \
    python3-sphinx \
    lsb-release \
    ninja-build \
    stow

lua文件:


include "map_builder.lua"
include "trajectory_builder.lua"options = {map_builder = MAP_BUILDER,trajectory_builder = TRAJECTORY_BUILDER,map_frame = "map",tracking_frame = "gyro_link",published_frame = "base_footprint",odom_frame = "odom",provide_odom_frame = true,publish_frame_projected_to_2d = false,-- publish_tracked_pose=true, --发布小车位置use_odometry = true,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
MAP_BUILDER.num_background_threads = 2
-- TRAJECTORY_BUILDER.pure_localization_trimmer.max_submaps_to_keep = 3
TRAJECTORY_BUILDER_2D.submaps.num_range_data = 45
TRAJECTORY_BUILDER_2D.min_range = 0.1
TRAJECTORY_BUILDER_2D.max_range = 6.
TRAJECTORY_BUILDER_2D.missing_data_ray_length = 1.
TRAJECTORY_BUILDER_2D.use_imu_data = true --是否使用imu数据TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
-- TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.linear_search_window = 0.1
-- TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.angular_search_window = math.rad(10.) --角度搜索框的大小
-- TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.translation_delta_cost_weight = 10.
-- TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.rotation_delta_cost_weight = 1e-1TRAJECTORY_BUILDER_2D.motion_filter.max_distance_meters = 0.05  --运动滤波更新距离   // 如果移动距离过小, 或者时间过短, 不进行地图的更新
TRAJECTORY_BUILDER_2D.motion_filter.max_angle_radians = math.rad(0.03)
TRAJECTORY_BUILDER_2D.motion_filter.max_time_seconds = 0.5TRAJECTORY_BUILDER_2D.ceres_scan_matcher.ceres_solver_options.num_threads = 1
TRAJECTORY_BUILDER_2D.ceres_scan_matcher.ceres_solver_options.max_num_iterations = 20  --迭代次数POSE_GRAPH.optimization_problem.huber_scale = 1e2POSE_GRAPH.constraint_builder.max_constraint_distance = 15.
POSE_GRAPH.constraint_builder.sampling_ratio = 0.03
POSE_GRAPH.constraint_builder.min_score = 0.50POSE_GRAPH.constraint_builder.global_localization_min_score = 0.60
POSE_GRAPH.optimize_every_n_nodes = 35return options

建图launch:

import os
from launch import LaunchDescription
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from ament_index_python.packages import get_package_share_directoryfrom launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSourcedef generate_launch_description():# 定位到功能包的地址pkg_share = FindPackageShare(package='carerobot_pkg').find('carerobot_pkg')scan_dir = get_package_share_directory('rplidar_ros')scan_launch_dir = os.path.join(scan_dir, 'launch') #雷达launch文件路径serial_dir = get_package_share_directory('serial_pkg')serial_launch_dir = os.path.join(serial_dir, 'launch') #串口launch文件路径remappings = [('/tf', 'tf'),('/tf_static', 'tf_static')]urdf = os.path.join(pkg_share, 'urdf', 'careRobot.urdf') #模型#=====================运行节点需要的配置=======================================================================# 是否使用仿真时间,我们用gazebo,这里设置成trueuse_sim_time = LaunchConfiguration('use_sim_time', default='false')# 地图的分辨率resolution = LaunchConfiguration('resolution', default='0.01')# 地图的发布周期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='careRobot_2d.lua')start_robot_state_publisher_cmd = Node(  #发布小车TF信息package='robot_state_publisher',executable='robot_state_publisher',  remappings=remappings,arguments=[urdf])joint_state_publisher_node = Node(package='joint_state_publisher',executable='joint_state_publisher',  remappings=remappings,arguments=[urdf])serial_cmd = IncludeLaunchDescription(  #串口开启PythonLaunchDescriptionSource(os.path.join(serial_launch_dir, 'serial_pkg.launch.py')),launch_arguments={'namespace': '','use_namespace': 'False'}.items())scan_cmd = IncludeLaunchDescription(  #雷达开启PythonLaunchDescriptionSource(os.path.join(scan_launch_dir, 'rplidar_A1.launch.py')),launch_arguments={'namespace': '','use_namespace': 'False'}.items())#=====================声明三个节点,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])occupancy_grid_node = Node(package='cartographer_ros',executable='occupancy_grid_node',name='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(serial_cmd)ld.add_action(scan_cmd)# Add the actions to launch all of the navigation nodesld.add_action(start_robot_state_publisher_cmd)ld.add_action(joint_state_publisher_node)  ld.add_action(cartographer_node)ld.add_action(occupancy_grid_node)# ld.add_action(rviz_node)  在虚拟机上面远程启动return ld

地图保存1:ros2 run nav2_map_server map_saver_cli -t map -f   name    //只是文件名  xx.yaml xx.pgm

地图保存2:

ros2 service call /write_state cartographer_ros_msgs/srv/WriteState "{filename: 'path/cartorapher.pbstream'}"  //绝对路径

ros2 service call /finish_trajectory cartographer_ros_msgs/srv/FinishTrajectory "{trajectory_id: '0'}"  //结束轨迹

定位launch:

import os
from launch import LaunchDescription
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from ament_index_python.packages import get_package_share_directoryfrom launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSourcefrom nav2_common.launch import RewrittenYaml#定位 launchdef generate_launch_description():# 定位到功能包的地址pkg_share = FindPackageShare(package='carerobot_pkg').find('carerobot_pkg')scan_dir = get_package_share_directory('rplidar_ros')scan_launch_dir = os.path.join(scan_dir, 'launch') #雷达launch文件路径serial_dir = get_package_share_directory('serial_pkg')serial_launch_dir = os.path.join(serial_dir, 'launch') #串口launch文件路径remappings = [('/tf', 'tf'),('/tf_static', 'tf_static')]urdf = os.path.join(pkg_share, 'urdf', 'careRobot.urdf') #模型#=====================运行节点需要的配置=======================================================================# 是否使用仿真时间,我们用gazebo,这里设置成trueuse_sim_time = LaunchConfiguration('use_sim_time', default='false')# 地图的分辨率resolution = LaunchConfiguration('resolution', default='0.01')# 地图的发布周期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='careRobot_2d.lua')autostart = LaunchConfiguration('autostart', default='True')#配置地图configuration_map = LaunchConfiguration('configuration_map', default=os.path.join(pkg_share, 'maps', 'careRobot.pbstream'))map_yaml_file = LaunchConfiguration('configuration_map', default=os.path.join(pkg_share, 'maps', 'careRobot.yaml'))#配置导航文件configuration_nav_params =  LaunchConfiguration('configuration_nav_params', default=os.path.join(pkg_share, 'params', 'careRobot_nav.yaml'))default_bt_xml_filename = LaunchConfiguration('default_bt_xml_filename', default=os.path.join(get_package_share_directory('nav2_bt_navigator'),'behavior_trees', 'navigate_w_replanning_and_recovery.xml'))map_subscribe_transient_local = LaunchConfiguration('map_subscribe_transient_local', default='True')namespace = LaunchConfiguration('namespace', default='')lifecycle_nodes = ['controller_server','planner_server','recoveries_server','bt_navigator','waypoint_follower']serial_cmd = IncludeLaunchDescription(  #串口开启PythonLaunchDescriptionSource(os.path.join(serial_launch_dir, 'serial_pkg.launch.py')),launch_arguments={'namespace': '','use_namespace': 'False'}.items())scan_cmd = IncludeLaunchDescription(  #雷达开启PythonLaunchDescriptionSource(os.path.join(scan_launch_dir, 'rplidar_A1.launch.py')),launch_arguments={'namespace': '','use_namespace': 'False'}.items())#=====================声明三个节点,cartographer/occupancy_grid_node/rviz_node=================================start_robot_state_publisher_cmd = Node(  #发布小车TF信息package='robot_state_publisher',executable='robot_state_publisher',  remappings=remappings,arguments=[urdf])joint_state_publisher_node = Node(package='joint_state_publisher',executable='joint_state_publisher',  remappings=remappings,arguments=[urdf])cartographer_node = Node(package = 'cartographer_ros',executable = 'cartographer_node',name='cartographer_node',parameters = [{'use_sim_time': True}],arguments = ['-configuration_directory',configuration_directory,     #配置文件路径'-configuration_basename', configuration_basename,      #配置文件名'-load_state_filename', configuration_map               #pbstream地图],# remappings = [#     ('echoes', 'horizontal_laser_2d')],output = 'screen')occupancy_grid_node = Node(package='cartographer_ros',executable='occupancy_grid_node',name='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')param_substitutions = {'use_sim_time': use_sim_time,'default_bt_xml_filename': default_bt_xml_filename,'autostart': autostart,'map_subscribe_transient_local': map_subscribe_transient_local}configured_params = RewrittenYaml(source_file=configuration_nav_params,root_key=namespace,param_rewrites=param_substitutions,convert_types=True)nav2_controller_node= Node( #导航控制器package='nav2_controller',executable='controller_server',output='screen',parameters=[configured_params],remappings=remappings)nav2_planner_node=Node( #导航归化器package='nav2_planner',executable='planner_server',name='planner_server',output='screen',parameters=[configured_params],remappings=remappings)nav2_recoveries_node=Node( #导航恢复package='nav2_recoveries',executable='recoveries_server',name='recoveries_server',output='screen',parameters=[configured_params],remappings=remappings)nav2_bt_navigator_node=Node( #行为树package='nav2_bt_navigator',executable='bt_navigator',name='bt_navigator',output='screen',parameters=[configured_params],remappings=remappings)nav2_waypoint_follower_node=Node(#点跟随package='nav2_waypoint_follower',executable='waypoint_follower',name='waypoint_follower',output='screen',parameters=[configured_params],remappings=remappings)nav2_lifecycle_manager_node=Node( #生命周期package='nav2_lifecycle_manager',executable='lifecycle_manager',name='lifecycle_manager_navigation',output='screen',parameters=[{'use_sim_time': use_sim_time},{'autostart': autostart},{'node_names': lifecycle_nodes}])#===============================================定义启动文件========================================================ld = LaunchDescription()ld.add_action(serial_cmd)ld.add_action(scan_cmd)# Add the actions to launch all of the navigation nodesld.add_action(start_robot_state_publisher_cmd)ld.add_action(joint_state_publisher_node)  ld.add_action(cartographer_node)ld.add_action(occupancy_grid_node)ld.add_action(nav2_controller_node)ld.add_action(nav2_planner_node)ld.add_action(nav2_recoveries_node)ld.add_action(nav2_bt_navigator_node)ld.add_action(nav2_waypoint_follower_node)ld.add_action(nav2_lifecycle_manager_node)#ld.add_action(rviz_node)return ld

ros2 -foxy安装cartographer建图定位-- 源码安装 使用相关推荐

  1. linux编译安装的好处,Linux学习—源码安装

    源码安装--可以按照自己的需求安装,这是源码安装的好处,而二进制安装无法选择 大部分的源码安装步骤大致相同,具体细节可以参考解压缩之后的README和INSTALL README: 介绍了软件包的功能 ...

  2. centos 源码安装mysql5.6_CentOS 7下源码安装MySQL 5.6

    目录 准备工作 运行环境 确认你的安装版本 下载MySQL 安装MySQL 准备安装环境 编译和安装 配置MySQL 单实例配置 单实例配置方法 添加防火墙 启动MySQL 重启MySQL 多实例配置 ...

  3. python2.7安装报错_python2.7源码安装方式

    安装python2.7 下载Python 2.7, 下载地址 解压安装 tar -xzvf Python-2.7.15.tgz cd Python-2.7.15 ./configure --prefi ...

  4. centos 7 mysql 源码安装_centos7 mysql5.7.17源码安装

    centos7 mysql5.7.17源码安装 **安装前准备 操作系统环境:Centos 7.2 1.解决依赖包并下载源码包至/home/soft/目录下[root@node03 ~]# yum - ...

  5. 最全解释:Linux操作系统下的软件安装与管理详解(源码安装、rpm/dpkg、yum/apt-get安装)

      在linux上安装软件,安装方式和软件包获取的途径都远远比windows的丰富,那当然这就变得复杂很多,本文旨在理解linux下繁杂的软件安装.管理原理 ,学习软件的安装方式.源码包格式.远程软件 ...

  6. ubuntu安装gcc-7,g++-7,源码安装python

    安装gcc-7/g++-7 添加镜像 vim /etc/apt/sources.list #在sources.list中添加如下内容 deb [arch=amd64] http://archive.u ...

  7. 离线安装wxpython_windows离线状态下源码安装Robotframework 环境及其依赖包

    最近公司需要在内网环境搭建自动化平台,无外网,因而无法使用方便快捷的PIP进行安装,但RF框架各组件有很多版本依赖,离线源码安装可能不知道有哪些依赖,特将自己采坑后的总结分享如下,以飨同道. 一.准备 ...

  8. mysql编译安装后目录空_MySQL源码安装完成后修改安装路径启动问题

    在Linux上源码编译安装完mysql后,又将安装的路径进行了修改,但是发现在设置后环境变量后启动报错,如下: [root@HServer_03 var]# mysqld_safe --user=my ...

  9. 源码安装mysql数据库_Linux下源码安装mysql数据库

    1.  创建mysql安装目录: [root@localhost ~]#mkdir –pv /usr/local/mysql/ 2.  创建数据存放目录: [root@localhost ~]#mkd ...

最新文章

  1. iOS 三种类型的Block
  2. 深入研究display:inline-block在浏览器中的应用
  3. solaris 命令
  4. 基于JAVA+SpringMVC+MYSQL的宿舍管理系统
  5. 缓存系列文章–无底洞问题
  6. js创建对象的多种方式及优缺点
  7. 进程被kill原因_Linux内核系列 简析进程生命周期:从生到死的这一生(一)
  8. 《卡巴斯基全系列》大客户key31个,有了它不用到处找卡巴斯基的KEY了!
  9. arXiv引用格式转换为已发表会议标准引用格式小工具分享
  10. 【金三银四】MySQL优化面试题(2021最新版)
  11. 【SVM分类】基于遗传算法优化支持向量机实现葡萄酒分类附matlab代码
  12. vue 全局背景音乐
  13. [WinError 2] 系统找不到指定的文件
  14. 富阳天空之城在哪里?
  15. H5学习之旅-H5的基本标签(2)
  16. 如何 增删改查 XML文件中的元素
  17. 两年工作经验程序员的迷茫
  18. 极验点选验证码位置识别(一):点选验证码位置识别技术总览
  19. 我的世界网易怎么调成java,网易版我的世界如何将单机地图改为联机地图
  20. c#量化交易_量化交易从入门到放弃(1)

热门文章

  1. 华为鸿蒙大屏电视,大屏手机还是智能电视?华为用鸿蒙系统增智慧
  2. php如何将日期换算成天数,使用php怎么计算给定日期的相差天数
  3. python自增_python的自增
  4. (C语言) AVL树 - 自平衡二叉树:插入、删除
  5. python异常-binascii.Error: Incorrect padding 报错解决
  6. 移动端获取当前屏幕的高度_手机移动端屏幕宽高详解
  7. 链表栈 一 二叉搜索树 一 深度优先之前序遍历
  8. x:null扩展 什么意思
  9. 盘点世界十大末日预言
  10. 计算机组成与设计(二)——指令:计算机指令 (一)