本文记录了>
/>
/>
/>
</
node>
includeinclude 可以在一个 launch file 中包含另外的 launch file groupgroup 可以把多个 node 组合在一起 疑问4:如何编写一个 launch file?无论是 python、xml 还是 yaml,编写 launch file 的步骤差不多一样。 设置命令行参数的默认值,设置 launch file 的包含关系,通过 标签设置 Node 信息,包括 name、namespace、parameter如果需要设置 remmaping 则设置 remapping 关系官方文档有出示个一个例子# 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",)
)
background_g_launch_arg = DeclareLaunchArgument(
"background_g",)
)
background_b_launch_arg = DeclareLaunchArgument(
"background_b",)
)
chatter_ns_launch_arg = DeclareLaunchArgument(
"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":/>
/>
/>
/>
/>
/>
/>
/>
>
/>
/>
/>
>
/>
/>
</
node>
</
launch>
yaml 要写也很容易。 # 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"
疑问5:如何在/>
把 from 中的 topic,转换成 to 指定的 topic 有 2 种用途:把一个 node 原本来发布的 topic,映射为另外一个名字把其他的 node 发布的原始 topic,映射为所需要的 topicROS2 官方教程的示例中有如下代码Node(
package='turtlesim',
executable='mimic',
name='mimic',
remappings=[
('/input/pose', '/turtlesim1/turtle1/pose'),
('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
]
)
实践官方教程有很详细的指引,这里简单概述一下。1.创建 launch 文件turtlesim_mimic_launch.pyfrom launch import LaunchDescription
from 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'),
]
)
])
2.启动ros2 launch turtlesim_mimic_launch.py
你会看到两个乌龟界面。
3. 调试发送命令让乌龟动起来. 新开一个终端,敲下面的命令。ros2 topic pub -r 1 /turtlesim1/turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: -1.8}}"
我们仔细观察看到,发送的是 /turtlesim1/turtle1/cmd_vel 这个 Topic,但 2 只乌龟都运动起来,这是因为我们在 mimic 这个节点中做了remap 动作,相当于进行了消息的透传。 我们可以通过 rqt_graph 查看更详细的信息。 新开一个终端然后输入 rqt_graph。
它们之间的关系还是一目了然的。参考1.ROS2官方文档 2.ROS1官方文档
在麻将等娱乐活动中,往往有一些朋友过于注重麻将技术的高低和游戏胜负结果,自己如果技高一筹,赢了对手,往往兴高采烈,自鸣得意,而一旦发现技术高超的对手则愤愤不平真人棋牌游戏,输了之后久久不能平静,平明搜集挖掘各类所谓的高深的麻将技术,力图提高自己麻将技术水平,甚至希望自己永远不输,能够一直赢下去。按照佛家来说,这是入了执念,太过执着于输赢成败,而忘记了输赢成败,奈争由人算,忘记了麻将游戏这项活动本身原始的意义。