ROS学习手记 - 3 理解ROS中的基本概念_ROS_Nodes
在上次我们完成了一趟简单的package的Create,Build之后,我们要玩正儿八经的ROS,在此之前,我们有很多概念需要理解。按照如下列表进展。
- Understanding ROS Nodes This tutorial introduces ROS graph concepts and discusses the use ofroscore,rosnode, androsrun commandline tools.
- Understanding ROS Topics This tutorial introduces ROS topics as well as using therostopic andrqt_plot commandline tools.
- Understanding ROS Services and Parameters This tutorial introduces ROS services, and parameters as well as using therosservice androsparam commandline tools.
Understanding ROS Nodes
roscore,rosnode, androsrun commandline tools
This tutorial introduces ROS graph concepts and discusses the use of roscore, rosnode, androsrun commandline tools.
Prerequisites
For this tutorial we will use a lightweight simulator, please install it using
$ sudo apt-get install ros-<distro>-ros-tutorials
Replace ‘
roscore is the first thing you should run when using ROS.
Please run:
$ roscore
Using rosnode
Open up a new terminal, and let’s use rosnode to see what runningroscore did
exbot@ubuntu:~$ rosnode list
/rosout
This showed us that there is only one node running: rosout. This is always running as it collects and logs nodes’ debugging output.
The rosnode info command returns information about a specific node.
exbot@ubuntu:~$ 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://ubuntu:40455/ ...
Pid: 3903
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Now, let’s see some more nodes. For this, we’re going to use rosrun to bring up another node.
Using rosrun
rosrun allows you to use the package name to directly run a node within a package (without having to know the package path).
Usage:
$ rosrun [package_name] [node_name]
So now we can run the turtlesim_node in the turtlesim package.
Then, in a new terminal:
$ rosrun turtlesim turtlesim_node
In a new terminal:
$ rosnode list
You will see something similar to:
/rosout
/turtlesim
Close the turtlesim window to stop the node (or go back to therosrun turtlesim terminal and usectrl-C). Now let’s re-run it, but this time use a Remapping Argument to change the node’s name:
$ rosrun turtlesim turtlesim_node __name:=my_turtle
Now, if we go back and use rosnode list:
$ rosnode list
- You will see something similar to:
/rosout /my_turtle
We see our new /my\_turtle node. Let's use anotherrosnode command,ping, to test that it's up:
$ 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](http://wiki.ros.org/ROS/Tutorials/UnderstandingTopics). Also, feel free to press
Ctrl-C to stop turtlesim\_node.
总结一下:
0, 准备工作:装了个 ros-hydro-ros-tutotials
1, 运行 roscore 作为运行ROS基础,
它是一个后台的服务,提供rosout node, 类似stdout, stderr。
除此之外,roscore还提供了:master, rosout, parameter server
2, 运行一个新的ros node是新开一个Terminal,用rosrun命令
Usage:
$ rosrun [package\_name] [node\_name]
$ rosrun turtlesim turtlesim\_node
3, node运行时,还可以改一下node的名字
这个叫做remapping,用处是:让你通过命令行,在多个configuration下,运行同一个node. 不太懂,暂时放下。
4, node运行时,rosnode是get info about a node工具
查看node:运行rosnode list来查看运行的node
可以ping它:$rosnode ping nodename
查看rosnode info /rosnode\_name 的工具,用来查看rosnode 的info,如:
$ rosnode info /rosout