I am using ROS and python and I have written this code. This code is supposed to subscribe to a ROS topic called "map" (coming from hector_slam using LIDAR) and save it into a variable called 'mapdata' which will be used later. I just want to make sure it is importing it correctly by publishing it as another ROS topic called 'mapprob'. The code compiles and runs fine, but nothing is published in 'mapprob'. I have made sure that "map" is publishing 'OccupancyGrid' messages and we want to extract the OccupancyGrid.data to use as 'mapdata'.
Any help will be appreciated.
Thanks,
CDS
#!/usr/bin/env python
import rospy
import sys
import time
import os
from nav_msgs.msg import OccupancyGrid
from nav_msgs.msg import MapMetaData
from std_msgs.msg import String
from std_msgs.msg import Float64
from std_msgs.msg import Int8MultiArray
def callback(OccupancyGrid):
# mapdata = Int8MultiArray()
mapdata.data = OccupancyGrid.data
def talker():
global mapdata
mapdata = Int8MultiArray()
pub = rospy.Publisher('mapprob', Int8MultiArray, queue_size=10)
rospy.init_node('talker', anonymous=True)
rospy.Subscriber("map", OccupancyGrid, callback)
# mapdata.data = OccupancyGrid.data
rospy.loginfo(mapdata)
pub.publish(mapdata)
rospy.spin()
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass