ROS2 学习笔记3:了解ROS2 节点 Node
Background 背景
1 ROS 2 图
在接下来的几个教程中,将学习一系列核心ROS 2概念,这些概念构成了所谓的 ROS(2) Graph
。
ROS图是ROS 2元素同时处理数据的网络。它包含所有可执行文件以及它们之间的连接 (如果要将它们全部映射并可视化)。
思考及疑问: ROS2 Graph, ROS2 Node topology, how to display in graph
2 ROS 2中的节点
ROS中的每个节点应负责单个模块目的 (例如,一个用于控制车轮电机的节点,一个用于控制激光测距仪的节点等)。每个节点可以通过话题、服务、动作或参数向其他节点发送和接收数据。
一个完整的机器人系统由许多协同工作的节点组成。在ROS 2中,单个可执行文件 (c++程序、Python程序等) 可以包含一个或多个节点。
Prerequisites 前提
安装turtlesim
在新终端中 source
ROS 2
Tasks 任务
1 ROS2 运行
指令ros2 run
从包中启动一个可执行文件
ros2 run <package_name> <executable_name>
运行turtlesim,打开一个新终端,然后输入以下命令
ros2 run turtlesim turtlesim_node
turtlesim仿真窗口启动,如前面课程所示
这里,包的名字是turtlesim
,可执行文件名字是turtlesim_node
我们还不知节点的名字,然而,你可以使用指令ros2 node list
来找节点名字
2 ROS2 节点列表
ros2 node list
显示所有正在运行的节点的名称。
当turtlesim仍在另一个终端中运行时,打开一个新终端,然后输入以下命令:
ros2 node list
终端将返回节点名称:
/turtlesim
打开另一个新终端,并使用以下命令启动teleop节点:
ros2 run turtlesim turtle_teleop_key
这里,包仍是 turtlesim
包,可执行文件为 turtle_teleop_key
回到 ros2 node list
的终端,再次运行。现在,将看到两个活动节点的名称:
/turtlesim
/teleop_turtle
2.1 重映射
Remapping https://design.ros2.org/articles/ros_command_line_arguments.html#name-remapping-rules
允许您将默认节点属性 (如节点名称、话题名称、服务名称等) 重新分配给自定义值。在上一个教程中,使用 turtle_teleop_key
上的重映射来更改被控制的默认海龟。
现在,让我们重新分配 /turtlesim
节点的名称。在新终端中,运行以下命令:
ros2 run turtlesim turtlesim_node --ros-args --remap __node:=my_turtle
**思考及疑问: 该命令各参数详解 重映射规则, – remap aaa:= bbb **
由于您再次在turtlesim上调用ros2 run
,另一个turtlesim
窗口将打开。但是,现在如果您返回到运行 ros2 node list
的终端,并再次运行它,您将看到三个节点名称:
/turtlesim
/teleop_turtle
/my_turtle
3 ROS2 节点信息
现在你知道节点名字了,也可以通过下面指令来了解节点更多信息:
ros2 node info <node_name>
要检查您的最新节点 my_turtle
,请运行以下命令:
ros2 node info /my_turtle
ros2 node info
与该节点交互的订阅者、发布者、服务和动作 (ROS图连接) 的列表。输出应如下所示:
**思考及疑问: how to display the topology in Graph **
/my_turtle
Subscribers:
/parameter_events: rcl_interfaces/msg/ParameterEvent
/turtle1/cmd_vel: geometry_msgs/msg/Twist
Publishers:
/parameter_events: rcl_interfaces/msg/ParameterEvent
/rosout: rcl_interfaces/msg/Log
/turtle1/color_sensor: turtlesim/msg/Color
/turtle1/pose: turtlesim/msg/Pose
Service Servers:
/clear: std_srvs/srv/Empty
/kill: turtlesim/srv/Kill
/my_turtle/describe_parameters: rcl_interfaces/srv/DescribeParameters
/my_turtle/get_parameter_types: rcl_interfaces/srv/GetParameterTypes
/my_turtle/get_parameters: rcl_interfaces/srv/GetParameters
/my_turtle/list_parameters: rcl_interfaces/srv/ListParameters
/my_turtle/set_parameters: rcl_interfaces/srv/SetParameters
/my_turtle/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically
/reset: std_srvs/srv/Empty
/spawn: turtlesim/srv/Spawn
/turtle1/set_pen: turtlesim/srv/SetPen
/turtle1/teleport_absolute: turtlesim/srv/TeleportAbsolute
/turtle1/teleport_relative: turtlesim/srv/TeleportRelative
Service Clients:
Action Servers:
/turtle1/rotate_absolute: turtlesim/action/RotateAbsolute
Action Clients:
现在尝试在 /teleop_turtle
节点上运行相同的命令,看看它的连接与 my_turtle 有什么不同
在接下来的教程中了解更多关于ROS图连接概念的信息,包括消息类型。
Summary 总结
节点是ROS2 基本元素,在机器人系统里面负责单一模块功能作用
在本课程,通过运行中执行文件turtlesim_node
和turtle_teleop_key
,启动turtlesim
包中的节点
你学会了使用ros2 node list
来获取活动节点的名字,使用ros2 node info
指令去深入了解某个节点.对于一个复杂真实的机器人系统,这些工具用在了解数据流显得至关重要
Next steps 下一步
了解ROS2 节点后,可以开始学习话题课程,话题是一种节点交流的方式
Related
Node Concepet
A node is a participant in the ROS 2 graph, which uses a client library to communicate with other nodes. Nodes can communicate with other nodes within the same process, in a different process, or on a different machine. Nodes are typically the unit of computation in a ROS graph; each node should do one logical thing.
Nodes can publish to named topics to deliver data to other nodes, or subscribe to named topics to get data from other nodes. They can also act as a service client to have another node perform a computation on their behalf, or as a service server to provide functionality to other nodes. For long-running computations, a node can act as an action client to have another node perform it on their behalf, or as an action server to provide functionality to other nodes. Nodes can provide configurable parameters to change behavior during run-time.
Nodes are often a complex combination of publishers, subscribers, service servers, service clients, action servers, and action clients, all at the same time.
Connections between nodes are established through a distributed discovery process.