How to subscribe to an OccupancyGrid map and publish a converted array from it?
Hello everyone I'm trying to set up a frontier-navigation system in Gazebo.Now I am able to build the map using SLAM. Now I have come to the stage that I need to determine the frontier grids in the map and calculate some distances and utilities.I have noticed that the OccupancyGrid message holds only a 1 dimension array as stated in OG msg
In order to do further processing,I need to convert the 1 dimention data into a 2 dimention array(exactly like the real-time map). Now I'm trying to write a subscriber and publisher node.As I followed the tutorials I have written the following codes for simple test but it just doesn't work.
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
#include "nav_msgs/OccupancyGrid.h"
void mapConvert(const nav_msgs::OccupancyGrid::ConstPtr& msg)
{
ROS_INFO("I heard: [%d]",msg->info.width);
map_pub.publish(msg->info.width);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "map_converter");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("map", 1000, mapConvert);
ros::Publisher map_pub = n.advertise<int>("mapconverted", 1000);
ros::Rate loop_rate(10);
int count = 0;
while (ros::ok())
{
ros::spinOnce();
loop_rate.sleep();
}
ros::spin();
return 0;
}
and when I use catkin_make it shows
/home/edmond/rosws/src/myrobot_gazebo/src/mapconvert.cpp: In function ‘void mapConvert(const ConstPtr&)’:
/home/edmond/rosws/src/myrobot_gazebo/src/mapconvert.cpp:9:7: error: ‘map_pub’ was not declared in this scope
map_pub.publish(msg->info.width);
^
In file included from /opt/ros/indigo/include/ros/serialization.h:37:0,
from /opt/ros/indigo/include/ros/publisher.h:34,
from /opt/ros/indigo/include/ros/node_handle.h:32,
from /opt/ros/indigo/include/ros/ros.h:45,
from /home/edmond/rosws/src/myrobot_gazebo/src/mapconvert.cpp:1:
/opt/ros/indigo/include/ros/message_traits.h: In instantiation of ‘static const char* ros::message_traits::MD5Sum<M>::value() [with M = int]’:
/opt/ros/indigo/include/ros/message_traits.h:228:103: required from ‘const char* ros::message_traits::md5sum() [with M = int]’
/opt/ros/indigo/include/ros/advertise_options.h:92:40: required from ‘void ros::AdvertiseOptions::init(const string&, uint32_t, const SubscriberStatusCallback&, const SubscriberStatusCallback&) [with M = int; std::string = std::basic_string<char>; uint32_t = unsigned int; ros::SubscriberStatusCallback = boost::function<void(const ros::SingleSubscriberPublisher&)>]’
/opt/ros/indigo/include/ros/node_handle.h:239:7: required from ‘ros::Publisher ros::NodeHandle::advertise(const string&, uint32_t, bool) [with M = int; std::string = std::basic_string<char>; uint32_t = unsigned int]’
/home/edmond/rosws/src/myrobot_gazebo/src/mapconvert.cpp:17:69: required from here
/opt/ros/indigo/include/ros/message_traits.h:121:29: error: ‘__s_getMD5Sum’ is not a member of ‘int’
return M::__s_getMD5Sum().c_str();
^
/opt/ros/indigo/include/ros/message_traits.h: In instantiation of ‘static const char* ros::message_traits::DataType<M>::value() [with M = int]’:
/opt/ros/indigo/include/ros/message_traits.h:237:105: required from ‘const char* ros::message_traits::datatype() [with M = int]’
/opt/ros/indigo/include/ros/advertise_options.h:93:44: required from ‘void ros::AdvertiseOptions::init(const string&, uint32_t, const SubscriberStatusCallback&, const SubscriberStatusCallback&) [with M = int; std::string = std::basic_string<char>; uint32_t = unsigned int; ros::SubscriberStatusCallback = boost::function<void(const ros::SingleSubscriberPublisher&)>]’
/opt/ros/indigo/include/ros/node_handle.h:239:7: required from ‘ros::Publisher ros::NodeHandle::advertise(const string&, uint32_t, bool) [with M = int; std::string = std::basic_string<char>; uint32_t = unsigned int]’
/home/edmond/rosws/src/myrobot_gazebo/src/mapconvert.cpp:17:69: required from here
/opt/ros/indigo/include/ros/message_traits.h:138:31: error: ‘__s_getDataType’ is not a member of ‘int’
return M::__s_getDataType().c_str();
^
/opt/ros/indigo/include/ros/message_traits.h: In instantiation of ‘static const char* ros::message_traits::Definition<M>::value() [with M = int]’:
/opt/ros/indigo/include/ros/message_traits.h:246:107: required from ‘const char* ros::message_traits::definition() [with M = int]’
/opt/ros/indigo/include/ros/advertise_options.h:94:56: required from ‘void ros::AdvertiseOptions::init(const string&, uint32_t, const SubscriberStatusCallback&, const SubscriberStatusCallback&) [with M = int; std::string = std::basic_string<char>; uint32_t = unsigned int; ros::SubscriberStatusCallback = boost::function<void(const ros::SingleSubscriberPublisher&)>]’
/opt/ros/indigo/include/ros/node_handle.h:239:7: required from ‘ros::Publisher ros::NodeHandle::advertise(const string&, uint32_t, bool) [with M = int; std::string = std::basic_string<char>; uint32_t = unsigned int]’
/home/edmond/rosws/src/myrobot_gazebo/src/mapconvert.cpp:17:69: required from here
/opt/ros/indigo/include/ros/message_traits.h:155:40: error: ‘__s_getMessageDefinition’ is not a member of ‘int’
return M::__s_getMessageDefinition().c_str();
^
make[2]: *** [myrobot_gazebo/CMakeFiles/mapconvert.dir/src/mapconvert.cpp.o] error 1
make[1]: *** [myrobot_gazebo/CMakeFiles/mapconvert.dir/all] error 2
make: *** [all] error 2
Invoking "make -j4 -l4" failed
I have checked other questions but could not figure out how to solve this problem.Any help would be much appreciated! Thank You!
Asked by edmond320 on 2016-02-24 08:55:06 UTC
Comments