
header: 消息头,包含序列号、时间戳和坐标系等信息。orientation: IMU 的当前朝向,用四元数表示,包括 $x, y, z$ 和 $w$ 四个值。orientation_covariance: 朝向协方差矩阵,包含 $9$ 个元素,描述 IMU 测量的朝向误差。angular_velocity: IMU 的角速度,包含 $x, y, z$ 三个分量。angular_velocity_covariance: 角速度协方差矩阵,包含 $9$ 个元素,描述 IMU 测量的角速度误差。linear_acceleration: IMU 的线性加速度,包含 $x, y, z$ 三个分量。linear_acceleration_covariance: 线性加速度协方差矩阵,包含 $9$ 个元素,描述 IMU 测量的线性加速度误差。
使用话题获得imu的欧拉角
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import Imu
from tf.transformations import euler_from_quaternion
def imu_callback(msg):
# 从 IMU 数据中获取四元数
orientation_q = msg.orientation
# 将四元数转换为欧拉角
(roll, pitch, yaw) = euler_from_quaternion([orientation_q.x, orientation_q.y, orientation_q.z, orientation_q.w])
# 输出欧拉角信息
print('Roll: %.2f, Pitch: %.2f, Yaw: %.2f' % (roll, pitch, yaw))
if __name__ == '__main__':
# 创建 ROS 节点和订阅 IMU 话题
rospy.init_node('imu_subscriber')
rospy.Subscriber('/imu_topic', Imu, imu_callback)
# 循环等待回调函数
rospy.spin()

浙公网安备 33010602011771号