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

Unable to output the costmap_2d occupancy grid array

asked 2021-04-10 04:57:58 -0600

updated 2021-04-10 04:58:42 -0600

Here's how my code looks -

costmap_2d::Costmap2DROS *global_costmap = new costmap_2d::Costmap2DROS("global_costmap", buffer);

I have specified the following params in my configuration file -

global_frame: odom
rolling_window: true
track_unknown_space: true

plugins:
  - {name: obstacles_laser,           type: "costmap_2d::ObstacleLayer"}
  - {name: inflation,                 type: "costmap_2d::InflationLayer"}

I am able to publish the occupancy grid using the terminal by running rostopic echo -n1 /global_costmap/costmap.

However, when I add the following line to my code -

unsigned char* global_og = global_costmap->getCostmap()->getCharMap() ; 

cout << global_og[10] << endl;

I see some strange characters being published.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-04-10 06:23:29 -0600

miura gravatar image

I think it shows the cost of the occupancy grid as a letter, not a number. I think you can solve this problem by casting it as a number.

example

unsigned char* global_og = global_costmap->getCostmap()->getCharMap() ;

cout << (int)global_og[10] << endl; // cast to int
edit flag offensive delete link more

Comments

1

Thank you!

skpro19 gravatar image skpro19  ( 2021-04-15 14:55:48 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2021-04-10 04:57:58 -0600

Seen: 154 times

Last updated: Apr 10 '21