22from geometry_msgs.msg
import Pose
23from geometry_msgs.msg
import PoseArray
24from geometry_msgs.msg
import Quaternion
25from geometry_msgs.msg
import Vector3
26from tf.transformations
import euler_from_quaternion, quaternion_from_euler
46 def __init__(self, pub, element_attr, list_attr=''):
53 for attr
in attr_array:
54 if len(attr_list) == 0:
55 attr_list.append(getattr(data, attr))
57 attr_list.append(getattr(attr_list[-1], attr))
63 Normalize a 4 element array/list/numpy.array for use
as a quaternion
64 :param quat_array: 4 element list/array
65 :returns: normalized array
68 quat = np.array(array)
69 return quat / np.sqrt(np.dot(quat, quat))
72 orientation_list = [quat.x, quat.y, quat.z, quat.w]
73 orientation_list = self.
normalize(orientation_list)
74 (roll, pitch, yaw) = euler_from_quaternion (orientation_list, axes=
'sxyz')
75 vector_msg = Vector3()
84 pose_array_msg = PoseArray()
89 fake_pose.orientation = quat
90 pose_array_msg.poses.append(fake_pose)
92 self.
pub.publish(pose_array_msg)
97 pose_array_msg = PoseArray()
101 fake_pose.orientation = quat
102 pose_array_msg.poses.append(fake_pose)
104 self.
pub.publish(pose_array_msg)
109 rospy.init_node(
'extract_rpy_from_quat')
113 element_accessor = args[3]
115 pub = rospy.Publisher(out_topic, PoseArray, queue_size=10)
118 converter =
Converter(pub, element_accessor)
119 callback = converter.handle_individual
122 converter =
Converter(pub, element_accessor, args[4])
123 callback = converter.handle_list
126 msg_class, _, _ = rostopic.get_topic_class(in_topic,
True)
128 sub = rospy.Subscriber(in_topic, msg_class, callback)
131 while not rospy.is_shutdown():
135if __name__ ==
'__main__':
137 if (len(sys.argv) < 4
or len(sys.argv) > 5):
138 print(
'At one-two arguments required extract_rpy_from_quat <in topic> <out topic> <element path> <list path>')
141 except rospy.ROSInterruptException:
142 print(
"ROS Exception")