• ros python 重置位置


    #!/usr/bin/env python
    import rospy
    import math
    import sys
    import commands
    import yaml
    from tf import transformations
    from geometry_msgs.msg import PoseWithCovarianceStamped
    class PoseSetter(rospy.SubscribeListener):
        def __init__(self, pose):
            self.pose = pose
        def peer_subscribe(self, topic_name, topic_publish, peer_publish):
            p = PoseWithCovarianceStamped()
            p.header.frame_id = "map"
            p.pose.pose.position.x = self.pose[0]
            p.pose.pose.position.y = self.pose[1]
            (p.pose.pose.orientation.x,
            p.pose.pose.orientation.y,
            p.pose.pose.orientation.z,
            p.pose.pose.orientation.w) = transformations.quaternion_from_euler(0, 0, self.pose[2])
            p.pose.covariance[6*0+0] = 0.5 * 0.5
            p.pose.covariance[6*1+1] = 0.5 * 0.5
            p.pose.covariance[6*3+3] = math.pi/12.0 * math.pi/12.0
            peer_publish(p)
            rospy.signal_shutdown("closed!")
    filenm="/opt/bp/tmp"
    sh="rostopic list|grep initialpose"
    globalmap="/opt/bp/maps/global_map.yaml"
    x=True
    with open(filenm, 'r') as f:
        content=f.read()
        if(content==""):
            with open(globalmap) as k:
                cmapyaml = yaml.load(k)
            with open("/opt/bp/maps/"+str(cmapyaml["hotelid"])+"/"+str(cmapyaml["floor"])+"/map.yaml") as j:
                mapyaml = yaml.load(j)
            pose=mapyaml["origin"]
        else:
            pose =map(float,content.split(","))
    while(1):
        if(commands.getstatusoutput(sh)[0]==0):
            break
    rospy.init_node('pose_setter', anonymous=True)
    if(x):
        pub=rospy.Publisher("initialpose", PoseWithCovarianceStamped,PoseSetter(pose),queue_size=10)
        x=False
    else:
        print("x=False")
    rospy.spin()

  • 相关阅读:
    RAID中条带的概念
    关于几个与IO相关的重要概念
    分布式调度
    ajax
    choices参数
    1.Python实现字符串反转的几种方法
    django web框架
    CRM总结
    Python面试重点(web篇)
    day02-网编并发数据库
  • 原文地址:https://www.cnblogs.com/sea-stream/p/10250171.html
Copyright © 2020-2023  润新知