点击 Pose
要得到orientation中的x,y,z值
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import PoseStamped
#对应消息类型,导入后,获取x
def callback(pose):
rospy.loginfo('I heard %f',pose.pose.orientation.x)
def listener():
rospy.init_node('listener', anonymous=True)
pose=PoseStamped()
rospy.Subscriber('uav1/ground_truth_to_tf/pose', PoseStamped, callback)
# spin() simply keeps python from exiting until this node is stopped
rospy.spin()
if __name__ == '__main__':
listener()
如果是Python3环境,使用
#!/usr/bin/env python3