当前位置:   article > 正文

ROS2 humble安装Cartographer以及使用_ros2 cartographer 安装

ros2 cartographer 安装

1,Cartographer的介绍

Cartographer是Google开源的一个可跨多个平台和传感器配置以2D和3D形式提供实时同时定位和建图(SLAM)的系统。

github地址:https://github.com/cartographer-project/cartographer

文档地址:https://google-cartographer.readthedocs.io/en/latest

2,Cartographer的安装

安装Cartographer与Cartographer_ros

sudo apt install ros-humble-cartographer
sudo apt install ros-humble-cartographer-ros

源码安装

  1. git clone https://ghproxy.com/https://github.com/ros2/cartographer.git -b ros2
  2. git clone https://ghproxy.com/https://github.com/ros2/cartographer_ros.git -b ros2

https://ghproxy.com如果你有代理,这部分你可以不需要

安装依赖

这里我们使用鱼香ros的一键安装

wget http://fishros.com/install -O fishros && . fishros

然后在你的工作空间xxx_ws下运行

rosdepc install -r --from-paths src --ignore-src --rosdistro humble -y

编译

colcon build --packages-up-to cartographer_ros

测试是否安装成功

ros2 pkg list | grep cartographer

看到下面结果即可

  1. cartographer_ros
  2. cartographer_ros_msgs

这里特别提供launch文件

  1. import os
  2. from launch import LaunchDescription
  3. from launch.substitutions import LaunchConfiguration
  4. from launch_ros.actions import Node
  5. from launch_ros.substitutions import FindPackageShare
  6. def generate_launch_description():
  7. # 定位到功能包的地址
  8. pkg_share = FindPackageShare(package='fishbot_cartographer').find('fishbot_cartographer')
  9. #=====================运行节点需要的配置=======================================================================
  10. # 是否使用仿真时间,我们用gazebo,这里设置成true
  11. use_sim_time = LaunchConfiguration('use_sim_time', default='true')
  12. # 地图的分辨率
  13. resolution = LaunchConfiguration('resolution', default='0.05')
  14. # 地图的发布周期
  15. publish_period_sec = LaunchConfiguration('publish_period_sec', default='1.0')
  16. # 配置文件夹路径
  17. configuration_directory = LaunchConfiguration('configuration_directory',default= os.path.join(pkg_share, 'config') )
  18. # 配置文件
  19. configuration_basename = LaunchConfiguration('configuration_basename', default='fishbot_2d.lua')
  20. rviz_config_dir = os.path.join(pkg_share, 'config')+"/cartographer.rviz"
  21. print(f"rviz config in {rviz_config_dir}")
  22. #=====================声明三个节点,cartographer/occupancy_grid_node/rviz_node=================================
  23. cartographer_node = Node(
  24. package='cartographer_ros',
  25. executable='cartographer_node',
  26. name='cartographer_node',
  27. output='screen',
  28. parameters=[{'use_sim_time': use_sim_time}],
  29. arguments=['-configuration_directory', configuration_directory,
  30. '-configuration_basename', configuration_basename])
  31. cartographer_occupancy_grid_node = Node(
  32. package='cartographer_ros',
  33. executable='cartographer_occupancy_grid_node',
  34. name='cartographer_occupancy_grid_node',
  35. output='screen',
  36. parameters=[{'use_sim_time': use_sim_time}],
  37. arguments=['-resolution', resolution, '-publish_period_sec', publish_period_sec])
  38. rviz_node = Node(
  39. package='rviz2',
  40. executable='rviz2',
  41. name='rviz2',
  42. arguments=['-d', rviz_config_dir],
  43. parameters=[{'use_sim_time': use_sim_time}],
  44. output='screen')
  45. #===============================================定义启动文件========================================================
  46. ld = LaunchDescription()
  47. ld.add_action(cartographer_node)
  48. ld.add_action(cartographer_occupancy_grid_node)
  49. ld.add_action(rviz_node)
  50. return ld

如果你遇到编译问题,请检查launch文件,我被困扰了很久。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/876908
推荐阅读
相关标签
  

闽ICP备14008679号