在上次我们完成了一趟简单的package的Create,Build之后,我们要玩正儿八经的ROS,在此之前,我们有很多概念需要理解。按照如下列表进展。
This tutorial introduces ROS graph concepts and discusses the use ofroscore,rosnode, androsrun commandline tools.
This tutorial introduces ROS topics as well as using therostopic andrqt_plot commandline tools.
This tutorial introduces ROS services, and parameters as well as using therosservice androsparam commandline tools.
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-tutorialsReplace '<distro>' with the name of your ROS distribution (e.g. hydro, groovy, electric, fuerte etc.)
Using roscore
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: 3903Now, let's see some more nodes. For this, we're going to use rosrun to bring up another node.
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_nodeIn 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
/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
What was covered:
总结一下:
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