本文内容来源于:http://wiki.ros.org/ROS/Tutorials/UnderstandingNodes
- 图(Graph)概念概览
- ROS核心(roscore)
roscore是使用ros运行的一个命令,需要在其他节点运行之前运行roscore。
$ roscore ... logging to /home/shao/.ros/log/93b4e9f2-d146-11e9-a3fd-69f079ca327f/roslaunch-UAVlab1-13621.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://UAVlab1:40901/ ros_comm version 1.12.14 SUMMARY ======== PARAMETERS * /rosdistro: kinetic * /rosversion: 1.12.14 NODES auto-starting new master process[master]: started with pid [13631] ROS_MASTER_URI=http://UAVlab1:11311/ setting /run_id to 93b4e9f2-d146-11e9-a3fd-69f079ca327f process[rosout-1]: started with pid [13644] started core service [/rosout]
运行成功后如上所示。
- rosnode命令
使用rosnode命令可以查看ros节点相关的信息。例如:rosnode list命令可以列出运行的ros节点。
新打开一个终端,运行rosnode list,如下:
$ rosnode list /rosout
可以看出,有一个rosout节点,为roscore命令启动的。
使用rosnode info命令可以查看ros节点的信息:$ rosnode info /rosout -------------------------------------------------------------------------------- Node [/rosout] Publications: * /rosout_agg [rosgraph_msgs/Log] Subscriptions: * /rosout [unknown type] Services: * /rosout/get_loggers * /rosout/set_logger_level contacting node http://UAVlab1:42313/ ... Pid: 13644
-
rosrun运行节点
rosrun命令可以运行ros节点,语法如下:
$ rosrun [package_name] [node_name]
官网该文档有问题,正确的应该是:
rosrun <package> <executable>
即第二个参数为可执行程序名,不一定和节点名一致。
新打开一个终端,运行:$ rosrun turtlesim turtlesim_node
小龟龟出现喽。
然后再用rosnode可以看到:
$ rosnode list /rosout /turtlesim
可以看出来多了个turtlesim的节点。
打开新终端,然后使用参数重映射,可以给节点名重命名。$ rosrun turtlesim turtlesim_node __name:=my_turtle
然后运行rosnode list
$ rosnode list /my_turtle /rosout /turtlesim
可以看出来多了一个节点my_turtle。
使用rosnode ping命令可以检查和某节点之间的通信,类似于ping命令。$ rosnode ping /my_turtle rosnode: node is [/my_turtle] pinging /my_turtle with a timeout of 3.0s xmlrpc reply from http://UAVlab1:43947/ time=0.296116ms xmlrpc reply from http://UAVlab1:43947/ time=0.949144ms xmlrpc reply from http://UAVlab1:43947/ time=0.707150ms xmlrpc reply from http://UAVlab1:43947/ time=0.704050ms xmlrpc reply from http://UAVlab1:43947/ time=1.071930ms