I want to publish a single /initialpose message when a node is run. How can I make sure it's only published once?
This is what I have:
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Pose, PoseWithCovarianceStamped
from std_msgs.msg import Header
from numpy import matrix
class PoseChange:
def __init__(self):
self.msg = PoseWithCovarianceStamped()
rospy.init_node("pose_change", anonymous=True)
rospy.Subscriber('/pose', Pose, self.callback)
self.pub = rospy.Publisher('/initialpose', PoseWithCovarianceStamped, queue_size=3)
def callback(self, data):
self.msg.header = Header()
self.msg.header.stamp = rospy.Time.now()
self.msg.header.frame_id = "map"
self.msg.pose.pose = data
self.msg.pose.covariance = matrix([[0.09, 0, 0, 0, 0, 0],
[0, 0.09, 0, 0, 0, 0],
[0, 0, 0.09, 0, 0, 0],
[0, 0, 0, 0.25, 0, 0],
[0, 0, 0, 0, 0.25, 0],
[0, 0, 0, 0, 0, 0.25]])
def run(self):
self.pub.publish(self.msg)
if __name__ == "__main__":
try:
m = PoseChange()
m.run()
except rospy.ROSInterruptException:
raise e
However, this never publishes when run. The /pose topic it's listening to is continuously publishing at 50 Hz.
Originally posted by j1337 on ROS Answers with karma: 25 on 2017-07-24
Post score: 1