当前位置:网站首页>ROS 重名
ROS 重名
2022-07-17 13:06:00 【2021 Nqq】
文章目录
ROS 节点名称重名
1. rosrun 设置命名空间与重映射
实现打开两个相同节点
- 方式1:设置命名空间
rosrun turtlesim turtlesim_node __ns:=ergouzi
rosrun turtlesim turtlesim_node __ns:=molvzi
rosnode list
/erGouZi/turtlesim
/molvzi/turtlesim
/rosout
/turtlesim
- 方式2:名称重映射
rosrun turtlesim turtlesim_node __name:=daqiang
rosrun turtlesim turtlesim_node __name:=xioaqiang
rosnode list
/daqiang
/erGouZi/turtlesim
/molvzi/turtlesim
/rosout
/turtlesim
/xioaqiang
2. launch文件设置命名空间与重映射
<!-- 需要启动多个乌龟GUI节点 -->
<launch>
<node pkg = "turtlesim" type = "turtlesim_node" name = "turtlesim" />
<!-- 名称重映射 -->
<node pkg = "turtlesim" type = "turtlesim_node" name = "t1" />
<!-- 命名空间 -->
<node pkg = "turtlesim" type = "turtlesim_node" name = "turtlesim" ns = "ergouzi" />
<!-- 命名空间 + 名称重映射 -->
<node pkg = "turtlesim" type = "turtlesim_node" name = "t2" ns = "maolvzi"/>
</launch>
3. 编码设置命名空间与重映射
ROS 话题名称设置
1. rosrun设置话题重映射
rosrun turtlesim turtlesim_node 与 rosrun teleop_twist_keyboard teleop_twist_keyboard.py
不能通信
rostopic list
/cmd_vel——keyboard
/rosout
/rosout_agg
/turtle1/cmd_vel ——node
/turtle1/color_sensor
/turtle1/pose
使用下面
rosrun teleop_twist_keyboard teleop_twist_keyboard.py /cmd_vel:=/turtle1/cmd_vel
或者
rosrun turtlesim turtlesim_node /turtle1/cmd_vel:=/cmd_vel
2. launch文件设置话题重映射
rename_topic——start.launch文件
<!-- 键盘控制乌龟运动 -->
<launch>
<!-- 将乌龟的话题设置为与键盘控制一致 -->
<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" />
<!-- 将键盘控制的话题设置为与乌龟一致 -->
</launch>
3. 编码设置话题名称

rosrun rename02_topic topic_name __ns:=xxx(命名空间)
rosnode list 与rostopic list
可以自己定义命名空间
#include"ros/ros.h"
#include"std_msgs/String.h"
/* 需求: 演示不同类型的话题名称设置 设置话题名称与命名空间 */
int main(int argc, char *argv[])
{
ros::init(argc,argv,"hello");//hello是节点
// ros::NodeHandle nh;
//核心:设置不同类型的话题
//1. 全局 ---- 话题名称以 / 开头(也可以设置自己的命名空间),这种情况下和节点(命名空间以及名称)没有关系
ros::Publisher pub1 = nh.advertise<std_msgs::String>("/chatter",1000);
// ros::Publisher pub1 = nh.advertise<std_msgs::String>("/yyy/chatter",1000);
//全局话题是/chatter,也可以用/yyy/chatter
//2. 相对 ---- 非 / 开头
ros::Publisher pub2 = nh.advertise<std_msgs::String>("chatter",1000);
// ros::Publisher pub2 = nh.advertise<std_msgs::String>("yyy/chatter",1000);
//3. 私有 ---- 需要创建特定的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);
// 注意:如果私有的NH创建的话题以 / 开头(全局话题),生成的话题是全局的,非私有的
// 全局话题的优先级更高
while(ros::ok())
{
}
return 0;
}
python实现
#! /usr/bin/env python
import rospy
from std_msgs.msg import String
if __name__ == "__main__":
rospy.init_node("hello")
""" 需求: 实现不同类型的话题设置 """
# 1. 全局
# pub = rospy.Publisher("/chatter",String,queue_size = 10)
# 2. 相对
pub = rospy.Publisher("chatter",String,queue_size = 10)
# 3. 私有
pub = rospy.Publisher("~chatter",String,queue_size = 10)
while not rospy.is_shutdown():
pass
ROS 参数名称设置
1. launch文件设置参数
<!-- 设置参数 -->
<launch>
<!-- 格式1: 全局 -->
<param name = "radius" value = "0.2" />
<!-- 格式2: 私有 -->
<node pkg = "turtlesim" type = "turtlesim_node" name = "t1" ns = "xxx">
<param name = "radius" value = "0.08" />
</node>
</launch>
2. 编码设置参数
C++实现
#include"ros/ros.h"
int main(int argc, char *argv[])
{
ros::init(argc,argv,"hello");
ros::NodeHandle nh;
/*
使用 ros::param 来设置参数
*/
// 1. 全局
ros::param::set("/radiusA",100);
// 2. 相对
ros::param::set("radiusB",100);
// 3. 私有
ros::param::set("~radiusC",100);
/*
使用 NodeHandle 设置参数
*/
// 全局
nh.setParam("/radius_nh_A",1000);
// 相对
nh.setParam("radius_nh_B",1000);
// 私有
ros::NodeHandle nh_private("~");
nh_private.setParam("radius_nh_C",1000);
return 0;
}
边栏推荐
- MFC | self drawn CEdit control under the framework
- c语言指针的有关总结
- Autojs learning - multi function treasure chest - bottom
- 【华为云IoT】读书笔记之《万物互联:物联网核心技术与安全》第3章(下)
- R language uses LM function to build linear regression model, and uses subset function to specify the subset of data set to build regression model (uses subset function to filter the data subset that
- C serialport configuration and attribute understanding
- 机器学习模型的评估方法
- SAP Fiori 的附件处理(Attachment handling)
- Map遍历 key-value 的4种方法
- Structure the combat battalion | module 7
猜你喜欢

2022年全国最新消防设施操作员(中级消防设施操作员)模拟试题及答案

Avi 部署使用指南(2):Avi 架构概述
![[PostgreSQL] PostgreSQL 15 optimizes distinct](/img/18/5aaae76c1c269960defc7db8a9e63f.png)
[PostgreSQL] PostgreSQL 15 optimizes distinct

"Baidu side" angrily sprayed the interviewer! Isn't it that the tree time increases by a line number?

常见集合特性

HCIA rip experiment 7.11

基于微信小程序的外卖点餐系统

Map遍历 key-value 的4种方法

Design and Simulation of intelligent storage cabinet control system

JSP based novel writing and creation website
随机推荐
Aike AI frontier promotion (7.17)
Convert excel table to word table, and keep the formula in Excel table unchanged
爱可可AI前沿推介(7.17)
YARN环境中应用程序JAR包冲突问题的分析及解决
开发第一个Flink应用
金鱼哥RHCA回忆录:CL210描述OPENSTACK控制平面--识别overclound控制平台服务+章节实验
Bazel use tutorial to
Hcip day 1 7.15
R language uses the KAP function of epidisplay package to calculate the proportion of calculation consistency of paired contingency tables and the value of kappa statistics, and uses xtabs function to
bazel使用教程 转
Attachment handling of SAP Fiori
unity3d如何利用asset store下载一些有用的资源包
圆桌实录:炉边对话——如何在 Web3 实现创新
Develop the first Flink app
华为防火墙认证技术
HCIA static comprehensive experiment report 7.10
C serialport configuration and attribute understanding
微信小程序云开发 1 - 数据库
SAP AppGyver 的 Universal Theme System 使用介绍
2022年全国最新消防设施操作员(中级消防设施操作员)模拟试题及答案