用Python编写ROS中的订阅和发布,导入消息类型问题

用Python编写ROS中的订阅和发布,导入消息类型问题_第1张图片

点击 Pose

用Python编写ROS中的订阅和发布,导入消息类型问题_第2张图片

要得到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

你可能感兴趣的:(ROS)