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[]
p.pose.pose.position.y = self.pose[]
(p.pose.pose.orientation.x,
p.pose.pose.orientation.y,
p.pose.pose.orientation.z,
p.pose.pose.orientation.w) = transformations.quaternion_from_euler(, , self.pose[])
p.pose.covariance[*+] = 0.5 * 0.5
p.pose.covariance[*+] = 0.5 * 0.5
p.pose.covariance[*+] = 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=)
x=False
else:
print("x=False")
print("ff")
rospy.spin()
print("pp")