zoukankan      html  css  js  c++  java
  • 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()

  • 相关阅读:
    【linux系列】配置免密登陆
    【linux系列】centos安装vsftp
    【linux系列】cenos7安装jdk
    MySQL DATE_SUB()
    Java基本数据类型
    Gson使用中遇到的Date格式问题
    数组中存放对象之java中定义类数组存放类
    获取X天后的日期
    sql统计总和和各状态数
    HttpServletRequest获取URL?后面的内容
  • 原文地址:https://www.cnblogs.com/sea-stream/p/10250171.html
Copyright © 2011-2022 走看看