python ros 订阅imu数据,实时显示欧拉角
#!/usr/bin/env python
# -*- coding: utf- -*-
import rospy
import math
from sensor_msgs.msg import Imu
from geometry_msgs.msg import Pose, Quaternion,PoseWithCovarianceStamped
import PyKDL def quat_to_angle(quat):
rot = PyKDL.Rotation.Quaternion(quat.x, quat.y, quat.z, quat.w)
return map(normalize_angle,rot.GetRPY()) def normalize_angle(angle):
res = angle
while res > math.pi:
res -= 2.0*math.pi
while res < -math.pi:
res += 2.0*math.pi
return res def callback(data):
#rpy
print(quat_to_angle(data.orientation))
#回调函数 收到的参数.data是通信的数据 默认通过这样的 def callback(data) 取出data.data数据 def getangle(orientation):
x=orientation.x
y=orientation.y
z=orientation.z
w=orientation.w f=*(w*y-z*z) r = math.atan2(*(w*x+y*z),-*(x*x+y*y))
p=
if(-<=f<=):
p = math.asin(f)
y = math.atan2(*(w*z+x*y),-*(z*z+y*y)) angleR = r*/math.pi
angleP = p*/math.pi
angleY = y*/math.pi return {"angleR":angleR,"angleP":angleP,"angleY":angleY} def listener(): # In ROS, nodes are uniquely named. If two nodes with the same
# node 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('listener', anonymous=True) #启动节点同时为节点命名, 若anoymous为真则节点会自动补充名字,实际名字以 listener_322345等表示
#若为假,则系统不会补充名字,采用用户命名。但是一次只能有一个同名节点,若后面有一个相同listener
#名字的节点则后面的节点启动会注销前面的相同节点名。 rospy.Subscriber("xxx_imu_driver/imu",Imu, callback)
#rospy.Subscriber("robot_pose",Pose, callback) #启动订阅,订阅主题,及标准字符串格式,同时调用回调函数,当有数据时调用函数,取出数据 # spin() simply keeps python from exiting until this node is stopped #循环程序
rospy.spin() if __name__ == '__main__':
listener()
#函数不被用作模块调用
python ros 订阅imu数据,实时显示欧拉角的更多相关文章
- 使用Python控制1602液晶屏实时显示时间(附PyCharm远程调试)
前言 原创文章,转载引用务必注明链接.水平有限,如有疏漏,欢迎指正. 本文介绍一下UP板的GPIO资源使用,以及一个使用Python演示一个简单的demo. 本文使用Markdown写成,为获得更好的 ...
- python ros 订阅robot_pose获取机器人位置
#!/usr/bin/env python import rospy import tf from tf.transformations import * from std_msgs.msg impo ...
- ROS在rviz中实时显示轨迹(nav_msgs/Path消息的使用)
消息结构说明nav_msgs/Path.msg结构#An array of poses that represents a Path for a robot to followHeader heade ...
- [转]ROS订阅激光数据
https://github.com/robopeak/rplidar_ros/blob/master/src/client.cpp /* * Copyright (c) 2014, RoboPe ...
- AngularJS checkbox/复选框 根据缓存数据实时显示
想缓存选择按钮时,可以使用这样的方法. index.html <!DOCTYPE html> <html data-ng-app="App"> <he ...
- 利用动态图层实现数据的实时显示(arcEngine IDynamiclayer)
marine 原文利用动态图层实现数据的实时显示(arcEngine IDynamiclayer) 说明:最近一个项目用到这方面知识,文章主要来至网络,后期会加入自己的开发心得.(以下的代码实例中,地 ...
- ROS实时采集Android的图像和IMU数据
前言 临近毕业,整理一下之前做的东西.这篇博客来自于博主在2016年3月份投的一篇会议论文(论文主要介绍了一个基于手机摄像头和IMU的简单VIO系统,用于AR的Tracking部分,本博文 ...
- python实现websocket服务器,可以在web实时显示远程服务器日志
一.开始的话 使用python简单的实现websocket服务器,可以在浏览器上实时显示远程服务器的日志信息. 之前做了一个web版的发布系统,但没实现在线看日志,每次发布版本后,都需要登录到服务器上 ...
- python websocket网页实时显示远程服务器日志信息
功能:用websocket技术,在运维工具的浏览器上实时显示远程服务器上的日志信息 一般我们在运维工具部署环境的时候,需要实时展现部署过程中的信息,或者在浏览器中实时显示程序日志给开发人员看.你还在用 ...
随机推荐
- 第一章 Java的IO演进之路
Unix中5种IO模型 就网络通信而言,一次数据读入可以分为两个阶段,首先等待数据从网络中到达,到达后需要复制到内核的缓冲区中,第二个阶段是从内核的缓冲区复制到进程的缓冲区,复制到进程的缓冲区才算读取 ...
- 在论坛中出现的比较难的sql问题:14(存储过程问题 存储过程参数、存储过程内的参数)
原文:在论坛中出现的比较难的sql问题:14(存储过程问题 存储过程参数.存储过程内的参数) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记解决的 ...
- WebApi 身份认 Basic基础认证
<body> <div style="text-align:center;"> <div>用户名:<input type="te ...
- win10+pyspark+pycharm+anaconda单机环境搭建
一.工具准备 1. jdk1.8 2. scala 3. anaconda3 4. spark-2.3.1-bin-hadoop2.7 5. hadoop-2.8.3 6. winutils 7. p ...
- 【转载】Sqlserver限制最大可使用内存
在Sqlserver的使用过程中,我们会发现随着运行时间的增长,Sqlserver占用的系统也越来越大,查了网上的相关资料说,Sqlserver在查询完相应数据后,为了下一次查询的性能,并不会马上释放 ...
- thinkphp5自动生成文档/注释代码自动生成api文档
composer require weiwei/api-doc dev-master 安装之后,readme 有详细的使用说明代码: 部分界面: gitbub:https://github.com/z ...
- Android笔记(四) Activity之间的数据传递
我们之前使用Intent进行Activity之间的跳转,其实Intent还可以在启动活动的时候传递数据. Intent提供了一系列的putExtra方法以便我们把想要传递的数据暂存在Intent中,待 ...
- 第二篇:Python基本知识
这一篇我们简单的介绍一下Python学习的基本知识-->Python文件是如何运行.Python文件打开通常会有两行注释,那么这两行注释是什么:上篇提到的字节码,这些字节码都存储在哪?即pyc文 ...
- tensor flow 线性回归
# -*- coding: utf-8 -*-"""Spyder Editor This is a temporary script file.tensor flow 之 ...
- pandas里面过滤列出现ValueError: cannot index with vector containing NA / NaN values错误的解决方法(转)
###df_18的字段fuek是否包含 / df_18[df_18['fuel'].str.contains('/')] 报错: ValueError Traceback (most recent c ...