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 ...
随机推荐
- siblings()
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- boost--序列化库serialization
序列化可以把对象转化成一个字节流存储或者传输,在需要时再回复成与原始状态一致的等价对象.C++标准没有定义这个功能.boost.serialization以库的形式提供了这个功能,非常强大,可以序列化 ...
- npm的.npmrc文件在哪里?缓存及全局包文件在什么位置?
npm的.npmrc文件在哪里?缓存及全局包文件在什么位置? npm作为node开发过程中的必备工具,长期使用之后,您可能会想:这些全局安装的node包都放在硬盘里面的哪个地方?配置文件.npmr ...
- 深入浅出TCP之listen
原文:http://blog.chinaunix.net/uid-29075379-id-3858844.html int listen(int fd, int backlog); 有几个概念需要在开 ...
- EF6添加mysql的edmx实体时报错:无法生成模型:“System.Data.StrongTypingException: 表“TableDetails”中列“IsPrimaryKey”的值为 DBNull
EF6.1.3 ,使用mysql5.7的实体数据模型时,提示: 由于出现以下异常,无法生成模型:“System.Data.StrongTypingException: 表“TableDetails”中 ...
- js实现网页tab选项卡切换效果
<style> *{margin:0;padding:0;} body{font-size:14px;font-family:"Microsoft YaHei";} u ...
- python start
由于工作关系,新学习使用了python,感觉能非常快速和方便的开发,看完<简明 Python 教程>就跃跃欲试,实际用的是发现有些和C#的理解不一样 (1)如何筛选元组 例如 recor ...
- codefirst configuration
codefirst 书写配置类,用于entity与数据库中表或view映射 1.对应表或视图都用this.ToTable("SimpleCompanyLoanView", &quo ...
- ARM的Trust Zone技术
ARM的Trust_Zone技术是一个系统的Access Control的架构. 与AXI,AHB,APB其中的secure,supervisor信号相关联. 与ARM core的模式相关连,当ARM ...
- fafu 1411
想了好久都没想到怎么去判断当分类dp的时候大于或者等于要求的 值时应该怎么半 后来经过停了 qlx的想法 然后就 敲了出来 这题说的是 一个整数 分解成几个素数的和 按这个数的含有的最大素数 进行排 ...