当前位置:网站首页>【ROS进阶篇】第三讲 ROS文件系统与分布式通信
【ROS进阶篇】第三讲 ROS文件系统与分布式通信
2022-06-29 20:58:00 【生如昭诩】
【ROS进阶篇】第三讲 ROS文件系统与分布式通信

前言
我们先前已经了解到,ROS系统是一个很典型的多进程分布式框架,对于一个完整的系统可以分为以下几个层次:
- 主机;
- 工作空间workspace;
- 功能包package;
- 节点node;
- 话题topic;
- 主机下的层次框架可以由下图展示:

本文主要研究的问题如下: - 元功能包的使用方法(关联功能包)
- ROS工作空间覆盖及隐患
- ROS分布式通信(不同主机间的通信)
一、元功能包
1. 概念

应用场景:在实际的ROS开发过程中,机器人往往需要设计多个功能,就需要调用不同的功能包,但是如果逐一安装则会导致效率低下,浪费时间,此时就需要功能包进行打包;
概念:元功能包(metapackage),ROS中的一个虚包,里面没有实质性的内容,但是依赖了其他的软件包,通过这种方法可以把其他包组合起来
实例:
sudo apt install ros-noetic-desktop-full
在进行ROS安装时,我们就运行了上述指令,类似于一个目录索引,告诉主机一个功能包集合,逐一下载安装;
2. 实现
- 新建功能包
- 修改package.xml:
<exec_depend>被集成的功能包</exec_depend>
.....
<export>
<metapackage />
</export>
- 修改编译规则CMakeLists.txt:
cmake_minimum_required(VERSION 3.0.2)
project(demo)
find_package(catkin REQUIRED)
catkin_metapackage()
参考地址:ROS Wiki Metapackage
二、工作空间覆盖
1. 问题分析
- 自行实现:
- 新建两个工作空间,在两个空间内创建同名功能包wssim
- 添加环境变量,修改 ~/.bashrc:
source /home/用户/路径/工作空间A/devel/setup.bash source /home/用户/路径/工作空间B/devel/setup.bash
- 加载环境变量:
source.bashrc- 查看环境变量:
echo $ROS_PACKAGE_PATH- 进入工作空间:
roscd wssim
- 此时会出现一个问题:即这里会直接进入工作空间B,实际的空间嵌套为:
工作空间B -> 工作空间A -> 系统内置空间
- 原因:配置顺序与优先级的关系
在实际的解析过程中,ROS首先会根据bashrc文件,按照其中配置设置工作空间优先级,生成对应功能包ROS_PACKAGE_PATH ROS路径,但是会遵循一个原则:
ROS_PACKAGE_PATH 中的值,和 .bashrc 的配置顺序相反 -> 先配置的优先级低
2. 结论与隐患
- 概念:不同工作空间中存在重名的功能包;
- 实质:功能包重名时,会按照 ROS_PACKAGE_PATH 查找,配置在前的会优先执行;
- 隐患:由于此时情况调用wssim会首先调用工作空间B中的功能包,可能并不满足我们对于实际操作的需求,会出现调用问题
BUG说明:
当在 .bashrc 文件中 source 多个工作空间后,可能出现的情况,在 ROS PACKAGE PATH 中只包含两个工作空间,可以删除自定义工作空间的 build 与 devel 目录,重新 catkin_make,然后重新载入 .bashrc 文件,问题解决。
三、分布式通信
1. 需求场景

在实际开发中,ROS系统常常用于完成多机之间的通讯与协同,会分布在不同的计算机上,在运行过程中经常与其他节点实现通信,存在着很多网络配置要求:
- 所有端口上的所有机器之间必须有完整的双向连接
- 每台计算机必须通过所有其他计算机都可以解析的名称来公告自己
2. 实现
- 基础准备:令不同主机处于同一网络,设置固定IP
虚拟机:将网络适配器修改为桥接模式
- 修改配置文件:主要指修改计算机的/etc/hosts的文件,在文件中加入对方的IP地址和计算机名
网络指令:
- IP地址查看:ifconfig
- 计算机名称:hostname
- 测试网络通信:ping
- 配置IP地址:
主机:修改~/.bashrc文件
export ROS_MASTER_URI=http://主机IP:11311
export ROS_HOSTNAME=主机IP
从机:修改~/.bashrc文件
export ROS_MASTER_URI=http://主机IP:11311
export ROS_HOSTNAME=从机IP
- 测试:
- 主机启动roscore
- 主机启动订阅节点,从机启动发布节点,测试通信
- 主机启动发布节点,从机启动订阅节点,反相测试
总结
- 声明:本节博客部分参考了CSDN用户赵虚左的ROS教程,下篇博客将会主要聚焦于节点名称、话题名称、参数名称的重名问题上,分别介绍各种重复导致的异常情况。

边栏推荐
- 如何在 SAP BTP ABAP 编程环境里直接调用 ABAP On-Premises 系统的 RFC 函数
- Implementation and Simulation of ads131a04 ADC Verilog
- 数字密码锁verilog设计+仿真+上板验证
- Clock tree synthesis (CTS)
- 空间导电盘式滑环材料的选择
- "Xiaodeng" active directory batch user creation in operation and maintenance
- Enter the year and month to find the total number of days in the month
- [today in history] June 29: SGI and MIPS merged; Microsoft acquires PowerPoint developer; News corporation sells MySpace
- Recruit | DBA Data Engineer every week with an annual salary of 35+. Dream of Kyushu and bright stars!
- Advances in computational imaging
猜你喜欢

How to judge the quality of conductive slip ring from its appearance

Win10 sets automatic dial-up networking task to realize automatic reconnection after startup and disconnection
![[a must for reptiles - > scrapy framework from black iron to king] first chapter - detailed explanation of 10000 character blog posts (recommended Collection)](/img/f3/a45fc96054e42725e491c3599c527f.jpg)
[a must for reptiles - > scrapy framework from black iron to king] first chapter - detailed explanation of 10000 character blog posts (recommended Collection)

Storage principle of string

A new Polaris has risen!

时钟树综合(CTS)

Selection of materials for space conductive disc slip ring

"Operation and maintenance department has Xiao Deng" to review and analyze file and folder access rights

THREEJS基础入门

「运维有小邓」实时监控用户登录操作
随机推荐
How to judge the quality of conductive slip ring from its appearance
leetcode:370. 区间加法
How can colleges and universities build future oriented smart campus based on cloud native? Full stack cloud native vs traditional technology architecture
The foundation and application of quantum machine learning: a concise literature review
Mapbox GL development tutorial (12): loading surface layer data
路由汇总带来的三层环路-解决实验
直播预告 | PostgreSQL 内核解读系列第一讲:PostgreSQL 系统概述
Golang basic learning
[fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design
AI scene Storage Optimization: yunzhisheng supercomputing platform storage practice based on juicefs
跳转打开新窗口
空间导电盘式滑环材料的选择
Lexin interview process
TMUX settings
leetcode:238. Product of arrays other than itself
Shutter bottomnavigationbar with page switching example
How to call RFC function of ABAP on premises system directly in SAP BTP ABAP programming environment
[a must for reptiles - > scrapy framework from black iron to king] first chapter - detailed explanation of 10000 character blog posts (recommended Collection)
Website stress testing tool - webbench
leetcode:307. 区域和检索 - 数组可修改