(转) ROS NAMING AND NAMESPACES

时间:2022-08-28 17:28:24

原文地址: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]

(转) ROS NAMING AND NAMESPACES

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

(转) ROS NAMING AND NAMESPACES

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

(转) ROS NAMING AND NAMESPACES

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.

(转) ROS NAMING AND NAMESPACES

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 NAMING AND NAMESPACES的更多相关文章

  1. ROS教程

    Learning ROS 学习ROS Depending on your learning style and preferences, you can take two approaches to ...

  2. ROS 5&period;x自动定时备份并发送到邮箱(实用)

    博主使用ROS已经有很长一段时间了,但经常会忘记备份配置与数据库,加上ROS本身自带的User-Man数据库并不是非常稳定,1年中总会出现1-2次数据丢失的情况.所以费了一定功夫才找到真正可用自动备份 ...

  3. ros下多机器人系统&lpar;1&rpar;

    multi-robot system 经过两个多月的ros学习,对ros的认识有了比较深入的了解,本篇博客主要记录在ros下开发多机器人系统以及对ros更深入的开发.本篇博客是假定读者已经学习完了全部 ...

  4. Naming Conventions for &period;NET &sol; C&num; Projects

    http://www.akadia.com/services/naming_conventions.html Naming Conventions for .NET / C# Projects Mar ...

  5. &lbrack;转&rsqb;JavaScript Namespaces and Modules

    Namespaces In most programming languages we know the concept of namespaces (or packages).Namespaces ...

  6. Gazebo機器人仿真學習探索筆記(七)连接ROS

    中文稍后补充,先上官方原版教程.ROS Kinetic 搭配 Gazebo 7 附件----官方教程 Tutorial: ROS integration overview As of Gazebo 1 ...

  7. ROS launch总结

    1 运行Launch文件2 新建Launch文件3  在namespace中启动nodes 4   remapping names 5 其他的launch元素 1 运行Launch文件 Launch文 ...

  8. ROS C&plus;&plus; 规范概要

    一.动机 代码一致才能可读.联调.高效率.高复用.可移植性. 二.命名方式 CamelCased camelCased under_scored ALL_CAPITALS 2.1 Package命名方 ...

  9. ROS launch 总结

    ROS launch 总结 转自博客:https://www.cnblogs.com/Jessica-jie/p/6961837.html 1 运行Launch文件2 新建Launch文件3  在na ...

随机推荐

  1. lua

    lua的语言特性: 1. lua 的table可以实现多种数据结构:数组.记录.线性表.队列.集合等: 2. lua的closure闭合函数 3. lua的迭代器和泛型的for 4. lua的协同程序 ...

  2. EF7 - What Does &OpenCurlyDoubleQuote;Code First Only” Really Mean

    这篇文章很有价值,但翻译了一段,实在翻译不下去了,没办法,只能转载了. 英文地址:http://blogs.msdn.com/b/adonet/archive/2014/10/21/ef7-what- ...

  3. C&num;使用委托进行异步编程。

    首先引用MSDN中的一段话来描述一下如何使用异步方式.NET Framework 允许您异步调用任何方法. 为此,应定义与您要调用的方法具有相同签名的委托:公共语言运行时会自动使用适当的签名为该委托定 ...

  4. shell命令从目录中循环匹配关键词

    #!/bin/bash while read line do for file in /home/local/test/* do if test -f $file then sed -n " ...

  5. PL&sol;SQL基础-异常处理

    --*********异常处理一.异常的类型 ORACLE异常分为两种类型:系统异常.自定义异常. 其中系统异常又分为:预定义异常和非预定义异常.1.预定义异常 ORACLE定义了他们的错误编号和异常 ...

  6. Nofollow

    今天整理一下SEO中经常用到的nofollow属性. nofollow它是HTML标签中的一个属性值,作用是告诉搜索引擎不要跟踪带有改属性值的链接, 用于指示搜索引擎不要追踪(即抓取)网页上的带有no ...

  7. DB天气app冲刺二阶段第八天

    今天突然感觉应该做收尾工作了 因为马上就要考试了,时间一下子就不够用了.. 今天主要修复了一下bug,然后天气基本能够实时准确了,就是多功能按钮还是没有弄好 准备简化一下功能. 明天看看还有什么需要改 ...

  8. UVA 11090 Going in Cycle&excl;&excl;

    要求给定的图的中平均权值最小的环,注意处理自环的情况就能过了. 按照w1+w2+w3+….wn < n*ave的不等式,也就是(w1-ave) + (w2-ave) +…..(wn-ave) & ...

  9. 添加解压缩版Tomcat到系统服务

    一.安装服务 在命令行中进入/Tomcat路径/bin/,执行“service.bat install”: 说明:1.服务名和显示名称:service.bat中设置了默认的服务名称,不同版本分别命名为 ...

  10. Memcached基础

    1.实例化 MemcachedClient client = new XMemcachedClient(); public XMemcachedClient() public XMemcachedCl ...