ROS是多进程(节点)的分布式框架,一个完整的ROS系统实现:
可能包含多台主机;
每台主机上又有多个工作空间(workspace);
每个的工作空间中又包含多个功能包(package);
每个功能包又包含多个节点(Node),不同的节点都有自己的节点名称;
每个节点可能还会设置一个或多个话题(topic)…

在多级层深的ROS系统中,其实现与维护可能会出现一些问题,比如:
本章主要内容介绍在ROS中上述问题的解决策略(见本章目录),预期达成学习目标也与上述问题对应:
场景:完成ROS中一个系统性的功能,可能涉及到多个功能包,比如实现了机器人导航模块,该模块下有地图、定位、路径规划…等不同的子级功能包。那么调用者安装该模块时,需要逐一的安装每一个功能包吗?
MetaPackage是Linux的一个文件管理系统的概念。是ROS中的一个虚包,里面没有实质性的内容,但是它依赖了其他的软件包,通过这种方法可以把其他包组合起来,我们可以认为它是一本书的目录索引,告诉我们这个包集合中有哪些子包,并且该去哪里下载。
例如:
还有一些常见的MetaPackage:navigation moveit! turtlebot3 …
方便用户的安装,我们只需要这一个包就可以把其他相关的软件包组织到一起安装了。
# 添加
<exec_depend>plumbing_pub_subexec_depend>
<exec_depend>plumbing_server_clientexec_depend>
<exec_depend>plumbing_param_serverexec_depend>
<export>
<metapackage /> # 空实现
export>
# 除了留下以下的句子,其余都要删除掉
cmake_minimum_required(VERSION 3.0.2)
project(plumbing_my) # 括号内是包名
find_package(catkin REQUIRED)
catkin_metapackage()
关于 launch 文件的使用我们已经不陌生了,在第一章内容中,就曾经介绍到:
一个程序中可能需要启动多个节点,比如:ROS 内置的小乌龟案例,如果要控制乌龟运动,要启动多个窗口,分别启动 roscore、乌龟界面节点、键盘控制节点。如果每次都调用 rosrun 逐一启动,显然效率低下,如何优化?
采用的优化策略便是使用roslaunch 命令集合 launch 文件启动管理节点,并且在后续教程中,也多次使用到了 launch 文件。
<!-- 启动乌龟GUI与键盘控制节点-->
<launch>
<!-- pkg——包,type——被执行的节点,name——节点取的名字,output = "screen"——日志输出到屏幕上-->
<!-- rosrun turtlesim(pkg)功能包 turtlrsim_node(type)-->
<!-- 启动的节点 -->
<node pkg = "turtlesim" type = "turtlesim_node" name = "turtle1" output = "screen"/>
<!-- 键盘控制 -->
<node pkg = "turtlesim" type = "turtle_teleop_key" name = "key" output = "screen" />
</launch>
source ./devel/setup.bash
roslaunch launch01_basic start_turtle.launch
<launch deprecated = "此文件已经过时,不建议使用">
<!-- 启动的节点 -->
<node pkg = "turtlesim" type = "turtlesim_node" name = "turtle1" output = "screen"/>
<!-- 键盘控制 -->
<node pkg = "turtlesim" type = "turtle_teleop_key" name = "key" output = "screen" />
</launch>
<!-- 需要复用 start_turtle1.launch -->
<launch>
<!-- 包含 -->
<include file = "$(find launch01_basic)/launch/start_turtle1.launch"/>
<!-- 其他节点 -->
</launch>
cd demo01_ws
source ./devel/setup.bash
roslaunch launch01_basic start_turtle_use.launch

启动launch 文件
cd demo01_ws
source ./devel/setup.bash
roslaunch launch01_basic start_turtle.launch
rosparam list
bg_R: 100
bg_G: 50
bg_B: 255
<launch>
<!-- 导出参数 -->
<rosparam command = "dump" file = "$(find launch01_basic)/launch/params_out.yaml" />
<!-- 删除参数 -->
<rosparam command = "delete" param = "bg_B"
</launch>
bg_B: 255
bg_G: 50
bg_R: 100
my_turtle:
background_b: 255
background_g: 86
background_r: 69
bg_B: 255
bg_G: 50
bg_R: 100
param_B: 3.14
param_A: 100
rosdistro: 'noetic'
roslaunch:
uris:
host_rosnoetic_virtualbox__35627: http://rosnoetic-VirtualBox:35627/
host_rosnoetic_virtualbox__35683: http://rosnoetic-VirtualBox:35683/
host_rosnoetic_virtualbox__37517: http://rosnoetic-VirtualBox:37517/
host_rosnoetic_virtualbox__37845: http://rosnoetic-VirtualBox:37845/
host_rosnoetic_virtualbox__38195: http://rosnoetic-VirtualBox:38195/
host_rosnoetic_virtualbox__39683: http://rosnoetic-VirtualBox:39683/
host_rosnoetic_virtualbox__40149: http://rosnoetic-VirtualBox:40149/
host_rosnoetic_virtualbox__40193: http://rosnoetic-VirtualBox:40193/
host_rosnoetic_virtualbox__44143: http://rosnoetic-VirtualBox:44143/
rosversion: '1.15.14'
run_id: 28c1ae38-04af-11ed-af3e-cfe9aa3ab2b3
<launch>
<!-- 启动两对乌龟GUI 与 键盘控制节点 能避免重名问题-->
<group ns = "first">
<node pkg = "turtlesim" type = "turtlesim_node" name = "my_turtle" output = "screen" />
<node pkg = "turtlesim" type = "turtle_teleop_key" name = "my_key" output = "screen" />
</group>
<group ns = "second">
<node pkg = "turtlesim" type = "turtlesim_node" name = "my_turtle" output = "screen" />
<node pkg = "turtlesim" type = "turtle_teleop_key" name = "my_key" output = "screen" />
</group>
</launch>
<launch>
<!-- 需求: 演示 arg 的使用,需要设置多个参数,这些参数使用的时同一个值(小车的长度),如何设置? -->
<!-- <param name = "A" value = "0.5" />
<param name = "B" value = "0.5" />
<param name = "C" value = "0.5" /> -->
<arg name = "car_length" default = "0.55" />
<param name = "A" value = "$(arg car_length)" />
<param name = "B" value = "$(arg car_length)" />
<param name = "C" value = "$(arg car_length)" />
</launch>
<!-- <deprecated = "此文件已经过时,不建议使用"> -->
<launch>
<!-- 添加被执行的节点 node是运动节点,key是键盘控制节点-->
<!-- pkg——功能包,type——被执行的节点,name——节点取的名字,output = "screen"——日志输出到屏幕上-->
<!-- 乌龟GUI-->
<!-- rosrun turtlesim(pkg) turtlrsim_node(type)-->
<!-- 启动的节点-->
<!-- respawn = "true" 关闭节点后,节点自动重启-->
<!-- required = "true" 节点退出后,关闭整个系统-->
<!-- ns = "hello" 设置节点的命名空间-->
<!-- param 使用: 向参数服务器设置参数 -->
<!-- param 格式1:launch 下,node 外 -->
<param name = "param_A" type = "int" value = "100" />
<!-- rosparam 使用: 操作参数服务器数据 -->
<!-- roparam 格式1:launch 下,node 外 -->
<!-- 加载参数 -->
<rosparam command = "load" file = "$(find launch01_basic)/launch/params.yaml" />
<!-- 导出参数 -->
<rosparam command = "dump" file = "$(find launch01_basic)/launch/params_out.yaml" />
<node pkg = "turtlesim" type = "turtlesim_node" name = "my_turtle" output = "screen">
<remap from = "/turtle1/cmd_vel" to = "/cmd_vel" />
<!-- param 格式2:node 下 -->
<param name = "param_B" type = "double" value = "3.14" />
<!-- roparam 格式2: node 下 -->
<rosparam command = "load" file = "$(find launch01_basic)/launch/params.yaml" />
</node>
<!-- 键盘控制的节点-->
<node pkg = "turtlesim" type = "turtle_teleop_key" name = "my_key" output = "screen" />
<!-- 添加hello_c文件-->
<!-- node pkg = "hello_vscode" type = "hello_vscode_c" name = "hello" output = "screen"/ -->
</launch>
所谓工作空间覆盖,是指不同工作空间中,存在重名的功能包的情形。
ROS 开发中,会自定义工作空间且自定义工作空间可以同时存在多个,可能会出现一种情况:虽然特定工作空间内的功能包不能重名,但是自定义工作空间的功能包与内置的功能包可以重名或者不同的自定义的工作空间中也可以出现重名的功能包,那么调用该名称功能包时,会调用哪一个呢?比如:自定义工作空间A存在功能包 turtlesim,自定义工作空间B也存在功能包 turtlesim,当然系统内置空间也存在turtlesim,如果调用turtlesim包,会调用哪个工作空间中的呢?