python ros topic demo
发布者:
#!/usr/bin/env python
#coding=utf- import rospy
from std_msgs.msg import String def talker():
pub = rospy.Publisher('chatter',String, queue_size=)
rospy.init_node('talker',anonymous=True)
rate = rospy.Rate() # 10hz
while not rospy.is_shutdown():
hello_str = "超哥 好帅啊 %s" % rospy.get_time()
rospy.loginfo(hello_str)
pub.publish(hello_str)
rate.sleep() if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass
from std_msgs.msg import String分析:
- 导入python的标准字符处理库
- String是一个函数,可以另外方式赋值
msg = String()
msg.data = str
或
String(data=str)
订阅者:
#!/usr/bin/env python
#coding=utf- import rospy
from std_msgs.msg import String def callback(data):
rospy.loginfo(rospy.get_caller_id() + '我觉得 %s', data.data) def listener(): # In ROS, nodes are uniquely named. If two nodes with the same
# name are launched, the previous one is kicked off. The
# anonymous=True flag means that rospy will choose a unique
# name for our 'listener' node so that multiple listeners can
# run simultaneously.
#对上面注释翻译
#在ROS中,节点是唯一命名的。 如果两个节点相同
#名称被启动,前一个被启动。该
#anonymous = True标志意味着rospy会选择一个独特的
#我们的'侦听器'节点的名称,以便多个侦听器可以
#同时运行。
rospy.init_node('listener', anonymous=True) rospy.Subscriber('chatter', String, callback) # spin() simply keeps python from exiting until this node is stopped
rospy.spin() if __name__ == '__main__':
listener()
先执行发布者,再执行订阅者(python xxx.py)
输出为:
[INFO] [WallTime: 1526964838.601590] /listener_1299_1526964825697好帅啊 1526964838.6
[INFO] [WallTime: 1526964838.701610] /listener_1299_1526964825697好帅啊 1526964838.7
[INFO] [WallTime: 1526964838.801621] /listener_1299_1526964825697好帅啊 1526964838.8
[INFO] [WallTime: 1526964838.901650] /listener_1299_1526964825697好帅啊 1526964838.9
[INFO] [WallTime: 1526964839.001606] /listener_1299_1526964825697好帅啊 1526964839.0
[INFO] [WallTime: 1526964839.101618] /listener_1299_1526964825697好帅啊 1526964839.1
python ros topic demo的更多相关文章
- ROS 进阶学习笔记(13) - Combine Subscriber and Publisher in Python, ROS
Combine Subscriber and Publisher in Python, ROS This article will describe an example of Combining S ...
- RPi 2B python opencv camera demo example
/************************************************************************************** * RPi 2B pyt ...
- ROS手动编写消息发布器和订阅器topic demo(C++)
1.首先创建 package cd ~/catkin_ws/src catkin_create_pkg topic_demo roscpp rospy std_msgs 2. 编写 msg 文件 cd ...
- python ros 回充demo
#!/usr/bin/env python #coding=utf- import rospy from std_msgs.msg import String i= def talker(): glo ...
- python ros 回充调用demo
#!/usr/bin/env python #coding=utf- import rospy from std_msgs.msg import String def talker(): pub = ...
- pyhanlp python 脚本的demo补充
java demo https://github.com/hankcs/HanLP/tree/master/src/test/java/com/hankcs/demo github python de ...
- python ros 创建节点订阅robot_pose
建立文件夹hello_rospy,再在该目录下建立子目录src,cd到该src目录,运行如下命令创建工作包 catkin_create_pkg beginner_tutorials std_msgs ...
- python ros 订阅robot_pose获取机器人位置
#!/usr/bin/env python import rospy import tf from tf.transformations import * from std_msgs.msg impo ...
- kafka--通过python操作topic
修改 topic 的分区数 shiyanlou:bin/ $ ./kafka-topics.sh --zookeeper localhost:2181 --alter --topic mySendTo ...
随机推荐
- testng入门教程16数据驱动(把数据写在xml)
testng入门教程16数据驱动(把数据写在xml) testng入门教程16数据驱动(把数据写在xml)把数据写在xml文件里面,在xml文件右键选择runas---testng执行 下面是case ...
- APPIUM Android 定位方式
原文地址https://www.cnblogs.com/sundalian/p/5629500.html 1.定位元素应用元素 1.1通过id定位元素 Android里面定位的id一般为resrouc ...
- 软件包管理:yum在线管理-yum命令
只要我们的电脑可以接入互联网,那么yum源就是配好的,yum命令可以直接使用. 列出的是服务器上全部的rpm包. 包名,包全名的概念只在rpm手动管理时有用. 关键字主要指包名,只要知道了关键字就可以 ...
- linux文件系统软链接硬链接
引子 目前,UNIX的文件系统有很多种实现,例如UFS(基于BSD的UNIX文件系统).ext3.ext4.ZFS和Reiserfs等等. 不论哪一种文件系统,总是需要存储数据.硬盘的最小存储单位是扇 ...
- vue框架(二)_vue环境搭建及创建项目
1.node.js:概念介绍及安装 node.js:是一个基于chrome浏览器的v8引擎,可以运行javascript的环境(平台) 特性:异步IO模型 npm:是一个包管理器(工具),可以按装依赖 ...
- NPOI 导出excel 分表
/// <summary> /// 由DataTable导出Excel[超出65536自动分表] /// </summary> /// <param name=" ...
- python 采坑总结 调用键盘事件后导致键盘失灵的可能原因
在练习python封装键盘事件的时候,实现一个keyDown和keyUp的功能: @staticmethod def keyDown(keyName): #按下按键 ...
- yum安装时提示app is currently holding the yum lock; waiting for it to exit
yum安装时出现下面情况 可能是yum升级一些文件时,出现这种情况 解决方法: #rm -f /var/run/yum.pid 强制关掉yun进程
- 向大家分享一个shell脚本的坑
打算在跳板机上写一个shell脚本,批量检查远程服务器上的main进程是否在健康运行中. 先找出其中一台远程机器,查看main进程运行情况 [root@two002 tmp]# ps -ef|grep ...
- 容器技术与DevOps
容器技术的使用支撑了目前 DevOps 三大主要实践:工作流.及时反馈.持续学习. 有人说容器技术与 DevOps 二者在发展的过程中是互相促进的关系.得益于 DevOps 设计理念的流行,容器生态系 ...