물체의 orientation을 표기하는 방법
#!/usr/bin/env python from tf.transformations import euler_from_quaternion, quaternion_from_euler q = quaternion_from_euler(1, 1, 1) print(q) e = euler_from_quaternion(q) print(e)
jsg@jsg-ubuntu:~/xycar_ws/src/my_imu/src$ python transform.py [ 0.16751879 0.57094147 0.16751879 0.78606663] (1.0000000000000004, 1.0, 1.0000000000000007)
jsg@jsg-ubuntu:~$ rosmsg show sensor_msgs/Imu std_msgs/Header header uint32 seq time stamp string frame_id geometry_msgs/Quaternion orientation float64 x float64 y float64 z float64 w float64[9] orientation_covariance geometry_msgs/Vector3 angular_velocity float64 x float64 y float64 z float64[9] angular_velocity_covariance geometry_msgs/Vector3 linear_acceleration float64 x float64 y float64 z float64[9] linear_acceleration_covariance
#!/usr/bin/env python import rospy import time from sensor_msgs.msg import Imu from tf.transformations import euler_from_quaternion Imu_msg = None def imu_callback(data): global Imu_msg Imu_msg = [data.orientation.x, data.orientation.y, data.orientation.z, data.orientation.w] rospy.init_node("Imu_Print") rospy.Subscriber("imu", Imu, imu_callback) while not rospy.is_shutdown(): if Imu_msg == None: continue (roll, pitch, yaw) = euler_from_quaternion(Imu_msg) print('Roll:%.4f, Pitch:%.4f, Yaw:%.4f' % (roll, pitch, yaw)) time.sleep(0.5)
<launch> <node pkg="xycar_imu" type="9dof_imu_node.py" name="xycar_imu" output="screen"> <param name="rviz_mode" type="string" value="false" /> </node> <node pkg="my_imu" type="roll_pitch_yaw.py" name="Imu_Print" output="screen" /> </launch>
rviz_imu_plugin 설치 : http://wiki.ros.org/rviz_imu_plugin
launch파일에 rviz 추가
<launch> <!-- rviz display --> <node name="rviz_visualizer" pkg="rviz" type="rviz" required="true" args="-d $(find rviz_imu)/rviz/imu_3d.rviz"/> <node pkg="xycar_imu" type="9dof_imu_node.py" name="xycar_imu" output="screen"> <param name="rviz_mode" type="string" value="false" /> </node> </launch>