当前位置:网站首页>ROS话题名称设置
ROS话题名称设置
2022-07-27 05:21:00 【三个刺客】
1 rosrun设置话题重映射
未映射之前的rqt_graph

rosrun名称重映射语法: rorun 包名 节点名 话题名:=新话题名称
实现teleop_twist_keyboard与乌龟显示节点通信方案由两种:
1.方案1
将 teleop_twist_keyboard 节点的话题设置为/turtle1/cmd_vel
启动键盘控制节点:rosrun teleop_twist_keyboard teleop_twist_keyboard.py /cmd_vel:=/turtle1/cmd_vel
启动乌龟显示节点: rosrun turtlesim turtlesim_node
二者可以实现正常通信
修改后的rqt_graph


此时也没有了/cmd_vel
2.方案2
将乌龟显示节点的话题设置为 /cmd_vel
启动键盘控制节点:rosrun teleop_twist_keyboard teleop_twist_keyboard.py
启动乌龟显示节点: rosrun turtlesim turtlesim_node /turtle1/cmd_vel:=/cmd_vel
二者可以实现正常通信


2 launch文件设置话题重映射
launch 文件设置话题重映射语法:
<node pkg="xxx" type="xxx" name="xxx">
<remap from="原话题" to="新话题" />
</node>
实现teleop_twist_keyboard与乌龟显示节点通信方案有两种:
1.方案1
将 teleop_twist_keyboard 节点的话题设置为/turtle1/cmd_vel
<launch>
<node pkg="turtlesim" type="turtlesim_node" name="t1" />
<node pkg="teleop_twist_keyboard" type="teleop_twist_keyboard.py" name="key">
<remap from="/cmd_vel" to="/turtle1/cmd_vel" />
</node>
</launch>
2.方案2
将乌龟显示节点的话题设置为 /cmd_vel
<!-- 键盘控制乌龟运动 -->
<launch>
<!-- 将乌龟的话题设置为与键盘控制一致 -->
<node pkg="turtlesim" type="turtlesim_node" name="t1">
<remap from="/turtle1/cmd_vel" to="/cmd_vel" />
</node>
<node pkg="teleop_twist_keyboard" type="teleop_twist_keyboard.py" name="key" />
<!-- 将键盘控制的话题设置为与乌龟一致 -->
</launch>3 编码设置话题名称
话题的名称与节点的命名空间、节点的名称是有一定关系的,话题名称大致可以分为三种类型:
- 全局(话题参考ROS系统,与节点命名空间平级)
- 相对(话题参考的是节点的命名空间,与节点名称平级)
- 私有(话题参考节点名称,是节点名称的子级)
结合编码演示具体关系。
int main(int argc, char *argv[])
{
//1.初始化节点设置一个节点名称
//2.设置不同类型的话题
//3.启动节点时,传递一个 __ns:= xxx
//4.节点启动后,使用 rostopic 查看话题信息
ros::init(argc,argv,"hello");
//ros::NodeHandle nh;
//核心:设置不同类型的话题
//1.全局 --- 话题名称需要以/开头(也可以设置自己的命名空间),这种情况下和节点(命名空间以及名称)没有关系
//ros::Publisher pub = nh.advertise<std_msgs::String>("/chatter",1000);
//ros::Publisher pub = nh.advertise<std_msgs::String>("/yyy/chatter",1000);
//2.相对
//ros::Publisher pub = nh.advertise<std_msgs::String>("chatter",1000);
//ros::Publisher pub = nh.advertise<std_msgs::String>("yyy/chatter",1000);
//3.私有 需要创建特定 NodeHandle
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;
}1.1全局名称
格式:以/开头的名称,和节点名称无关
示例1:
ros::Publisher pub = nh.advertise<std_msgs::String>("/chatter",1000);
结果1:
/chatter
示例2:
ros::Publisher pub = nh.advertise<std_msgs::String>("/yyy/chatter",1000);
结果2:
/yyy/chatter
1.2相对名称
格式:非/开头的名称,参考命名空间(与节点名称平级)来确定话题名称
示例1:
ros::Publisher pub = nh.advertise<std_msgs::String>("chatter",1000);
结果1:
xxx/chatter
示例2:
ros::Publisher pub = nh.advertise<std_msgs::String>("yyy/chatter",1000);
xxx/yyy/chatter
1.3私有名称
格式:以~开头的名称
示例1:
ros::NodeHandle nh("~");
ros::Publisher pub = nh.advertise<std_msgs::String>("chatter",1000);
结果1:
/xxx/hello/chatter
示例2:
ros::NodeHandle nh("~");
ros::Publisher pub = nh.advertise<std_msgs::String>("yyy/chatter",1000);
结果2:
/xxx/hello/yyy/chatter
PS:当使用~,而话题名称有时/开头时,那么话题名称是绝对的
示例3:
ros::NodeHandle nh("~");
ros::Publisher pub = nh.advertise<std_msgs::String>("/yyy/chatter",1000);
结果3:
/yyy/chatter
边栏推荐
- 论文写作(收获)
- 这是我的博客
- Force buckle 160. intersecting linked list
- IP核小结
- [first song] rebirth of me in py introductory training (6): definition and application of functions
- Super remote connection management tool: Royal TSX
- 如何区分独立服务器与VPS主机?
- [song] rebirth of me in py introductory training (7): function call
- STM32 infrared remote control
- C语言--字符串操作函数与内存操作函数
猜你喜欢

Leetcode one question per day 30. Concatenate substrings of all words

AE 3D particle system plug-in: Trapcode particle

Redis在windows下的idea连接不上问题

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

Unity Hub登录无响应

WebODM win10安装教程(亲测)

PS 2022 updated in June, what new functions have been added

When multiple formulas in latex share a sequence number

arcgis for js api(2) 获取要素服务的id集合

Unity 桌面7.6 版本解读
随机推荐
acwing每日一题 正方形数组的数目
[song] rebirth of me in py introductory training (9): exception handling
遥感影像识别-成像合成
Dynamic planning for solving problems (5)
Solve binary tree (7)
Redis在windows下的idea连接不上问题
力扣 236. 二叉树的最近公共祖先
Dynamic planning for solving problems (4)
Unity 桌面7.6 版本解读
Solve binary tree (5)
PZK学C语言之初识指针
Cmder的基础文件操作
力扣每日一题 剑指 Offer II 091. 粉刷房子
1 semi automatic crawler
Weidongshan digital photo frame project learning (III) transplantation of freetype
C thread lock
[song] rebirth of me in py introductory training (10): numpy
UnityShader-高斯模糊
性感素数(Acwing每日一题)
Can it replace PS's drawing software?