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 ...
随机推荐
- POJ1258:Agri-Net(最小生成树模板题)
http://poj.org/problem?id=1258 Description Farmer John has been elected mayor of his town! One of hi ...
- PAT 1034 Head of a Gang[难][dfs]
1034 Head of a Gang (30)(30 分) One way that the police finds the head of a gang is to check people's ...
- Hive的安装与配置
1.因为我使用MySQL做为Hive的元数据库,所以先安装MySQL. 参考:http://www.cnblogs.com/hunttown/p/5452205.html 登录命令:mysql -h主 ...
- Ember.js学习教程 -- 目录
写在前面的话: 公司的新项目需要用到Ember.js,版本为v1.13.0.由于网上关于Ember的资料非常少,所以只有硬着头皮看官网的Guides,为了加深印象和方便以后查阅就用自己拙劣的英语水平把 ...
- Django初级手册6-静态文件
用Django加载外部文件 在Django中iamges,JS或者CSS通称为static文件 定制APP的外观 一般放在应用目录下的static/polls/目录下,下为polls/static/p ...
- Python: 序列: 过滤序列元素
问题: 你有一个数据序列,想利用一些规则从中提取出需要的值或者是缩短序列 answer: eg1:列表推导 最简单的过滤序列元素的方法就是使用列表推导.比如:>>> mylist = ...
- Java EE企业应用发展
新形式下的企业应用特点企业应用系统从封闭走向开放,由局域网转到互联网,随着涉众面的极大扩展,新的企业应用要求多浏览器支持,国际化支持,全球业务的互联互通.企业需求提升.除了功能性需求,客户对于安全,性 ...
- Linux基础命令---diff
diff 逐行比较两个文本文件,把文件的差异显示到标准输出.如果要指定要比较目录,那么diff命令会比较目录中相同文件名的文件,不会比较子目录. 此命令的适用范围:RedHat.RHEL.Ubuntu ...
- APP获取证书签名指纹
Android: public static String getSignatureSHA1(Context context) { String sign = null; try { // 通过包管理 ...
- FreeModbus移植实例(转)
源:分享FreeRTOS + FreeModbus + UART_RTO FREERTOS 移植学习 入门必备 正点原子官方所有开发板的FreeRTOS教程及其例程正式发布(STM32F103,STM ...