当前位置:网站首页>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
边栏推荐
- Read the introduction tutorial of rainbow
- 八、picker用法 下拉框选择效果
- Hcip day 12
- 用 Table 在 SwiftUI 下创建表格
- 2022 low voltage electrician examination questions and answers
- The method of implementing simple student achievement management system with C language
- VTK notes - picker picker summary
- Excel VBA 开发过程中遇到的一些问题,解决方案,持续更新
- [Tanabata] Tanabata lonely little frog research edition? The final chapter of Tanabata Festival!
- 爆肝整理JVM十大模块知识点总结,不信你还不懂
猜你喜欢

Interviewer: what are the usage scenarios of ThreadLocal? How to avoid memory leakage?

Multi merchant mall system function disassembly lecture 17 - platform side order list

@Solution to DS ('slave') multi data source compatible transaction problem

Tdengine helps Siemens' lightweight digital solutions

BGP experiment

Summarize the knowledge points of the ten JVM modules. If you don't believe it, you still don't understand it

Various pitfalls encountered in UI development
C# 获取当前路径7种方法

Redis redis use in jedis

How long can we "eat" the dividends of domestic databases?
随机推荐
@Solution to DS ('slave') multi data source compatible transaction problem
十、时间戳
Vtkcellpicker picking triangular patches
Why can the anonymous functions of JQ access the methods inside
Swiftui layout - size (bottom)
pix2pix
基于 MinIO 对象存储保障 Rancher 数据
2022 high altitude installation, maintenance, removal of examination question bank and online simulated examination
实时切换 Core Data 的云同步状态
文件批量重命名工具Bulk Rename Utility
Cv:: mat conversion to qimage error
C语言库函数getchar()怎么使用
BGP experiment
Pointers and arrays (7)
QT qbuttongroup realizes single selection and multiple selection
The method of implementing simple student achievement management system with C language
树莓派基础 | 总结记录树莓派学习过程中的一些操作
为 @CloudStorage 添加了类 @Published 的能力
国产数据库的红利还能“吃”多久?
Third class exercise