当前位置:网站首页>[advanced ROS chapter] Lecture 4: duplicate names in ROS (nodes, topics and parameters)
[advanced ROS chapter] Lecture 4: duplicate names in ROS (nodes, topics and parameters)
2022-06-29 21:00:00 【Life is like Zhaoxu】
【ROS Advanced 】 Lesson four ROS The problem of double names in English ( node 、 Topics and parameters )

List of articles
Preface
In the last blog post , We have to ROS The file management system is analyzed in hierarchy , The workspace coverage and the communication between different hosts are studied , This section focuses on changing the direction , To consider ROS There are many duplicate names in the system , for example Duplicate node name 、 Topic name 、 Parameter duplicate name etc. .
One 、 Duplicate node name
1. Introduction to the problem
- Concept : stay ROS Node is the most basic concept in the system , When creating a node , For example, using C++ Language , You need to specify API Define the node name , If there is a node with the same name , Then there will be problems when calling ;
- Physical truth : stay ROS When the node with the same name is started , The existing nodes will be closed directly , The tips are as follows :
[ WARN] [1578812836.351049332]: Shutdown request received.
[ WARN] [1578812836.351207362]: Reason given for shutdown: [new node registered with same name]
- Solutions :
- using namespace std : add prefix
- Name remapping : Rename
For the above two strategies , There are three ways to achieve this :rosrun command 、launch Documentation and programming , This article will analyze and introduce one by one
2. resolvent
1)rosrun
- Set namespace :
rosrun Function package name The node name __ns:=/ New node roll call
Examples are as follows :
rosrun turtlesim turtlesim_node __ns:=/xxx
rosrun turtlesim turtlesim_node __ns:=/yyy
- Name remapping :
rosrun Function package name The node name __name:= New node roll call
Examples are as follows :
rosrun turtlesim turtlesim_node __name:=t1 | rosrun turtlesim turtlesim_node /turtlesim:=t1
rosrun turtlesim turtlesim_node __name:=t2 | rosrun turtlesim turtlesim_node /turtlesim:=t2
2)launch
- In the previous launch File parsing tutorial , We mentioned that node Two attributes of a tag ,name and ns, By setting these two properties, you can easily implement the above two strategies ;
<launch>
<node pkg="turtlesim" type="turtlesim_node" name="t1" />
<node pkg="turtlesim" type="turtlesim_node" name="t1" ns="xxx"/>
</launch>
3)c++
- Set namespace :
std::map<std::string, std::string> map;
map["__ns"] = "xxxx";
ros::init(map,"test_node");
- Name remapping : After giving the original node name Add time stamp
ros::init(argc,argv,"test_node",ros::init_options::AnonymousName);
Two 、 Topic name
1. Introduction to the problem
- Compared to nodes ,ROS Of course, there is also the problem of duplicate names , But it will be more complicated , Because in practical application , The setting of topic name is relatively flexible , It needs to be modified flexibly .
- Solutions : The same as the node name , The basic strategy is still Remapping and prefixes The two methods , The difference is that there are many kinds of prefixes , It can be divided into the following three categories :
- Global prefix : Reference resources ROS System , Level with namespace
- Relative prefix : Reference namespace , Level with node name
- Private prefix : Reference node name , Under the node name
- Case study : In the test of the solution , Suppose the scenario is as follows :
Use the keyboard to control the function pack , Used to control turtle movement , The instructions are as follows :
sudo apt install ros-noetic-teleop-twist-keyboard
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
rosrun turtlesim turtlesim_node
- problem : The former ( The control node ) The topic is
cmd_vel, the latter ( According to the node ) yes/turtle1/cmd_vel
2. resolvent
1)rosrun
- The name remapping method is mainly used , Modify the topic name conveniently through the following instructions
rosrun Function package name The node name Topic name := New words title
Examples are as follows :
rosrun teleop_twist_keyboard teleop_twist_keyboard.py /cmd_vel:=/turtle1/cmd_vel
rosrun turtlesim turtlesim_node
// Or vice versa
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
rosrun turtlesim turtlesim_node /turtle1/cmd_vel:=/cmd_vel
2)launch
- Again , adopt launch In file node Medium remap Topic remapping can be realized
<launch>
<node pkg="turtlesim" type="turtlesim_node" name="t1" />
<node pkg="teleop_twist_keyboard" type="teleop_twist_keyboard.py" name="key">
<remap from="/cmd_vel" to="/turtle1/cmd_vel" />
</node>
<-- notes : The opposite solution -->
<node pkg="turtlesim" type="turtlesim_node" name="t1">
<remap from="/turtle1/cmd_vel" to="/cmd_vel" />
</node>
<node pkg="teleop_twist_keyboard" type="teleop_twist_keyboard.py" name="key" />
</launch>
3)c++
- about C++ Solutions for , Mainly adopts add prefix The way to , And different names , Prefixes added are different :
- Premise : Set the node name to tsnode, Add the space prefix when starting the node :xxx
- Global name :
// With / The name at the beginning , Independent of node name ros::Publisher pub = nh.advertise<std_msgs::String>("/chatter",1000); // result :/chatter
- Relative name :
// Not / The name at the beginning , Refer to the workspace to determine the topic name ros::Publisher pub = nh.advertise<std_msgs::String>("chatter",1000); // result :xxx/chatter
- Private name :
// With ~ The name at the beginning , Add workspace and node name prefix ros::NodeHandle nh("~"); ros::Publisher pub = nh.advertise<std_msgs::String>("chatter",1000); // result :/xxx/tsnode/chatter
3、 ... and 、 Parameter duplicate name
1. Introduction to the problem
- Concept : Different from before , Parameter names can also be overwritten by duplicate names , But most of the solutions are add prefix The way to ;
- terms of settlement : When generating parameters , In essence, it will have a certain prefix , Prefix types are three of the same topic , This article will introduce ;
2. resolvent
1)rosrun
- use rosrun Start node , Can be set by the following command :
rosrun Function package name The node name _ Parameter name := Parameter values
- example : Automatic addition Node prefix ( Private model ):
rosrun turtlesim turtlesim_node _A:=100
// View the corresponding parameter information
/turtlesim/A
2)launch
- The two methods :
- node Set parameters outside the label : Global properties
<launch>
<param name="p1" value="100" />
<-- result :/p1 -->
</launch>
- node Set parameters in the label : Private nature
<launch>
<node pkg="turtlesim" type="turtlesim_node" name="t1">
<param name="p2" value="100" />
</node>
<-- result :/t1/p2 -->
</launch>
3)c++
about C++ Programmatically , adopt API:param::set perhaps NodeHandle Realization :
paramset:
ros::param::set("/set_A",100); // overall situation , It has nothing to do with namespace and node name
ros::param::set("set_B",100); // relative , Reference namespace
ros::param::set("~set_C",100); // private , Reference namespace and node name
// result
/set_A
/xxx/set_B
/xxx/yyy/set_C
- NodeHandle:
ros::NodeHandle nh;
nh.setParam("/nh_A",100); // overall situation , It has nothing to do with namespace and node name
nh.setParam("nh_B",100); // relative , Reference namespace
ros::NodeHandle nh_private("~");
nh_private.setParam("nh_C",100);// private , Reference namespace and node name
// result
/nh_A
/xxx/nh_B
/xxx/yyy/nh_C
summary
- Statement : The blog section of this section refers to CSDN User zhaoxuzuo ROS course , From the next blog ROS The advanced tutorial will step into the study of functional components , We start with TF Change the toolkit and start again .

边栏推荐
- String类的常用方法
- 期末复习【微机原理】
- CAD assistant - 3D model format conversion tool
- 空间导电盘式滑环材料的选择
- 【ROS进阶篇】第三讲 ROS文件系统与分布式通信
- Implementation and Simulation of ads131a04 ADC Verilog
- Flutter BottomNavigationBar带有页面切换示例
- Navigation experiment [microcomputer principle] [experiment]
- flutter BottomNavigationBar切换页面保持状态
- A keepalived high availability accident made me learn it again!
猜你喜欢

Analysis of the factors affecting the transmission signal of the conductive slip ring

Design of VHDL telephone billing system

Practical guide to GStreamer application development (V)
![Navigation [microcomputer principle]](/img/79/8311a409113331e72f650a83351b46.png)
Navigation [microcomputer principle]

不同系统下的文件层级符号小结

WIN10设置自动拨号联网任务,实现开机、断网自动重连

【ROS进阶篇】第三讲 ROS文件系统与分布式通信

STM32最小系统搭建(原理图)

The reason why the log analysis tool of "operation and maintenance" is used more and more frequently

CAD assistant - 3D model format conversion tool
随机推荐
导航 实验【微机原理】【实验】
「运维有小邓」日志分析工具使用越来越频繁的原因
推荐书籍--白夜行
Leading by 11%, Huawei cloud sky chip AI solver once again topped the international authoritative list
At least 3 years for learning amplifier?
GoAhead WebServer移植
Shutter bottomnavigationbar toggle page hold
High energy live broadcast, a gathering of celebrities! We invite you to explore bizdevops.
阿里云发布《中国机器人产业图谱(2022)》,122页pdf
【ROS进阶篇】第二讲 自定义头、源文件封装
量子机器学习的基础和应用:一个简明文献综述
HAproxy + Keepalive实现LDAP代理服务
PostgreSQL Weekly News - 22 juin
习近平在湖北武汉考察时强调 把科技的命脉牢牢掌握在自己手中 不断提升我国发展独立性自主性安全性
The reason why the log analysis tool of "operation and maintenance" is used more and more frequently
每周招聘|DBA数据工程师,年薪35+ ,梦起九州,星河灿烂!
How to call RFC function of ABAP on premises system directly in SAP BTP ABAP programming environment
Deploy web using gunicorn Py application
Recommended books -- walking in the daytime and at night
Initialization of global and static variables