Ask Your Question

help with simple /map publisher that will not publish - python

asked 2014-02-01 09:41:19 -0500

david.c.liebman gravatar image

updated 2016-10-24 08:35:41 -0500

ngrennan gravatar image

How do I publish this test data to the /map topic. I would like to use this routine to test other things I'm working on. I think I'm doing it right but when I type 'rostopic echo /map' I see nothing. If I run the script at the command prompt after typing 'roscore' in another terminal I see the test OccupancyGrid on the screen. I don't know what I'm doing wrong.

#!/usr/bin/env python

import rospy
import sys

from nav_msgs.msg import *
from std_msgs.msg import *

def map_stuff():
    rospy.init_node('turtlebot_map', anonymous=True)
    if not rospy.is_shutdown():

def create_map( ):
    test_map = OccupancyGrid() = 1.0 = 10 = 10 = 0.0 = 1.0 = 2.0 = 3.0 = 4.0 = 5.0 = 6.0 = []
    for i in range(0, 100):
    print test_map
    map_pub = rospy.Publisher('/map', OccupancyGrid)

if __name__ == '__main__':
    except rospy.ROSInterruptException:

I followed online tutorials as closely as I could. Any help would be appreciated.

edit retag flag offensive close merge delete


You can help me build my map, it is not working?

Higor gravatar image Higor  ( 2020-04-24 08:01:02 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2014-02-01 15:56:03 -0500

updated 2014-02-02 02:20:13 -0500

You are publishing just once in create_map(). Try these changes:

def map_stuff():
     global map_pub
     map_pub = rospy.Publisher('/map', OccupancyGrid) # remove this line from create_map()
     rospy.init_node('turtlebot_map', anonymous=True)
     while not rospy.is_shutdown():
edit flag offensive delete link more



this will work if you make map_pub global somehow. You're right, the thing is I'm doing it just once in my code. If I publish it repeatedly (not sure if that's a good idea) then you can see it on 'rostopic echo /map'...

david.c.liebman gravatar image david.c.liebman  ( 2014-02-02 02:12:47 -0500 )edit

Sorry, I forgot global label. Why do you think that publish repeatedly could be a bad idea? Maybe you want a service instead a topic? or have you tried map_server?

gustavo.velascoh gravatar image gustavo.velascoh  ( 2014-02-02 02:21:59 -0500 )edit

I added a line that reads like

map_pub = rospy.Publisher('/map', OccupancyGrid, latch=True)
and it seems to work better. Hopefully this will help me. Thanks for your help!!

david.c.liebman gravatar image david.c.liebman  ( 2014-02-02 10:06:49 -0500 )edit

Your Answer


Add Answer

Question Tools

1 follower


Asked: 2014-02-01 09:41:19 -0500

Seen: 2,019 times

Last updated: Apr 24 '20