1.相关概念
Nodes:A node is an executable that uses ROS to communicate with other nodes.
Messages: ROS data type used when subscribing or publishing to a topic.
Topics: Nodes canpublishmessagesto a topic as well assubscribetoa topic to receive messages.
Master: Name service for ROS (i.e. helps nodes find each other)
rosout: ROS equivalent of stdout/stderr
roscore: Master + rosout + parameter server
2.Nodes
A node really isn't much more than an executable file within a ROS package. ROS nodes use a ROS client library to communicate with other nodes. Nodes can publish or subscribe to a Topic. Nodes can also provide or use a Service.
3.客户端库
根据编程语言不同有:
rospy = python client library
roscpp = c++ client library
4.roscore
当运行ROS时第一件事就是运行roscore命令。
5.使用rosnode
由于执行了roscore命令后Terminal界面就被占用了,此时需要再打开一个新Terminal再进行如下操作才能有相应结果(即操作依赖于roscore的运行):
rosnode list
此时会看到:
/rosout
当前只有rosout这个node在运行,运行roscore就一直存在,用于调试或打印输出信息。
rosnode info /rosout
该命令可以看到rosout这个node的更多信息。
6.使用rosrun
运行ROS自带的turtle例子:
rosrun turtlesim turtlesim_node
其中,turtlesim是包名,turtlesim_node是节点名。
命令运行后有如下输出:
[ INFO] [1495245056.523181709]: Startingturtlesim with node name /turtlesim
[ INFO] [1495245056.543466285]: Spawningturtle [turtle1] at x=[5.544445], y=[5.544445], theta=[0.000000]
对应的运行界面如下:
turtle
此时执行rosnode list命令,会有如下输出:
/rosout
/turtlesim
多了一个turtlesim结点,对于结点名,我们也可以指定,如下命令:
rosrun turtlesim turtlesim_node __name:=slam_turtle
即在使用rosrun时通过__name参数来设定,执行该命令后再执行rosnode
list,会有如下返回值:
/rosout
/slam_turtle
接下来使用rosnode ping slam_turtle命令可以测试该结点的运行状况,命令执行返回值:
rosnode: node is [/slam_turtle]
pinging /slam_turtle with a timeout of 3.0s
xmlrpc reply from http://slam:46576/ time=3.997087ms
xmlrpc reply from http://slam:46576/ time=1.501083ms
xmlrpc reply from http://slam:46576/ time=1.564980ms
xmlrpc reply from http://slam:46576/ time=1.533031ms
xmlrpc reply from http://slam:46576/ time=1.444101ms
^Cping average: 2.008057ms
7.回顾
roscore = ros+core : master (provides name service for ROS) + rosout (stdout/stderr) +parameter server
rosnode = ros+node : ROS tool toget information about a node.
rosrun = ros+run : runs a node from a given package.