3 Node to convert from quaternions to rpy in various ROS messages 8 from geometry_msgs.msg
import Vector3
9 from geometry_msgs.msg
import Pose
10 from geometry_msgs.msg
import PoseArray
11 from sensor_msgs.msg
import Imu
12 from gazebo_msgs.msg
import ModelStates
13 from nav_msgs.msg
import Odometry
16 def __init__(self,pose_index=None,model_name=None,
17 input_msg_type=
'Pose'):
27 if (
not (pose_index==
None)):
28 data = data[pose_index]
31 index = data.name.index(model_name)
33 rospy.logwarn_throttle(10.0,
'Model state {} not found'.format(model_name))
35 data = data.pose[index]
42 rospy.logerr(
"Don't know what to do with message type %s"%
45 q = (data.orientation.x,
49 euler = tf.transformations.euler_from_quaternion(q)
50 self.pubmsg.x = euler[0]
51 self.pubmsg.y = euler[1]
52 self.pubmsg.z = euler[2]
53 rospy.logdebug(
"publishing rpy: %.2f, %.2f, %.2f" 54 %(euler[0],euler[1],euler[2]))
55 self.pub.publish(self.
pubmsg)
57 if __name__ ==
'__main__':
59 rospy.init_node(
'quat2rpy', anonymous=
True)
63 out_topic =
'out_topic' 64 pose_index = rospy.get_param(
'~pose_index',
None)
65 model_name = rospy.get_param(
'~model_name',
None)
66 inmsgtype = rospy.get_param(
'~input_msg_type',
'Pose')
70 node=
Node(pose_index, model_name, input_msg_type=inmsgtype)
74 node.pub = rospy.Publisher(out_topic,Vector3,queue_size=10)
77 if (not(model_name ==
None)):
78 inmsgtype =
'ModelStates[%s]'% model_name
79 rospy.Subscriber(in_topic,ModelStates,node.callback)
80 elif (
not (pose_index ==
None)):
81 inmsgtype =
'PoseArray[%d]'%pose_index
83 rospy.Subscriber(in_topic,PoseArray,node.callback)
85 if inmsgtype ==
'Pose':
87 rospy.Subscriber(in_topic,Pose,node.callback)
88 elif inmsgtype ==
'Imu':
89 rospy.Subscriber(in_topic,Imu,node.callback)
90 elif inmsgtype ==
'Odometry':
91 rospy.Subscriber(in_topic,Odometry,node.callback)
93 rospy.logerr(
"I don't know how to deal with message type <%s>"%
98 rospy.loginfo(
"Subscribing to %s, looking for %s messages."%
101 rospy.loginfo(
"Publishing to %s, sending Vector3 messages"%
108 except rospy.ROSInterruptException:
def __init__(self, pose_index=None, model_name=None, input_msg_type='Pose')