ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How can I publish an int8 array as a nav_msgs/OccupancyGrid?

asked 2014-04-28 03:22:35 -0600

Luke_ROS gravatar image

updated 2014-04-28 05:06:02 -0600

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: According to (cannot post link due to missing karma: 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; = 1.0;         // float32      = 2;           // uint32     = 2;           // uint32
int8_t a[4] = {100, 100, 50, 0};   // array of int8_t
std::cout << a << std::endl; = 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.


Following the hint, the code below worked for me.

int p[] = {100, 100, 50, 0};
std::vector<signed char> a(p, p+4); = a;
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2014-04-28 03:49:29 -0600

dornhege gravatar image

Check out the message fields description on how arrays are handled. The data[] is actually a std::vector, so you can't initialize with a raw array.

edit flag offensive delete link more



Perfect. That hint lead me back on the right track. I will post the working code below my original question.

Luke_ROS gravatar image Luke_ROS  ( 2014-04-28 05:03:43 -0600 )edit

Question Tools

1 follower


Asked: 2014-04-28 03:22:35 -0600

Seen: 3,714 times

Last updated: Apr 28 '14