ROS中四元素欧拉角变换
来源:互联网 发布:iphone翻墙用什么软件 编辑:程序博客网 时间:2024/05/22 12:11
python版本
#my_pkg/msg/Eulers.msg类型Header headerfloat64 rollfloat64 pitchfloat64 yaw#my_pkg/quat_to_euler.py文件#!/usr/bin/python# -*- coding: utf-8 -*-# Start up ROS pieces.PKG = 'my_pkg'import roslib; roslib.load_manifest(PKG)import rospyimport tf# ROS messages.from nav_msgs.msg import Odometryfrom sensor_msgs.msg import Imufrom my_pkg.msg import Eulersclass QuatToEuler(): def __init__(self): self.got_new_msg = False self.euler_msg = Eulers() # Create subscribers and publishers. sub_imu = rospy.Subscriber("imu", Imu, self.imu_callback) sub_odom = rospy.Subscriber("odom", Odometry, self.odom_callback) pub_euler = rospy.Publisher("euler", Eulers) # Main while loop. while not rospy.is_shutdown(): # Publish new data if we got a new message. if self.got_new_msg: pub_euler.publish(self.euler_msg) self.got_new_msg = False # Odometry callback function. def odom_callback(self, msg): # Convert quaternions to Euler angles. (r, p, y) = tf.transformations.euler_from_quaternion([msg.pose.pose.orientation.x, msg.pose.pose.orientation.y, msg.pose.pose.orientation.z, msg.pose.pose.orientation.w]) self.fill_euler_msg(msg, r, p, y) # IMU callback function. def imu_callback(self, msg): # Convert quaternions to Euler angles. (r, p, y) = tf.transformations.euler_from_quaternion([msg.orientation.x, msg.orientation.y, msg.orientation.z, msg.orientation.w]) self.fill_euler_msg(msg, r, p, y) # Fill in Euler angle message. def fill_euler_msg(self, msg, r, p, y): self.got_new_msg = True self.euler_msg.header.stamp = msg.header.stamp self.euler_msg.roll = r self.euler_msg.pitch = p self.euler_msg.yaw = y# Main function. if __name__ == '__main__': # Initialize the node and name it. rospy.init_node('quat_to_euler') # Go to class functions that do all the heavy lifting. Do error checking. try: quat_to_euler = QuatToEuler() except rospy.ROSInterruptException: pass
#launch 文件<node pkg="my_pkg" type="quat_to_euler.py" name="imu_euler_angles"> <remap from="imu" to="microstrain/data"/> <remap from="euler" to="microstrain/euler"/></node><node pkg="my_pkg" type="quat_to_euler.py" name="kf_euler_angles"> <remap from="odom" to="kf/odom"/> <remap from="euler" to="kf/euler"/></node>
#运行rxplot /microstrain/euler/roll:/kf/euler/roll
C++版本
/****************************************************************************Conversion from a quaternion to roll, pitch and yaw.Nodes:subscribed /rotation_quaternion (message of type geometry_msgs::Quaternion)published /rpy_angles (message oftype geometry_msgs::Vector3.h)****************************************************************************/#include "ros/ros.h"#include "geometry_msgs/Vector3.h"#include "geometry_msgs/Quaternion.h"#include "tf/transform_datatypes.h"#include "LinearMath/btMatrix3x3.h"// Here I use global publisher and subscriber, since I want to access the// publisher in the function MsgCallback:ros::Publisher rpy_publisher;ros::Subscriber quat_subscriber;// Function for conversion of quaternion to roll pitch and yaw. The angles// are published here too.void MsgCallback(const geometry_msgs::Quaternion msg){ // the incoming geometry_msgs::Quaternion is transformed to a tf::Quaterion tf::Quaternion quat; tf::quaternionMsgToTF(msg, quat); // the tf::Quaternion has a method to acess roll pitch and yaw double roll, pitch, yaw; tf::Matrix3x3(quat).getRPY(roll, pitch, yaw); // the found angles are written in a geometry_msgs::Vector3 geometry_msgs::Vector3 rpy; rpy.x = roll; rpy.y = pitch; rpy.z = yaw; // this Vector is then published: rpy_publisher.publish(rpy); ROS_INFO("published rpy angles: roll=%f pitch=%f yaw=%f", rpy.x, rpy.y, rpy.z);}int main(int argc, char **argv){ ros::init(argc, argv, "talker"); ros::NodeHandle n; rpy_publisher = n.advertise<geometry_msgs::Vector3>("rpy_angles", 1000); quat_subscriber = n.subscribe("rotation_quaternion", 1000, MsgCallback); // check for incoming quaternions untill ctrl+c is pressed ROS_INFO("waiting for quaternion"); ros::spin(); return 0;}
参考文档:
ROS论坛
阅读全文
0 0
- ROS中四元素欧拉角变换
- (四)ROS坐标变换可视化(示例运行)
- 《ROS精品入门》学习笔记四:ROS中的空间描述与变换
- ROS的tf包中坐标变换的方法
- ROS的tf包中坐标变换的方法
- ROS之tf坐标变换
- (四)理解ROS topics
- android.graphics四、Android中图像变换Matrix的原理
- 视觉SLAM——第三章 Eigen几何模块Geometry使用 四元素 欧式变换矩阵
- 矩阵元素变换
- 共享元素变换
- -webkit-transform(元素变换)
- ROS学习--(四)创建ROS Package
- ROS学习笔记四:理解ROS节点
- ROS Gazebo(四):ROS Control
- ROS教程(四):编译ROS程序包
- ROS学习笔记(四):ROS主题
- ROS专题----tf和tf2坐标变换
- 头条项目总结
- linux jdk1.8
- Linux上定时任务发布及锁定(1)
- Insert into a Cyclic Sorted List
- Air系列模块驱动lcd显示
- ROS中四元素欧拉角变换
- 类型别名
- JavaShowAlgorithm-Median of Two Sorted Arrays
- 深度学习-note-RNN(循环神经网络)
- python 中 os 和 sys 的区别和联系
- 第二章 SQL命令参考-ROLLBACK
- 属性getter和setter
- 2017双十一阿里技术汇总
- C语言实验——整数位