当前位置:网站首页>ROS duplicate name
ROS duplicate name
2022-07-19 10:51:00 【2021 Nqq】
List of articles
ROS Duplicate node name
1. rosrun Set namespace and remap
Open two same nodes
- The way 1: Set namespace
rosrun turtlesim turtlesim_node __ns:=ergouzi
rosrun turtlesim turtlesim_node __ns:=molvzi
rosnode list
/erGouZi/turtlesim
/molvzi/turtlesim
/rosout
/turtlesim
- The way 2: Name remapping
rosrun turtlesim turtlesim_node __name:=daqiang
rosrun turtlesim turtlesim_node __name:=xioaqiang
rosnode list
/daqiang
/erGouZi/turtlesim
/molvzi/turtlesim
/rosout
/turtlesim
/xioaqiang
2. launch File set namespace and remap
<!-- 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>
3. Encoding setting namespace and remapping
ROS Topic name setting
1. rosrun Set topic remapping
rosrun turtlesim turtlesim_node And rosrun teleop_twist_keyboard teleop_twist_keyboard.py
Can't communicate
rostopic list
/cmd_vel——keyboard
/rosout
/rosout_agg
/turtle1/cmd_vel ——node
/turtle1/color_sensor
/turtle1/pose
Use the following
rosrun teleop_twist_keyboard teleop_twist_keyboard.py /cmd_vel:=/turtle1/cmd_vel
perhaps
rosrun turtlesim turtlesim_node /turtle1/cmd_vel:=/cmd_vel
2. launch File set topic remapping
rename_topic——start.launch file
<!-- Keyboard controls tortoise movement -->
<launch>
<!-- Set the turtle's topic to be consistent with the keyboard control -->
<node pkg = "turtlesim" type = "turtlesim_node" name = "t1" >
<remap from = "/turtle1/cmd_vel" to = "/cmd_vel" />
</node>
<nodep pkg = "teleop_twist_keyboard" type = "teleop_twist_keyboard.py" name = "key1" />
<!-- Set the topic controlled by the keyboard to be consistent with the tortoise -->
</launch>
3. Code and set the topic name
rosrun rename02_topic topic_name __ns:=xxx( Namespace )
rosnode list And rostopic list
You can define your own namespace
#include"ros/ros.h"
#include"std_msgs/String.h"
/* demand : Demonstrate different types of topic name settings Set topic name and namespace */
int main(int argc, char *argv[])
{
ros::init(argc,argv,"hello");//hello Is the node
// ros::NodeHandle nh;
// The core : Set different types of topics
//1. overall situation ---- Topic name with / start ( You can also set your own namespace ), In this case, and nodes ( Namespace and name ) It doesn't matter.
ros::Publisher pub1 = nh.advertise<std_msgs::String>("/chatter",1000);
// ros::Publisher pub1 = nh.advertise<std_msgs::String>("/yyy/chatter",1000);
// The overall topic is /chatter, It can also be used. /yyy/chatter
//2. relative ---- Not / start
ros::Publisher pub2 = nh.advertise<std_msgs::String>("chatter",1000);
// ros::Publisher pub2 = nh.advertise<std_msgs::String>("yyy/chatter",1000);
//3. private ---- You need to create a specific NodeHandle nh("~")
ros::NodeHandle nh("~");
// ros::Publisher pub = nh.advertise<std_msgs::String>("chatter",1000);
ros::Publisher pub = nh.advertise<std_msgs::String>("yyy/chatter",1000);
// Be careful : If private NH Create a topic with / start ( Global topics ), The generated topic is global , Non private
// The priority of global topics is higher
while(ros::ok())
{
}
return 0;
}
python Realization
#! /usr/bin/env python
import rospy
from std_msgs.msg import String
if __name__ == "__main__":
rospy.init_node("hello")
""" demand : Implement different types of topic settings """
# 1. overall situation
# pub = rospy.Publisher("/chatter",String,queue_size = 10)
# 2. relative
pub = rospy.Publisher("chatter",String,queue_size = 10)
# 3. private
pub = rospy.Publisher("~chatter",String,queue_size = 10)
while not rospy.is_shutdown():
pass
ROS Parameter name setting
1. launch File settings parameters
<!-- Set parameters -->
<launch>
<!-- Format 1: overall situation -->
<param name = "radius" value = "0.2" />
<!-- Format 2: private -->
<node pkg = "turtlesim" type = "turtlesim_node" name = "t1" ns = "xxx">
<param name = "radius" value = "0.08" />
</node>
</launch>
2. Code setting parameters
C++ Realization
#include"ros/ros.h"
int main(int argc, char *argv[])
{
ros::init(argc,argv,"hello");
ros::NodeHandle nh;
/*
Use ros::param To set parameters
*/
// 1. overall situation
ros::param::set("/radiusA",100);
// 2. relative
ros::param::set("radiusB",100);
// 3. private
ros::param::set("~radiusC",100);
/*
Use NodeHandle Set parameters
*/
// overall situation
nh.setParam("/radius_nh_A",1000);
// relative
nh.setParam("radius_nh_B",1000);
// private
ros::NodeHandle nh_private("~");
nh_private.setParam("radius_nh_C",1000);
return 0;
}
边栏推荐
- String类型函数传递问题
- 分类任务中的类别不平衡问题
- TS解决引入插件的类型文件不存在的问题
- Autojs learning - multi function treasure chest - bottom
- Beego framework realizes file upload + seven cattle cloud storage
- 腾讯云服务器利用镜像部署WordPress个人网站!
- input number 纯数字输入 限制长度 限制 最大值
- 金鱼哥RHCA回忆录:CL210描述OPENSTACK控制平面--识别overclound控制平台服务+章节实验
- 自动化之图形界面库pyautogui
- (一)了解MySQL
猜你喜欢
随机推荐
[makefile] some notes on the use of makefile
LeetCode 2315. 统计星号(字符串)
[PostgreSQL] PostgreSQL 15 optimizes distinct
论文笔记:Mind the Gap An Experimental Evaluation of Imputation ofMissing Values Techniques in TimeSeries
Custom complex logic verification during adding and modifying -2022 new project
新增、修改操作时自定义复杂逻辑校验-2022新项目
How to use SVG to make text effects arranged along any path
Google Earth Engine——Hansen Global Forest Change v1.8 (2000-2020) 森林覆盖度和森林损失量数据集
树链剖分思想讲解 + AcWing 2568. 树链剖分(dfs序 + 爬山法 + 线段树)
线程池原理
追根问底:Objective-C关联属性原理分析
Map遍历 key-value 的4种方法
Pytorch框架 学习记录1 CIFAR-10分类
Pytorch手动实现多层感知机
Leetcode丑数题解
【华为云IoT】读书笔记之《万物互联:物联网核心技术与安全》第3章(下)
LeetCode 2335. 装满杯子需要的最短总时长
华为机试:连续出牌数量
Google Earth Engine APP(GEE)—设定中国区域的一个夜间灯光时序分析app
[Acwing]第 60 场周赛 B- 4495. 数组操作