Ask Your Question

Revision history [back]

if __name__ == '__main__':
    rospy.init_node('distance_node')
    soundPub = rospy.Publisher('/distance', Range, queue_size=1)
    pub_range = Range()
    try:
        while True:

Well, this is an endless loop. That is why it won't shut down.

You'll want to check for an exit condition and break the loop.

A good exit condition when using rospy would be to see whether ROS has been requested to shutdown, so something like this would work:

while not rospy.is_shutdown():

For reference, see the Writing a Simple Publisher and Subscriber (Python) tutorial on the wiki.

if __name__ == '__main__':
    rospy.init_node('distance_node')
    soundPub = rospy.Publisher('/distance', Range, queue_size=1)
    pub_range = Range()
    try:
        while True:
            [..]
            time.sleep(1)

Well, this is an endless loop. That is why it won't shut down.

You'll want to check for an exit condition and break the loop.

A good exit condition when using rospy would be to see whether ROS has been requested to shutdown, so something like this would work:

while not rospy.is_shutdown():

For reference, see the Writing a Simple Publisher and Subscriber (Python) tutorial on the wiki.