当前位置:网站首页>[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 .

边栏推荐
猜你喜欢

「运维有小邓」Active Directory批量用户创建

Selection of materials for space conductive disc slip ring

如何从外表判断导电滑环的质量

leetcode:238. Product of arrays other than itself

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

导航 习题【微机原理】【习题】

Cantata version 9.5 has officially passed the sgs-t Ü V certification and conforms to all major software safety standards

Calibration, correction and world coordinate calculation of binocular stereo vision camera (openCV)

Detailed description of gaussdb (DWS) complex and diverse resource load management methods

知识蒸馏(Knowledge Distilling)学习笔记
随机推荐
How can colleges and universities build future oriented smart campus based on cloud native? Full stack cloud native vs traditional technology architecture
Design of VHDL telephone billing system
"Xiaodeng" active directory batch user creation in operation and maintenance
智能门锁主流品牌有哪些?选购门锁时要注重产品的哪些特性?
CORDIC based Signal Processor desgn
String类的常用方法
How to evaluate iFLYTEK AI translation pen P20 series? Is it worth buying?
Sentinel's quick start takes you through flow control in three minutes
Navigation experiment [microcomputer principle] [experiment]
leetcode:724. Find the central subscript of the array
Topic39——78. subset
导航【微机原理】
String字符串的存储原理
每周招聘|DBA数据工程师,年薪35+ ,梦起九州,星河灿烂!
Jump to open a new window
My creation anniversary
Uncover the secret! Pay attention to those machines under the membership system!
Logical structure and physical structure
Verilog realizes serial communication and sends it to the nixie tube
广东二级造价工程师《造价管理》真题解析