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

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

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

Luke_ROS gravatar image

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

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;
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

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

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 map.data with a raw array.

edit flag offensive delete link more

Comments

1

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 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 3,793 times

Last updated: Apr 28 '14