当前位置:网站首页>17、 Solutions to duplicate names of ROS function packages and nodes
17、 Solutions to duplicate names of ROS function packages and nodes
2022-07-28 14:53:00 【Rock magnon】
List of articles
1、ROS Different workspace function packages have the same name
1. Definition
The so-called workspace coverage , It means in different workspaces , There are function packages with duplicate names . stay ROS In development , In the same workspace , The function package will not have the same name . however , In different workspaces , There may be the phenomenon of duplicate function package names .
2. Call rules when the function package has the same name
- In the root directory .bashrc Add... To the file ROS Function package retrieval path :
source /opt/ros/noetic/setup.bash source /media/d102/EPAN/Desktop/code_study_ubuntu/rosdemo_05/devel/setup.bash source /media/d102/EPAN/Desktop/code_study_ubuntu/rosdemo_04/devel/setup.bash- Update the search path
In the root directory :
source .bashrc- Update the search path
- Print ROS Function package retrieval path
- command :
echo $ROS_PACKAGE_PATH
echo $ROS_PACKAGE_PATH
/media/d102/EPAN/Desktop/code_study_ubuntu/rosdemo_04/src:/media/d102/EPAN/Desktop/code_study_ubuntu/rosdemo_05/src:/opt/ros/noetic/share
so , The path is farther back , The higher the priority , When the function package has the same name , Will search according to priority , Those with high priority are executed first
- roscd Function pack
Will enter the workspace containing the corresponding function package , By viewing the workspace path , You can know which workspace function package is called
- roscd Function pack
3. Safe hidden trouble
When there is a function package with the same name , Execution exceptions may occur . such as ,C When the function package is executed , rely on A Medium turtle Function pack , But it did B Medium turtle Function pack , Because the two function packs have the same name , Different functions , This leads to execution exceptions
4.BUG explain
In the root directory .bashrc In file , meanwhile source Multiple files , It might show up in ROS_PACKAGE_PATH Contains only two workspaces bug, The solution is as follows :( This BUG It's very metaphysical , At present, we have not found 100% Effective methods , The following methods are for reference )
Delete... In the workspace build and devel Folder recompile , And then reload .bashrc file
- Be careful :
When recompiling , It may appear as follows BUG:-- Using PYTHON_EXECUTABLE: /home/matthew/anaconda3/envs/torch/bin/python3 -- Using Debian Python package layout -- Could NOT find PY_em (missing: PY_EM) CMake Error at /opt/ros/noetic/share/catkin/cmake/empy.cmake:30 (message): Unable to find either executable 'empy' or Python module 'em'... try installing the package 'python3-empy' Call Stack (most recent call first): /opt/ros/noetic/share/catkin/cmake/all.cmake:164 (include) /opt/ros/noetic/share/catkin/cmake/catkinConfig.cmake:20 (include) CMakeLists.txt:58 (find_package)
This is because catkin Looking for python Version is anaconda The following version , So you need to specify the following command instead :
catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3
2. ROS Duplicate node name
2.1 background
Sometimes , You need to start the same node , If you start directly , Because the node names are the same , The node that starts first will be shut down due to the duplicate name , To solve this problem , The following three methods can be used :
2.2 terms of settlement
2.2.1 rosrun Set namespace and remap
2.2.1.1 rosrun Set namespace
- Format :rosrun package_name node_name __ns:=ns_name
- Code implementation :
# bash1 rosrun turtlesim turtlesim_node __ns:=ns1 # bash2 rosrun turtlesim turtlesim_node __ns:=ns2 - Running results :
rosnode list /ns1/turtlesim /ns2/turtlesim /rosout /turtlesim
2.2.1.2 rosrun Name remapping
- Format :rosrun package_name node_name __name:=new_name( Do not apply to Python)
- Code implementation :
# bash1 rosrun turtlesim turtlesim_node __name:=t1 # bash2 rosrun turtlesim turtlesim_node __name:=t2 - Running results :
rosnode list /t1 /t2 /turtlesim
2.2.1.3 rosrun Superposition of namespace and name remapping
- Format 1:rosrun package_name node_name __ns:=ns_name __name:=new_name
- Format 2:rosrun package_name node_name __name:=new_name __ns:=ns_name
- Code implementation :
# bash1 rosrun turtlesim turtlesim_node __ns:=ns1 __name:=t1 # bash2 rosrun turtlesim turtlesim_node __name:=t2 __ns:=ns2 - Running results :
/ns1/t1 /ns2/t2
2.2.1.4 Setting environment variables can also set namespaces
- Format :export ROS_NAMESPACE=ns_name
- Code implementation :
# bash1 [email protected]:~$ export ROS_NAMESPACE=ns3 [email protected]:~$ rosrun turtlesim turtlesim_node # bash2 [email protected]:~$ export ROS_NAMESPACE=ns4 [email protected]:~$ rosrun turtlesim turtlesim_node - Running results :
/ns3/turtlesim /ns4/turtlesim
2.2.2 launch File set namespace and remap
- Code implementation :
<launch> <!-- Reference nodes --> <node pkg="turtlesim" type="turtlesim_node" name="turtlesim" /> <!-- Name remapping --> <node pkg="turtlesim" type="turtlesim_node" name="turtlesim_01" /> <!-- Namespace --> <node pkg="turtlesim" type="turtlesim_node" name="turtlesim" ns="ns_01"/> <!-- Namespace + Name remapping --> <node pkg="turtlesim" type="turtlesim_node" name="turtlesim_02" ns="ns_02"/> </launch> - Running results :
rosnode list /ns3/ns_01/turtlesim /ns3/ns_02/turtlesim_02 /ns3/turtlesim_01 /turtlesim
2.2.3 Code set namespace and remap
2.2.3.1 C++ Implement remapping
- Code implementation :
ros::init(argc,argv,"server",ros::init_options::AnonymousName);// Add a timestamp after the node - Running results :
# bash1 rosrun server_client server # bash2 rosnode list /server_1656775703891563446
2.2.3.2 C++ Implementation namespace
- Code implementation :
std::map<std::string, std::string> map; map["__ns"] = "namespace_01"; ros::init(map,"server",ros::init_options::AnonymousName);//server Name the node - Running results :
# bash1 rosrun server_client server # bash2 rosnode list /namespace_01/server_1656776071871347181
2.2.3.3 Python Implement remapping ( Cannot implement namespace )
- Code implementation :
rospy.init_node("server_p",anonymous=True) # The timestamp will be added after the node - Running results :
# bash1 rosrun server_client server_p.py # bash2 rosnode list /server_p_188947_1656776369182
边栏推荐
- [Tanabata] Tanabata lonely little frog research edition? The final chapter of Tanabata Festival!
- When Xcode writes swiftui code, it is a small trap that compiles successfully but causes the preview to crash
- 实时切换 Core Data 的云同步状态
- SwiftUI 布局 —— 尺寸( 下 )
- VTK vtkcontourwidget extracts regions of interest
- Afnetworking crash course
- Tdengine helps Siemens' lightweight digital solutions
- 看了就会的 Rainbond 入门教程
- SwiftUI 布局 —— 尺寸( 上 )
- Introduction to MITK
猜你喜欢

Redis configuration file explanation

VTK vtkcontourwidget extracts regions of interest

10、 Timestamp

多商户商城系统功能拆解17讲-平台端订单列表

Introduction to MITK

How long can we "eat" the dividends of domestic databases?

八、picker用法 下拉框选择效果

Getting started with scottplot tutorial: getting and displaying values at the mouse
Some problems encountered in the development of Excel VBA, solutions, and continuous updates

@DS('slave') 多数据源兼容事务问题解决方案
随机推荐
Installing redis in Linux
多商户商城系统功能拆解17讲-平台端订单列表
@DS('slave') 多数据源兼容事务问题解决方案
Brief introduction of diversity technology
How to perform batch operations in core data
C语言实现简单学生成绩管理系统的方法
When Xcode writes swiftui code, it is a small trap that compiles successfully but causes the preview to crash
用 Table 在 SwiftUI 下创建表格
Another way of understanding the essence of Hamming code
Unittest executes runtestcase prompt <_ io. Textiowrapper name= '< stderr>' mode=W encoding=UTF-8 > solution
Hcip day 11
C language program: judging triangles
Redis persistence
Iterator iterator interface
国产数据库的红利还能“吃”多久?
58子站安居,经纪人营销管理平台登录接口加密逆向
2022 melting welding and thermal cutting examination questions and online simulation examination
多线程顺序运行有几种方法?
String转为long 类型报错原因:要转为long必须是int、double、float型[通俗易懂]
(function(global,factory){