Why did the pub before rospy.spin() not work?
I want to use Python to publish a topic before the spin. There is no problem with data printing, but there is no data in the echo outside, It can work in the callbacks.
self.pub_distance = rospy.Publisher('/path_distance',Int32,queue_size=10)
def run(self):
distance_ = Int32()
distance_.data = self.generate_path(0, self.path.keys()[-1])
print distance_ #Here's a value printed on the screen
self.pub_distance.publish(distance_) #But this doesn't work!!!
rospy.spin()
Too little info! Could you include your code?
already added.
rospy.spin()
is blocking and sets off the "event loop" (an "infinite while" if you will). How/where do you callrun()
?this code is my simple version,run() is running in main function.
I can understand spin(), but why did the pub is not working?
Did you solve this problem because i am facing with the same problem right now?
Two solutions, delay 1s before pub or make publish global (move out of class)