(转) ROS NAMING AND NAMESPACES
原文地址:http://nootrix.com/2013/08/ros-namespaces/
In this tutorial, we will be talking about ROS namespaces which allow to combine nodes in ways unplanned by developers. This is actually what all ROS is about: allow building systems by connecting nodes, often developed by third parties according to your needs. This is possible thanks to a flexible node naming system. As usual, we will illustrate presented concepts with concrete examples that you can run on your own machine. As a prerequisite, you only need to be familiar with thebasic concepts of ROS introduced in a previous post.
View Running Nodes Using rqt_graph
Every ROS application is a graph of nodes typically connected through some topics. We illustrate this idea by the example of turtle simulator. First start the ROS infrastructure is running by evaluating in a terminal the command:
roscore
Now, start the turtle simulator node by evaluating in a new terminal:
rosrun turtlesim turtlesim_node
As a result, a simulator window opens. It looks like the one shown by Figure 1, except may be the turtle colors and shape that are different on each launch. On the terminal you’ll see two information lines similar to the ones blow. The[INFO] tag is followed by a time stamp ([<seconds since epoch>.<nano_seconds>]), and then a log about the node name (/turtlesim) and the turtle initial position.
[INFO] [1374406333.186210549]: Starting turtlesim with node name /turtlesim
[INFO] [1374406333.192485241]: Spawning turtle [turtle1] at x=[5.544445], y=[5.544445], theta=[0.000000]

Figure 1: The TurtleSim Simulator Window
To make the turtle move, launch a driver node by evaluating in another terminal:
rosrun turtlesim draw_square
You can display running ROS nodes using the rqt_graph utility under ROS Groovy (Use rxgraph under ROS Fuerte), by evaluating in a terminal the command line:
rqt_graph
Figure 2: rqt_graph Shows Nodes and Their Connections Through Topics
As a result, you’ll get the window shown by Figure 2. Ellipses represent nodes while arrows represent connexions through topics. We can see that the /turtlesim node (that is visualized by the graphical turtle in Figure 1) is the publisher of the /turtle1/pose topic that provides the current pose of the turtle . The unique subscriber of this topic is the /draw_square node. The second arrow corresponds to the /turtle1/command_velocity topic. It is used by the/draw_square node to send velocity commands to /turtlesim.
One Driver for Two simulated Turtles
Suppose now that we want to have two turtle simulations running side by side, both driven by the same driver (e.g.draw_square). The naive approach consisting in running yet another turtlesim_node does not work. Instead, the first turtle simulation terminates with a warning log ([WARN] tag) as below. It states that the new simulation node replaces the first one.
[WARN] [1374671981.742213033]: Shutdown request received.
[WARN] [1374671981.742445480]: Reason given for shutdown: [new node registered with same name]
To avoid name conflicts, you need to provide a different node name for the second turtle simulator. The rosruncommand does allow to assign a different name to the node by evaluating the following command line. The value assigned to the __name parameter (here turtlesim2) is the replacement for the default node name.
rosrun turtlesim turtlesim_node __name:=turtlesim2

Figure 3: Nodes of two turtle simulators sharing a single driver
Figure 3 shows the graph displayed by rqt_graph once you hit the update button. The arrows refer to connections between nodes. To actually see the topics, select the “Nodes/Topics (active)” item in the drop down list of rqt_graph. The result is shown on Figure 4. Topics are represented as rectangles nested into the turtle1 box. If you hover the mouse over a topic, it gets color highlight, as well as connected nodes.
Figure 4: Displaying Topics in rqt_graph
Namespaces
Now it’s time to introduce the concept of namespace. A namespace can be viewed as a directory which contents are items of different names. These items can be nodes, topics, or even other namespaces. Indeed, namespaces can be organized in hierarchies of arbitrary depth.
In the examples above, you already have been dealing with two namespaces. There is the root namespace, referred by a forward slash “/“. The root namespace of Figure 4 includes four items. Three of them are nodes (draw_square,turtlesim, and turtlesim2) while the fourth is the turtle1 namespace. The turtle1 namespace includes two items which are both topics: command_velocity and pose.
To talk to each other, nodes need to refer to same topics. In the previous examples, we used the default topic names. This was ok for our toy scenario. But, sometimes you need to make nodes use topics with different names. A typical example is a system where different sub-systems are similar.
Two Turtle Simulators Driven by Different Drivers
We illustrate the concept of namespace with two turtle simulators driven by two instances of the draw_square driver. Each simulator and is driven by a dedicated driver. Thus, we need to ensure that nodes have different names. We also need to ensure that within each simulation, nodes talk using different topics.
The renaming facility provided by rosrun does allow to avoid collisions. However, it result into multiple long command lines. A better solution is use roslaunch. It requires writing a XML file that contains all information about nodes to launch and their namespaces. The XML listing below allows running side by side two turtle simulation nodes driven by two different draw_square nodes.
<launch>
<group ns="sim1">
<node name="turtle" pkg="turtlesim" type="turtlesim_node"/>
<node name="controller" pkg="turtlesim" type="draw_square"/>
</group>
<group ns="sim2">
<node name="turtle" pkg="turtlesim" type="turtlesim_node"/>
<node name="controller" pkg="turtlesim" type="draw_square"/>
</group>
</launch>
The XML format for roslaunch provides tags for defining nodes. By changing the name argument we can have different instances of the same node type of a given package running side by side. In our example, we kept the names identical. But, we wrapped nodes inside group tags. Each group is mapped to a different namespace by setting the ns argument.
Time to launch all nodes by evaluating the following single command line. We assume that thetwoTurtleSimulations.launch file with the XML code above is in the folder where the command line is evaluated.
roslaunch twoTurtleSimulations.launch
Note that roslaunch takes care of everything. No need to run roscore! Still, if you have already lauched roscore, it will work just fine. Anyway, rqt_graph will display the set of nodes and connexions as shown by Figure 5.
(转) ROS NAMING AND NAMESPACES的更多相关文章
- ROS教程
Learning ROS 学习ROS Depending on your learning style and preferences, you can take two approaches to ...
- ROS 5.x自动定时备份并发送到邮箱(实用)
博主使用ROS已经有很长一段时间了,但经常会忘记备份配置与数据库,加上ROS本身自带的User-Man数据库并不是非常稳定,1年中总会出现1-2次数据丢失的情况.所以费了一定功夫才找到真正可用自动备份 ...
- ros下多机器人系统(1)
multi-robot system 经过两个多月的ros学习,对ros的认识有了比较深入的了解,本篇博客主要记录在ros下开发多机器人系统以及对ros更深入的开发.本篇博客是假定读者已经学习完了全部 ...
- Naming Conventions for .NET / C# Projects
http://www.akadia.com/services/naming_conventions.html Naming Conventions for .NET / C# Projects Mar ...
- [转]JavaScript Namespaces and Modules
Namespaces In most programming languages we know the concept of namespaces (or packages).Namespaces ...
- Gazebo機器人仿真學習探索筆記(七)连接ROS
中文稍后补充,先上官方原版教程.ROS Kinetic 搭配 Gazebo 7 附件----官方教程 Tutorial: ROS integration overview As of Gazebo 1 ...
- ROS launch总结
1 运行Launch文件2 新建Launch文件3 在namespace中启动nodes 4 remapping names 5 其他的launch元素 1 运行Launch文件 Launch文 ...
- ROS C++ 规范概要
一.动机 代码一致才能可读.联调.高效率.高复用.可移植性. 二.命名方式 CamelCased camelCased under_scored ALL_CAPITALS 2.1 Package命名方 ...
- ROS launch 总结
ROS launch 总结 转自博客:https://www.cnblogs.com/Jessica-jie/p/6961837.html 1 运行Launch文件2 新建Launch文件3 在na ...
随机推荐
- Java中的Clone机制(浅层复制)
浅层复制代码: import java.util.*; class Int{ private int i; public Int(int ii){i = ii;} public void increm ...
- Django的model中日期字段设置默认值的问题
之前写过这样一个model: class MonthlyFeeMember(models.Model): worker = models.ForeignKey(Student, verbose_nam ...
- SVN - 详细文档
1.首先打开Cornerstone 2.然后如下图所示: 3.选择对应的仓库,如下图所示 4.然后Import完成之后,就把本地的文件提交到SVN服务器上了,如下图所示,另外如果你想要使用SVN进行版 ...
- [OpenJudge] 百练2754 八皇后
八皇后 Description 会下国际象棋的人都很清楚:皇后可以在横.竖.斜线上不限步数地吃掉其他棋子.如何将8个皇后放在棋盘上(有8 * 8个方格),使它们谁也不能被吃掉!这就是著名的八皇后问题. ...
- 转载收藏之用 - 微信公众平台开发教程(七):解决用户上下文(Session)问题
从这篇文章中我们已经了解了微信公众平台消息传递的方式,这种方式有一个先天的缺陷:不同用户的请求都来自同一个微信服务器,这使得常规的Session无法使用(始终面对同一个请求对象,况且还有对方服务器Co ...
- content的定义
http://www.myexception.cn/HTML-CSS/1472528.html http://stackoverflow.com/questions/2770681/css-conte ...
- jQuery对象与DOM对象的互相转换
jQuery对象转换成DOM对象jQuery提供了两种方法将一个jQuery对象转换成DOM对象,即[index]和get(index).1.jQuery对象是一个数组对象,可以通过[index]的方 ...
- 蓝牙芯片NRF51822入门学习1:时间管理
前言 之前辞职找工作的时候发现,很多公司希望招聘蓝牙技术方面的人才,所以干脆丢开LWIP静下心来学习蓝牙技术.原本以为一两星期能基本学会的,谁知道所选的蓝牙芯片nrf51822是个坑货,坑了我一个月. ...
- CentOS6.4/6.7下Mysql数据库的安装与配置(转载)
通过RPM方式 给centos 安装mysql 最好有光盘,呵呵,网络也可以下载rpm安装包,不过文件较大. 1 挂载光盘 mount /dev/cdrom /mnt/cdrom/mount: b ...
- 关于BitmapFactory.decodeStream(is)方法无法正常解码为Bitmap对象的解决方法
在android sdk 1.6版本API帮助文档中,其中关于BitmapFactory.decodeFactory.decodeStream(InputStream is)的帮助文档是这么说明的: ...