当前位置:   article > 正文

Orange Pi KunPeng Pro 从零到部署ROS2 humble+Cartographer_ros2 cartographer

ros2 cartographer

 非常高兴接到官方邀请,能够为orange pi kunpeng pro做一次简单的开箱测评, 这是一款极具性价比的开发板,下面是一些参数信息

功能详细信息
尺寸107x68 毫米
内存8/16GB LPDDR4X
闪存32MB SPI Flash
SSD 支持M.2 2280 NVMe/SATA
外接存储32/64/128/256GB eMMC
MicroSD 卡槽
接口2个HDMI (4K60), 40针GPIO (UART/I2C/SPI/I2S/PWM), 2个USB 3.0, USB-C 3.0, microUSB (调试), 2个MIPI摄像头接口, MIPI屏幕接口, 3.5毫米耳机接口, Type-C 20V/65W电源接口, 电池接口
网络千兆以太网, 双频 Wi-Fi 5, 蓝牙4.2

开箱俯视图:

 ​对应接口功能图:

 

 引脚图:

参考资料

官方资料参考

香橙派官方资料Orange Pi Kunpeng pro Orange Pi官网-香橙派(Orange Pi)开发板

 

因为截止24.5.28官方只提供了两个系统的镜像,一个是ubuntu22.04,还有一个是openEuler, 原卡自带openEuler, 那么这里我选择重新烧录ubuntu22.04的系统

1.ROS Humble安装

Part 1. 调整Ubuntu系统中的相关配置


step 1. 设置语言

终端输入指令:

sudo apt update
sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

step 2. 设置镜像源

用小鱼ros一键布置镜像源, 小鱼的一键布置ROS不太好用,这里选择手动布置ROS2

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


step 3. 从github下载相关文件

终端指令:

sudo apt update && sudo apt install curl gnupg lsb-release


sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

step 4. 将上述配置更新至系统

sudo apt-get update
sudo apt-get upgrade


Part 2. 安装ROS2-humble系统


step 1. 下载ROS系统

sudo apt install ros-humble-desktop


注1:humble表示版本名称,不同的Ubuntu系统需要下载对应的不同的版本名称,ubuntu22.04对应版本humble,其余版本可以登陆ROS官网自行查看;
注2:desktop表示桌面版本,即完整版本,自动安装我们常用的功能。

出现问题:

libicu-dev : Depends: libicu70 (= 70.1-2) but 70.1-2ubuntu1 is to be installed E: Unable to correct problems, you have held broken packages.

解决:sudo apt install libicu70=70.1-2

step 2. 调整配置

 source /opt/ros/humble/setup.bash echo " source /opt/ros/humble/setup.bash" >> ~/.bashrc


Part 3. 检测ROS2-humble系统是否可以正常运行


通信测试

打开一个终端,指令:ros2 run demo_nodes_cpp talker
另开一个终端,指令:ros2 run demo_nodes_py listener


如果listenner可以正常显示talker发出的信号,即表示正常。


小海龟仿真测试

一个终端,指令:ros2 run turtlesim turtlesim_node启动海龟仿真器
另一个终端,指令:ros2 run turtlesim turtle_teleop_key启动键盘控制节点

如果可以通过键盘正常操控小海龟移动,即表示正常。

终端输入rviz2看是否成功

2. Cartographer 安装

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

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

1.安装carto

  1. sudo apt install ros-humble-cartographer
  2. sudo apt install ros-humble-cartographer-ros

2.克隆

将下面的源码克隆到fishbot_ws的src目录下

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

3.安装依赖

这里我们使用rosdepc进行依赖的安装,rosdepc指令找不到可以先运行下面的一键安装命令,选择一键配置rosdep即可。

rosdepc install -r --from-paths src --ignore-src --rosdistro $ROS_DISTRO -y

colcon build --packages-up-to cartographer_ros

如果是源码编译请先source下工作空间后再使用下面指令查看是否安装成功;

ros2 pkg list | grep cartographer

能看到下面的结果即可

  1. cartographer_ros
  2. cartographer_ros_msgs

4.配置文件

4.1 pose_graph.lua-后端参数配置项

该文件主要和地图构建

--Fast csm的最低分数,高于此分数才进行优化。
constraint_builder.min_score = 0.65
--全局定位最小分数,低于此分数则认为目前全局定位不准确
constraint_builder.global_localization_min_score = 0.7

4.2 文件:backpack_2d.lua

该部分参数主要是用于和ROS2进行通信和数据收发的配置,比如配置从哪个话题读取里程记数据,从哪个话题来获取深度信息(雷达)。

  1. include "map_builder.lua"
  2. include "trajectory_builder.lua"
  3. options = {
  4. map_builder = MAP_BUILDER,
  5. trajectory_builder = TRAJECTORY_BUILDER,
  6. -- 用来发布子地图的ROS坐标系ID,位姿的父坐标系,通常是map。
  7. map_frame = "map",
  8. -- SLAM算法跟随的坐标系ID
  9. tracking_frame = "base_link",
  10. -- 将发布map到published_frame之间的tf
  11. published_frame = "base_link",
  12. -- 位于“published_frame ”和“map_frame”之间,用来发布本地SLAM结果(非闭环),通常是“odom”
  13. odom_frame = "odom",
  14. -- 是否提供里程计
  15. provide_odom_frame = true,
  16. -- 只发布二维位姿态(不包含俯仰角)
  17. publish_frame_projected_to_2d = false,
  18. -- 是否使用里程计数据
  19. use_odometry = false,
  20. -- 是否使用GPS定位
  21. use_nav_sat = false,
  22. -- 是否使用路标
  23. use_landmarks = false,
  24. -- 订阅的laser scan topics的个数
  25. num_laser_scans = 0,
  26. -- 订阅多回波技术laser scan topics的个数
  27. num_multi_echo_laser_scans = 1,
  28. -- 分割雷达数据的个数
  29. num_subdivisions_per_laser_scan = 10,
  30. -- 订阅的点云topics的个数
  31. num_point_clouds = 0,
  32. -- 使用tf2查找变换的超时秒数
  33. lookup_transform_timeout_sec = 0.2,
  34. -- 发布submap的周期间隔
  35. submap_publish_period_sec = 0.3,
  36. -- 发布姿态的周期间隔
  37. pose_publish_period_sec = 5e-3,
  38. -- 轨迹发布周期间隔
  39. trajectory_publish_period_sec = 30e-3,
  40. -- 测距仪的采样率
  41. rangefinder_sampling_ratio = 1.,
  42. --里程记数据采样率
  43. odometry_sampling_ratio = 1.,
  44. -- 固定的frame位姿采样率
  45. fixed_frame_pose_sampling_ratio = 1.,
  46. -- IMU数据采样率
  47. imu_sampling_ratio = 1.,
  48. -- 路标采样率
  49. landmarks_sampling_ratio = 1.,
  50. }

5.创建fishbot_cartographer

在src目录下,使用创建功能包指令,创建功能包

cd src
ros2 pkg create fishbot_cartographer

接着创建配置文件夹、launch文件夹和rviz配置文件夹。

cd fishbot_cartographer
mkdir config
mkdir launch
mkdir rviz

功能包结构:

.
├── CMakeLists.txt
├── config
├── launch
├── src
├── package.xml
└── rviz

相较于默认的配置文件,主要修改以下内容(见注释)

  1. include "map_builder.lua"
  2. include "trajectory_builder.lua"
  3. options = {
  4. map_builder = MAP_BUILDER,
  5. trajectory_builder = TRAJECTORY_BUILDER,
  6. map_frame = "map",
  7. tracking_frame = "base_link",
  8. -- base_link改为odom,发布map到odom之间的位姿态
  9. published_frame = "odom",
  10. odom_frame = "odom",
  11. -- true改为false,不用提供里程计数据
  12. provide_odom_frame = false,
  13. -- false改为true,仅发布2D位资
  14. publish_frame_projected_to_2d = true,
  15. -- false改为true,使用里程计数据
  16. use_odometry = true,
  17. use_nav_sat = false,
  18. use_landmarks = false,
  19. -- 0改为1,使用一个雷达
  20. num_laser_scans = 1,
  21. -- 1改为0,不使用多波雷达
  22. num_multi_echo_laser_scans = 0,
  23. -- 10改为11/1=1等于不分割
  24. num_subdivisions_per_laser_scan = 1,
  25. num_point_clouds = 0,
  26. lookup_transform_timeout_sec = 0.2,
  27. submap_publish_period_sec = 0.3,
  28. pose_publish_period_sec = 5e-3,
  29. trajectory_publish_period_sec = 30e-3,
  30. rangefinder_sampling_ratio = 1.,
  31. odometry_sampling_ratio = 1.,
  32. fixed_frame_pose_sampling_ratio = 1.,
  33. imu_sampling_ratio = 1.,
  34. landmarks_sampling_ratio = 1.,
  35. }
  36. -- false改为true,启动2D SLAM
  37. MAP_BUILDER.use_trajectory_builder_2d = true
  38. -- 0改成0.10,比机器人半径小的都忽略
  39. TRAJECTORY_BUILDER_2D.min_range = 0.10
  40. -- 30改成3.5,限制在雷达最大扫描范围内,越小一般越精确些
  41. TRAJECTORY_BUILDER_2D.max_range = 3.5
  42. -- 5改成3,传感器数据超出有效范围最大值
  43. TRAJECTORY_BUILDER_2D.missing_data_ray_length = 3.
  44. -- true改成false,不使用IMU数据,大家可以开启,然后对比下效果
  45. TRAJECTORY_BUILDER_2D.use_imu_data = false
  46. -- false改成true,使用实时回环检测来进行前端的扫描匹配
  47. TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
  48. -- 1.0改成0.1,提高对运动的敏感度
  49. TRAJECTORY_BUILDER_2D.motion_filter.max_angle_radians = math.rad(0.1)
  50. -- 0.55改成0.65,Fast csm的最低分数,高于此分数才进行优化。
  51. POSE_GRAPH.constraint_builder.min_score = 0.65
  52. --0.6改成0.7,全局定位最小分数,低于此分数则认为目前全局定位不准确
  53. POSE_GRAPH.constraint_builder.global_localization_min_score = 0.7
  54. -- 设置0可关闭全局SLAM
  55. -- POSE_GRAPH.optimize_every_n_nodes = 0
  56. return options

编写launch文件

/cartographer_node节点:

该节点从/scan和/odom话题接收数据进行计算,输出/submap_list数据.

该节点需要接收一个参数配置文件(第二部分写的那个)参数。

/occupancy_grid_node节点:

该节点接收/submap_list子图列表,然后将其拼接成map并发布

在路径src/fishbot_cartographer/launch/下新建cartographer.launch.py文件,接着我们将上面两个节点加入到这个launch文件中。

我们在第二部分写的配置文件就是给cartographer_node节点的,可以通过这个节点启动参数configuration_directory和configuration_basename进行传递。

  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

打开CmakeLists.txt,添加下面一条指令,将三个目录安装到install目录。

install(
  DIRECTORY config launch rviz
  DESTINATION share/${PROJECT_NAME}
)

6 开始建图

colcon build --packages-select fishbot_cartographer

启动建图前,需要先启动gazebo仿真环境,因为我们的建图程序依赖于Gazebo提供雷达和里程计等数据。

source install/setup.bash
ros2 launch fishbot_description gazebo.launch.py

source install/setup.bash
ros2 launch fishbot_cartographer cartographer.launch.py

打开遥控节点:

ros2 run teleop_twist_keyboard teleop_twist_keyboar

 保存地图

sudo apt install ros-humble-nav2-map-server

ros2 run nav2_map_server map_saver_cli --help

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

闽ICP备14008679号