Ask Your Question
0

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():
        create_map()
        rospy.spin()

def create_map( ):
    test_map = OccupancyGrid()
    test_map.info.resolution = 1.0 
    test_map.info.width = 10
    test_map.info.height = 10
    test_map.info.origin.position.x = 0.0 
    test_map.info.origin.position.y = 1.0 
    test_map.info.origin.position.z = 2.0 
    test_map.info.origin.orientation.x = 3.0 
    test_map.info.origin.orientation.y = 4.0 
    test_map.info.origin.orientation.z = 5.0 
    test_map.info.origin.orientation.w = 6.0 
    test_map.data = []
    for i in range(0, 100):
        test_map.data.append(i)
    print test_map
    map_pub = rospy.Publisher('/map', OccupancyGrid)
    map_pub.publish(test_map);
    return 

if __name__ == '__main__':
    try:
        map_stuff()
    except rospy.ROSInterruptException:
        pass

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

edit retag flag offensive close merge delete

Comments

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
0

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():
        create_map()
        rospy.spin()
edit flag offensive delete link more

Comments

1

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
1

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

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 2,019 times

Last updated: Apr 24 '20