当前位置:网站首页>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)
边栏推荐
- How to build an enterprise level OLAP data engine for massive data and high real-time requirements?
- Communication protocol and message format between microservices
- PathMatchingResourcePatternResolver解析配置文件 资源文件
- What are the differences between vite and wenpack?
- [cloud native] talk about the understanding of the old message middleware ActiveMQ
- Seat / safety configuration upgrade is the administrative experience of the new Volvo S90 in place
- 2.9.4 Boolean object type processing and convenient methods of ext JS
- Use of rule engine drools
- Sentinel fusing and current limiting
- Which websites can I visit to check the latest medical literature?
猜你喜欢

2021 CIKM |GF-VAE: A Flow-based Variational Autoencoder for Molecule Generation

Leetcode:1184. Distance between bus stops -- simple

支持代理直连Oracle数据库,JumpServer堡垒机v2.24.0发布

Can literature | relationship research draw causal conclusions

生活相关——十年的职业历程(转)

redux

HelloWorld case analysis

吴恩达机器学习课后习题——线性回归

Advanced content of MySQL -- three MySQL logs that must be understood binlog, redo log and undo log

(translation) timing of website flow chart and user flow chart
随机推荐
Implementation of distributed lock
Dynamic planning for stair climbing
华为高层谈 35 岁危机,程序员如何破年龄之忧?
Life related - less expectation, happier
生活相关——一个华科研究生导师的肺腑之言(主要适用于理工科)
Communication protocol and message format between microservices
LeetCode:1184. 公交站间的距离————简单
如何构建面向海量数据、高实时要求的企业级OLAP数据引擎?
Method of test case design: introduction, trial recruit, preliminary exploration of equivalence boundary
Day24 job
【第019问 Unity中对SpherecastCommand的理解?】
Laravel8 implements interface authentication encapsulation using JWT
[Reading Notes - > data analysis] Introduction to BDA textbook data analysis
Design and implementation of smart campus applet based on cloud development
Working ideas of stability and high availability guarantee
The PHP Eval () function can run a string as PHP code
VM虚拟机 没有未桥接的主机网络适配器 无法还原默认配置
红星美凯龙高负债之下,盯上新能源了?
吴恩达机器学习课后习题——线性回归
Matrix and Gauss elimination [matrix multiplication, Gauss elimination, solving linear equations, solving determinants] the most detailed in the whole network, with examples and sister chapters of 130