#!/usr/bin/env python
import rospy
import tf
import time
from tf.transformations import *
from std_msgs.msg import String
from geometry_msgs.msg import Pose
from geometry_msgs.msg import Quaternion
filenm="/opt/bp/tmp"
tms=
tp_x=0.0
tp_y=0.0
tp_a=0.0
i=tms
def get_pos(data):
global tp_x
global tp_y
global tp_a
global i
global tms
(roll, pitch, yaw) = euler_from_quaternion([data.orientation.x, data.orientation.y, data.orientation.z, data.orientation.w])
if(i==):
rospy.loginfo("current position(x:%f,y:%f),theta:%f", data.position.x, data.position.y, yaw)
if(tp_x==round(data.position.x,)):
if(tp_y==round(data.position.y,)):
if(tp_a==round(yaw,)):
rospy.loginfo("still!")
else:
with open(filenm, 'w+') as f:
f.write(str(data.position.x)+","+str(data.position.y)+","+str(yaw))
rospy.loginfo("write!")
else:
with open(filenm, 'w+') as f:
f.write(str(data.position.x)+","+str(data.position.y)+","+str(yaw))
rospy.loginfo("write!")
else:
with open(filenm, 'w+') as f:
f.write(str(data.position.x)+","+str(data.position.y)+","+str(yaw))
rospy.loginfo("write!")
i=tms
tp_x=round(data.position.x,)
tp_y=round(data.position.y,)
tp_a=round(yaw,)
i=i-
#rospy.loginfo("current position(x:%f,y:%f,z:%f)", data.position.x, data.position.y, data.position.z) def poslistener():
# 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.
rospy.init_node('poslistener', anonymous=True) rospy.Subscriber("robot_pose", Pose, get_pos) # spin() simply keeps python from exiting until this node is stopped
rospy.spin() if __name__ == '__main__':
poslistener()

ros python 订阅robot_pose的更多相关文章

  1. python ros 创建节点订阅robot_pose

    建立文件夹hello_rospy,再在该目录下建立子目录src,cd到该src目录,运行如下命令创建工作包 catkin_create_pkg beginner_tutorials std_msgs ...

  2. python ros 订阅robot_pose获取机器人位置

    #!/usr/bin/env python import rospy import tf from tf.transformations import * from std_msgs.msg impo ...

  3. How to fix the conflict between ROS Python and Conda

    Problem: Ever since I have installed Conda, ROS does not seem to work. And predictably it is because ...

  4. ROS多线程订阅消息

    对于一些只订阅一个话题的简单节点来说,我们使用ros::spin()进入接收循环,每当有订阅的话题发布时,进入回调函数接收和处理消息数据.但是更多的时候,一个节点往往要接收和处理不同来源的数据,并且这 ...

  5. ros python 重置位置

    #!/usr/bin/env python import rospy import math import sys import commands import yaml from tf import ...

  6. ros python 构造 pose

    #!/usr/bin/env python import numpy as npfrom geometry_msgs.msg import Pose, Point, Quaternion, Twist ...

  7. ros Python找不到msg包的问题解决办法

    https://answers.ros.org/question/113671/catkin-package-cannot-find-own-message-type-python/ 原因是因为.py ...

  8. ros python

    https://www.ncnynl.com/archives/201611/1059.html python的节点需要对节点设置权限为可执行,在.py文件所在的路径执行如下命令 $ touch ta ...

  9. ros python 四元数 转 欧拉角

    import sysimport math w = -0.99114048481x = -0.00530699081719y = 0.00178255140781z = -0.133612662554 ...

随机推荐

  1. Filter与Servlet的区别与联系

    Filter与Servlet的区别与联系 转自 http://blog.csdn.net/gaibian0823/article/details/51027495 在我们写代码时,在web.xml中总 ...

  2. Cobbler 自动化部署系统

    yum安装 yum install -y epel-release yum install -y httpd dhcp tftp cobbler cobbler-web pykickstart xin ...

  3. How to enable TLS 1.2 on Windows Server 2008 R2

    Problem How to enable TLS 1.2 on Windows Server 2008 R2? Resolution QuoVadis recommends enabling and ...

  4. Bootstrap 网格系统(Grid System)的工作原理 - 媒体查询

    媒体查询 媒体查询是非常别致的"有条件的 CSS 规则".它只适用于一些基于某些规定条件的 CSS.如果满足那些条件,则应用相应的样式. Bootstrap 中的媒体查询允许您基于 ...

  5. unittest之suite测试集(测试套件)

    suite 这个表示测试集,不要放在class内,否则会提示"没有这样的测试方法在类里面 ",我觉得它唯一的好处就是调试的时候可以单独调试某个class而已,我一般不用它,调试时可 ...

  6. Linux系统——MySQL基础(一)

    # 数据库 ## 数据库简单的分类:(1)关系型数据库:MySQL和Oracle.Postgresql(2)非关系型数据库:Memcached和Redis(3)消息队列中间件(4)搜索引擎数据库:El ...

  7. Python之路----递归函数

    1.小练一下 用map来处理字符串列表,把列表中所有人都变成sb,比方alex_sb name=['alex','wupeiqi','yuanhao','nezha'] # def func(item ...

  8. C++提供了四个转换运算符

    const_cast <new_type> (expression) static_cast <new_type> (expression) reinterpret_cast ...

  9. JavaScript 方法扩展

    一.String全部替换方法 String.prototype.replaceAll = function(s1, s2){ return this.replace(new RegExp(s1, &q ...

  10. 分享三个USB抓包软件---Bus Hound,USBlyzer 和-USBTrace(转)

    源:分享三个USB抓包软件---Bus Hound,USBlyzer 和-USBTrace Bus Hound官方下载地址:http://perisoft.net/bushound/Bus Hound ...