How can I publish an int8 array as a nav_msgs/OccupancyGrid?
Ultimately I would like to publish an Eigen matrix as a nav_msgs/OccupancyGrid. So I thought it would be a good idea to try first if I can publish an arbitrary int8 array as a map.
To my understanding, the map consists of an int8[] array (cannot post link due to missing karma: docs.ros.org/api/nav_msgs/html/msg/OccupancyGrid.html). According to (cannot post link due to missing karma: wiki.ros.org/msg#Fields)) an int8 is equivalent to an int8_t in C++. But the following simple code does not work and causes the error below (the code compiles without the last line). What am I missing here? Thanks a lot.
nav_msgs::OccupancyGrid map;
map.info.resolution = 1.0; // float32
map.info.width = 2; // uint32
map.info.height = 2; // uint32
int8_t a[4] = {100, 100, 50, 0}; // array of int8_t
std::cout << a << std::endl;
map.data = a;
Error by the compiler:
error: no match for ‘operator=’ in ‘map.nav_msgs::OccupancyGrid_<std::allocator<void> >::data = a’
If relevant: I use Hydro on an Ubuntu 12.04 LTS.
SOLUTION:
Following the hint, the code below worked for me.
int p[] = {100, 100, 50, 0};
std::vector<signed char> a(p, p+4);
map.data = a;