ROS2-Beginner:9-启动节点

发布时间 2023-06-01 20:01:33作者: gary_123

目标:使用命令行工具来启动多个节点

背景

在大多数入门教程中,您一直在为运行的每个新节点打开新的终端。当您创建越来越多节点同时运行的更复杂的系统时,打开终端和重新输入配置细节会变得乏味。

launch文件允许您同时启动和配置包含ROS 2节点的许多可执行文件。

使用ros2-launch命令运行一个启动文件将同时启动整个系统——所有节点及其配置。

任务

运行launch文件

ros2 launch turtlesim multisim.launch.py
# turtlesim/launch/multisim.launch.py

from launch import LaunchDescription
import launch_ros.actions

def generate_launch_description():
    return LaunchDescription([
        launch_ros.actions.Node(
            namespace= "turtlesim1", package='turtlesim', executable='turtlesim_node', output='screen'),
        launch_ros.actions.Node(
            namespace= "turtlesim2", package='turtlesim', executable='turtlesim_node', output='screen'),
    ])

 

launch文件以python形式书写,也可以使用XML和YAML来创建launch。in Using Python, XML, and YAML for ROS 2 Launch Files.

更多的launch教程 ROS 2 launch tutorials.

控制Turtlesim 节点

ros2 topic pub  /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}}"
ros2 topic pub  /turtlesim2/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}}"

总结

到目前为止所做的工作的意义在于,您已经用一个命令运行了两个turtlesim节点。一旦你学会了编写自己的启动文件,你就可以用ros2启动命令以类似的方式运行多个节点并设置它们的配置。

 main launch file tutorial page.