当前位置:网站首页>ROS node name duplicate
ROS node name duplicate
2022-07-27 06:19:00 【Three assassins】
scene :ROS The node created in has a name ,C++ Initialize the node by API:
ros::init(argc,argv,"xxxx");To define the node name , stay Python The initialization node in is throughrospy.init_node("yyyy")To define the node name . stay ROS Network topology , Nodes with duplicate names cannot appear , Because it is assumed that duplicate names can exist , Then there will be confusion when calling , That means , You cannot start a node with the same name or start the same node multiple times , You bet , stay ROS If you start the node with the same name , Previously existing nodes will be closed directly , But if there is such a need , How to optimize ?
stay ROS The solution strategy given in is to use Namespace or name remapping .
A namespace is a prefix to a name , Name remapping is aliasing a name . Both of these strategies can solve the problem of node name duplication , There are many ways to realize the two strategies :
- rosrun command
- launch file
- coded
All of the above three ways can be through namespace or name remapping , To avoid duplicate node names , This section will demonstrate the use of the three one by one , The requirements of the three are similar .
Case study
Start two turtlesim_node node , Of course, if you directly open two terminals , Direct start , Then the node that is started for the first time will shut down , And give tips :
[ WARN] [1578812836.351049332]: Shutdown request received.
[ WARN] [1578812836.351207362]: Reason given for shutdown: [new node registered with same name]
1 rosrun Set namespace and remap
1.rosrun Set namespace
1.1 Set namespace presentation
grammar : rosrun Package name The node name __ns:= New name
rosrun turtlesim turtlesim_node __ns:=/xxx
rosrun turtlesim turtlesim_node __ns:=/yyyexample
rosrun turtlesim turtlesim_node __ns:=ergouzi
rosrun turtlesim turtlesim_node __ns:=maolvzi
Both nodes can operate normally
1.2 Running results
[email protected]:~$ rosnode list
/ergouzi/turtlesim
/first/my_turtle
/maolvzi/turtlesim
/my_turtle
/rosout
/second/my_turtle
2.rosrun Name remapping
2.1 Alias the node
grammar : rosrun Package name The node name __name:= New name
rosrun turtlesim turtlesim_node __name:=t1
rosrun turtlesim turtlesim_node __name:=t2
example
rosrun turtlesim turtlesim_node __name:=daqiang
rosrun turtlesim turtlesim_node __name:=xiaoqiang
2.2 Running results
rosnode list View node information , Show results :
[email protected]:~$ rosnode list
/daqiang
/xiaoqiang
3.rosrun Namespace and name remapping overlay
3.1 The namespace name is also remapped
grammar : rosrun Package name The node name __ns:= New name __name:= New name
rosrun turtlesim turtlesim_node __name:=daqiang __ns:=ergouzi
rosrun turtlesim turtlesim_node __name:=xiaoqiang __ns:=maolvzi
[email protected]:~$ rosnode list
/ergouzi/daqiang
/rosout
/maolvzi/xiaoqiang
2 launch File set namespace and remap
Introduce launch When using the syntax of the file , stay node There are two properties in the tag : name and ns, They are used to realize name remapping and namespace setting respectively . Use launch It is also relatively simple to remap file namespace and name .
1.launch file
Create a new function pack rename01_node, Then create a new launch Folder , New under this path start_turtle.launch
<!-- Need to start multiple turtles GUI node -->
<launch>
<node pkg="turtlesim" type="turtlesim_node" name="turtlesim" />
<!-- Name remapping -->
<node pkg="turtlesim" type="turtlesim_node" name="t1" />
<!-- Namespace -->
<node pkg="turtlesim" type="turtlesim_node" name="turtlesim" ns="ergouzi" />
<!-- Namespace + Name remapping -->
<node pkg="turtlesim" type="turtlesim_node" name="t2" ns="maolvzi" />
</launch>roscore
roslaunch renaame01_node start_turtle.launch
3 Encoding setting namespace and remapping
If the custom node implements , Then you can set the namespace and remap more flexibly .
1.C++ Realization : Remap
1.1 Name alias settings
Core code ros::init(argc,argv,"zhangsan",ros::init_options::AnonymousName);
1.2 perform
Time stamp will be added after the name .
2.C++ Realization : Namespace
2.1 Namespace settings
Core code
std::map<std::string, std::string> map;
map["__ns"] = "xxxx";
ros::init(map,"wangqiang");
2.2 perform
The node name has a namespace .
边栏推荐
猜你喜欢

Ulcl function --5gc

ROS运行管理之launch文件

Wireshark IP address domain name resolution

Robot navigation implementation

文件内容的读写——数据流

OSG environment construction (win10+vs2019)

Pzk's first understanding of pointer in learning C language

力扣每日一题leetcode 513. 找树左下角的值

Li Kou daily question sword finger offer II 091. paint the house

切线空间以及TBN矩阵
随机推荐
Unity 引擎开始从 Mono 迁移到 .NET CoreCLR
多坐标变换
wireshark数据包修改--添加或修改消息字段(二)
多线程的知识补充
tqdm无法单行显示的问题
Automated Deployment Project
ROS话题名称设置
Multi threaded CAS, synchronized lock principle, JUC and deadlock
Brief introduction to unity window interface
5g network identity - detailed explanation of 5g Guti
UnityShader-LowPoly
Socket long link
链表回文判断
数据库的联合查询
Unity Hub登录无响应
Leetcode one question per day 30. Concatenate substrings of all words
Non photorealistic rendering (NPR) paper understanding and reproduction (unity) - stylized highlights for cartoon rendering and animation
力扣 110. 平衡二叉树
Code implementation and introduction of all commonly used sorting
Solve binary tree (5)