zoukankan      html  css  js  c++  java
  • python ros 关闭节点

    def myhook():
      print "shutdown time!"
    rospy.on_shutdown(myhook)


    rospy.signal_shutdown(reason)
    
    • 初始化节点关闭
    • reason 为关闭理由,字符串内容。

    例子:

    #!/usr/bin/env python
    import rospy
    import math
    import sys
    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()
            print("hh")
            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)
            print("ll")
            rospy.signal_shutdown("closed!")
    
    x=True
    print("dd")
    pose = [-9.983256,-2.641909,-1.201580]#x,y,a
    rospy.init_node('pose_setter', anonymous=True)
    if(x):
        print("tt")
        pub=rospy.Publisher("initialpose", PoseWithCovarianceStamped,PoseSetter(pose),queue_size=10)
        x=False
    else:
        print("x=False")
    print("ff")
    rospy.spin()
    print("pp")

  • 相关阅读:
    23种设计模式目录总览
    Unity3d优化总结2
    Unity3d优化总结1
    Unity四元数和旋转
    浅谈Unity中的GC以及优化
    Unity自带寻路Navmesh
    High-level NavMesh Building Components
    Unity3D的四种坐标系
    安装SQLserver2008r2出现 试图执行未经授权的操作
    C#获取上传文件的扩展名
  • 原文地址:https://www.cnblogs.com/sea-stream/p/10244234.html
Copyright © 2011-2022 走看看