[Python] IMU test code
Basic code for the IMU test
Code
#! /usr/bin/env python
import rospy
from sensor_msgs.msg import Imu
from tf.transformations import euler_from_quaternion, quaternion_from_euler
import math
def callback(msg):
print('----')
print("[Quaternion]")
print(msg.orientation.x)
print(msg.orientation.y)
print(msg.orientation.z)
print(msg.orientation.w)
print('\n[Angular velocity]')
print(msg.angular_velocity.x)
print(msg.angular_velocity.y)
print(msg.angular_velocity.z)
print('\n[Linear Acceleration]')
print(msg.linear_acceleration.x)
print(msg.linear_acceleration.y)
print(msg.linear_acceleration.z)
print("\n[Euler]")
q = [msg.orientation.x, msg.orientation.y, msg.orientation.z, msg.orientation.w]
(roll, pitch, yaw) = euler_from_quaternion(q)
print(roll)
print(pitch)
print(yaw*180/math.pi)
count = 0
rospy.init_node('get_imu_data_node')
rate = rospy.Rate(10)
sub = rospy.Subscriber('imu_data', Imu, callback)
rospy.spin()
Leave a comment