Describe roschina/教程/UnderstandingNodes here.
Note: This tutorial assumes that you have completed the previous tutorials: building a ROS package. |
Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
Understanding ROS Nodes
Description: This tutorial introduces ROS graph concepts and discusses the use of roscore, rosnode, and rosrun commandline tools.Tutorial Level: BEGINNER
Next Tutorial: Understanding ROS topics
ROS节点关系图一些概念的简要说明
Nodes: 一个可执行的文件,使用ROS框架来与其它节点通讯.
Topics: 节点通过主题发布消息并通过订阅一个主题来接收消息.
Messages: 一种ROS数据类型,通过主题来订阅和发布.
Master: ROS的名字服务,功能包括帮助节点间互相查找到等。
rosout: ROS 中控制台输出作用类似 stdout/stderr
roscore: ROS内核,包括Master + rosout + parameter server (parameter server 后面介绍)
Nodes
一个节点不仅仅是ROS package中的一个可执行文件。 ROS nodes 使用 ROS client library 来与其它的node通讯。 Nodes 能发布和订阅一个Topic。 Nodes 也能提供或使用 Service。
Client Libraries
ROS client libraries 可以在不同的编程语言中使用:
- rospy = python client library
- roscpp = c++ client library
roscore
在ROS中,roscore 是第一个要运行的程序:
$ roscore
运行后会显示结果如下:
... logging to ~/.ros/log/9cf88ce4-b14d-11df-8a75-00251148e8cf/roslaunch-bvo-13039.log Checking log directory for disk usage. This may take awhile. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://bvo:33919/ ros_comm version 1.4.7 SUMMARY ======== PARAMETERS * /rosversion * /rosdistro NODES auto-starting new master process[master]: started with pid [13054] ROS_MASTER_URI=http://bvo:11311/ setting /run_id to 9cf88ce4-b14d-11df-8a75-00251148e8cf process[rosout-1]: started with pid [13067] started core service [/rosout]
如果 roscore 初始化失败,有可能是网络配置问题. 参考文章 Network Setup - Single Machine Configuration 打开一个新的终端,使用 rosnode 查看roscore 运行了哪些。
命令 rosnode
rosnode命令显示实现当前运行的ROS nodes 的相关信息.。命令 rosnode list列出当前运行的node:
$ rosnode list
显示结果是:
/rosout
结果显示只有一个node在运行: rosout. 这个节点通常都会运行,作用是收集其它节点运行的调试信息和日志信息。
命令 rosnode info 返回一个节点的详细信息。比如 $ rosnode info /rosout将会显示节点rosout的发布的主题/rosout_agg等更多内容:
$ rosnode info /rosout
返回结果:
-------------------------------------------------------------------------------- Node [/rosout] Publications: * /rosout_agg [rosgraph_msgs/Log] Subscriptions: * /rosout [unknown type] Services: * /rosout/set_logger_level * /rosout/get_loggers contacting node http://foo.local:54614/ ... Pid: 5092
命令Using rosrun
运行节点可以使用rosrun命令完成,该命令参数如下:
$ rosrun [package_name] [node_name]
现在我们运行turtlesim package中的节点程序turtlesim_node. 之前我们需要先编译下这个package:
$ rosmake turtlesim
然后打开一个新的终端窗口,输入并运行:
$ rosrun turtlesim turtlesim_node
得到结果:
注意: 实际运行时可能和本图片有些出入.
再打开一个新的终端:
$ rosnode list
得到结果:
/rosout /turtlesim
ROS一个强大的功能特点是可以通过命令行重新赋予节点程序名称.
切换到运行命令 rosrun turtlesim 的窗口,使用 ctrl-C 停止节点程序运行. 然后换个节点名 Remapping Argument重新启动运行:
$ rosrun turtlesim turtlesim_node __name:=my_turtle
我们在回到rosnode list命令窗口:
$ rosnode list
得到结果:
/rosout /my_turtle
现在看到了新的节点 /my_turtle . 使用命令rosnode , ping, 检测运行状态:
$ rosnode ping my_turtle
rosnode: node is [/my_turtle] pinging /my_turtle with a timeout of 3.0s xmlrpc reply from http://aqy:42235/ time=1.152992ms xmlrpc reply from http://aqy:42235/ time=1.120090ms xmlrpc reply from http://aqy:42235/ time=1.700878ms xmlrpc reply from http://aqy:42235/ time=1.127958ms
Review
What was covered:
- roscore = ros+core : master (provides name service for ROS) + rosout (stdout/stderr) + parameter server (parameter server will be introduced later)
- rosnode = ros+node : ROS tool to get information about a node.
- rosrun = ros+run : runs a node from a given package.
Now that you understand how ROS nodes work, let's look at how ROS topics work. Also, feel free to press Ctrl-C to stop turtlesim_node.