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

点击 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

猜你喜欢

转载自blog.csdn.net/m0_37393277/article/details/79632836