当前位置:网站首页>How is the launch of ros2 different?
How is the launch of ros2 different?
2022-07-26 04:15:00 【Mr anhydrous】
One 、 summary
stay launch Multi node execution ,ROS2 And ROS1 There's a big difference . First ,ros2 And ros1 The difference , lie in ROS2 No more *.launch Script files , In its place 3 Three formats are implemented :
- python Script
- xml file
- yaml file
Two 、 start-up launch file
2.1 launch Use of
adopt launch file ,ROS2 Many nodes can be started at the same time , This simplifies using the command line to start different programs multiple times Node.
2.2 launch Start command
1)xml file yaml file
ros2 launch <package_name> <launch_file_name>2) about py file , It can also be started directly launch file , like this :
ros2 launch turtlesim_mimic_launch.py
3、 ... and 、launch The content of the document
3.1 launch File content description
because launch file After all, files are multi node execution scripts , therefore , And “ ros2 run ” The contents of the instructions are roughly the same , Such as package name 、 The node name . Of course , To enrich some . Such as :
<node pkg="turtlesim" exec="turtlesim_node" name="sim" namespace="turtlesim2">
<param name="background_r" value="$(var background_r)"/>
<param name="background_g" value="$(var background_g)"/>
<param name="background_b" value="$(var background_b)"/>
</node>3.2 About include
include Can be in a launch file Contains additional launch file
3.3 About group
group You can put more than one node Put together
Four 、 Practice writing a launch file
4.1 Necessary routine
Whether it's python、xml still yaml, To write launch file The steps are almost the same .
- Set the default value of command line parameters ,
- Set up launch file The inclusive relationship of , adopt label
- Set up Node Information , Include name、namespace、parameter
- If you need to set remmaping Is set remapping Relationship
4.2 for instance
Here's the official document An example , It's for turtles turtlesim Example :
from launch import LaunchDescriptionfrom launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
Node(
package='turtlesim',
namespace='turtlesim1',
executable='turtlesim_node',
name='sim'
),
Node(
package='turtlesim',
namespace='turtlesim2',
executable='turtlesim_node',
name='sim'
),
Node(
package='turtlesim',
executable='mimic',
name='mimic',
remappings=[
('/input/pose', '/turtlesim1/turtle1/pose'),
('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
])
])The above code is very clear , Is to start two turtle nodes , One mimic node ; Some of the above concepts that need to be explained are : What is the function of namespaces ? What's the point of remapping ?( After execution , Analyze with command line )
4.3 remap What's the effect
remap Is a very useful technique , It's usually used to make Topic Mapping . A node doesn't know this Topic, But by renaming , Or pseudonym , Or re disguise ( Be careful , Subscribers here only accept certain names Topic), Make some receive this Topic.
<remap from="/different_topic" to="/needed_topic"/>hold from Medium topic, convert to to designated topic
Yes 2 Uses :
- Put one node Originally released topic, Map to another name
- Put the others node Published original topic, Map to the desired topic
4.4 Execute with parameters launch
We noticed the above launch file There is args, such as background_r, When the command line is started, the data can be transmitted through , adopt key:=value form . Such as :
ros2 launch <package_name> <launch_file_name> background_r:=2555、 ... and 、 Reference resources : Three ways of writing
The following code is for reference , Are three file implementation methods of the same content , Because it's longer , I hope you can read it slowly .
5.1 be based on python The case of
# example.launch.py
import os
from ament_index_python import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.actions import IncludeLaunchDescription
from launch.actions import GroupAction
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch.substitutions import TextSubstitution
from launch_ros.actions import Node
from launch_ros.actions import PushRosNamespace
def generate_launch_description():
# args that can be set from the command line or a default will be used
background_r_launch_arg = DeclareLaunchArgument(
"background_r", default_value=TextSubstitution(text="0")
)
background_g_launch_arg = DeclareLaunchArgument(
"background_g", default_value=TextSubstitution(text="255")
)
background_b_launch_arg = DeclareLaunchArgument(
"background_b", default_value=TextSubstitution(text="0")
)
chatter_ns_launch_arg = DeclareLaunchArgument(
"chatter_ns", default_value=TextSubstitution(text="my/chatter/ns")
)
# include another launch file
launch_include = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(
get_package_share_directory('demo_nodes_cpp'),
'launch/topics/talker_listener.launch.py'))
)
# include another launch file in the chatter_ns namespace
launch_include_with_namespace = GroupAction(
actions=[
# push-ros-namespace to set namespace of included nodes
PushRosNamespace(LaunchConfiguration('chatter_ns')),
IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(
get_package_share_directory('demo_nodes_cpp'),
'launch/topics/talker_listener.launch.py'))
),
]
)
# start a turtlesim_node in the turtlesim1 namespace
turtlesim_node = Node(
package='turtlesim',
namespace='turtlesim1',
executable='turtlesim_node',
name='sim'
)
# start another turtlesim_node in the turtlesim2 namespace
# and use args to set parameters
turtlesim_node_with_parameters = Node(
package='turtlesim',
namespace='turtlesim2',
executable='turtlesim_node',
name='sim',
parameters=[{
"background_r": LaunchConfiguration('background_r'),
"background_g": LaunchConfiguration('background_g'),
"background_b": LaunchConfiguration('background_b'),
}]
)
# perform remap so both turtles listen to the same command topic
forward_turtlesim_commands_to_second_turtlesim_node = Node(
package='turtlesim',
executable='mimic',
name='mimic',
remappings=[
('/input/pose', '/turtlesim1/turtle1/pose'),
('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
]
)
return LaunchDescription([
background_r_launch_arg,
background_g_launch_arg,
background_b_launch_arg,
chatter_ns_launch_arg,
launch_include,
launch_include_with_namespace,
turtlesim_node,
turtlesim_node_with_parameters,
forward_turtlesim_commands_to_second_turtlesim_node,
])This is the use of python Written , The last thing to come back is LaunchDescription Information , This is equivalent to xml in Content in Tags
5.2 be based on xml Writing
<!-- example.launch.xml -->
<launch>
<!-- args that can be set from the command line or a default will be used -->
<arg name="background_r" default="0"/>
<arg name="background_g" default="255"/>
<arg name="background_b" default="0"/>
<arg name="chatter_ns" default="my/chatter/ns"/>
<!-- include another launch file -->
<include file="$(find-pkg-share demo_nodes_cpp)/launch/topics/talker_listener.launch.py"/>
<!-- include another launch file in the chatter_ns namespace-->
<group>
<!-- push-ros-namespace to set namespace of included nodes -->
<push-ros-namespace namespace="$(var chatter_ns)"/>
<include file="$(find-pkg-share demo_nodes_cpp)/launch/topics/talker_listener.launch.py"/>
</group>
<!-- start a turtlesim_node in the turtlesim1 namespace -->
<node pkg="turtlesim" exec="turtlesim_node" name="sim" namespace="turtlesim1"/>
<!-- start another turtlesim_node in the turtlesim2 namespace
and use args to set parameters -->
<node pkg="turtlesim" exec="turtlesim_node" name="sim" namespace="turtlesim2">
<param name="background_r" value="$(var background_r)"/>
<param name="background_g" value="$(var background_g)"/>
<param name="background_b" value="$(var background_b)"/>
</node>
<!-- perform remap so both turtles listen to the same command topic -->
<node pkg="turtlesim" exec="mimic" name="mimic">
<remap from="/input/pose" to="/turtlesim1/turtle1/pose"/>
<remap from="/output/cmd_vel" to="/turtlesim2/turtle1/cmd_vel"/>
</node>
</launch>5.3 be based on yaml The file of
# example.launch.yaml
launch:
# args that can be set from the command line or a default will be used
- arg:
name: "background_r"
default: "0"
- arg:
name: "background_g"
default: "255"
- arg:
name: "background_b"
default: "0"
- arg:
name: "chatter_ns"
default: "my/chatter/ns"
# include another launch file
- include:
file: "$(find-pkg-share demo_nodes_cpp)/launch/topics/talker_listener.launch.py"
# include another launch file in the chatter_ns namespace
- group:
- push-ros-namespace:
namespace: "$(var chatter_ns)"
- include:
file: "$(find-pkg-share demo_nodes_cpp)/launch/topics/talker_listener.launch.py"
# start a turtlesim_node in the turtlesim1 namespace
- node:
pkg: "turtlesim"
exec: "turtlesim_node"
name: "sim"
namespace: "turtlesim1"
# start another turtlesim_node in the turtlesim2 namespace and use args to set parameters
- node:
pkg: "turtlesim"
exec: "turtlesim_node"
name: "sim"
namespace: "turtlesim2"
param:
-
name: "background_r"
value: "$(var background_r)"
-
name: "background_g"
value: "$(var background_g)"
-
name: "background_b"
value: "$(var background_b)"
# perform remap so both turtles listen to the same command topic
- node:
pkg: "turtlesim"
exec: "mimic"
name: "mimic"
remap:
-
from: "/input/pose"
to: "/turtlesim1/turtle1/pose"
-
from: "/output/cmd_vel"
to: "/turtlesim2/turtle1/cmd_vel"Reference article :
ROS2 Medium launch File entry 6 A question - You know (zhihu.com)
边栏推荐
- 2.9.4 Boolean object type processing and convenient methods of ext JS
- HelloWorld case analysis
- 构建关系抽取的动词源
- [深入研究4G/5G/6G专题-42]: URLLC-13-《3GPP URLLC相关协议、规范、技术原理深度解读》-7-低延时技术-1-子载波间隔扩展
- PHP method to find the location of session storage file
- dijikstra(先预处理)+dfs,relocation truncated to fit
- Soft simulation rasterization renderer
- 1. Mx6u-alpha development board (main frequency and clock configuration experiment)
- 1. Mx6u-alpha development board (GPIO interrupt experiment)
- Inventory the concept, classification and characteristics of cloud computing
猜你喜欢

Segger embedded studio cannot find xxx.c or xxx.h file

How to download the supplementary literature?

LeetCode:1184. 公交站间的距离————简单

【SVN】一直出现 Please execute the ‘Cleanup‘ command,cleanup以后没有反应的解决办法

Pathmatchingresourcepatternresolver parsing configuration file resource file

Apple removed the last Intel chip from its products

Acwing brush questions

荐书 |《学者的术与道》:写论文是门手艺

Acwing_12. 背包问题求具体方案_dp
![Acwing game 61 [End]](/img/e3/191f7d888fc8cced608d41ef837a92.png)
Acwing game 61 [End]
随机推荐
1. Mx6u-alpha development board (main frequency and clock configuration experiment)
座椅/安全配置升级 新款沃尔沃S90行政体验到位了吗
Recommendation | scholar's art and Tao: writing papers is a skill
p-范数(2-范数 即 欧几里得范数)
Apple removed the last Intel chip from its products
Wechat applet realizes music player (5)
Leetcode:1184. Distance between bus stops -- simple
[question 019: what is the understanding of spherecastcommand in unity?]
Graph translation model
Under the high debt of Red Star Macalline, is it eyeing new energy?
Life related - less expectation, happier
Synchronous FIFO based on shift register
JS get some attributes of the object
How to build an enterprise level OLAP data engine for massive data and high real-time requirements?
firewall 命令简单操作
(翻译)网站流程图和用户流程图的使用时机
The PHP Eval () function can run a string as PHP code
MATLAB绘图
构建关系抽取的动词源
Constructing verb sources for relation extraction