Ask Your Question

How can I find the index of the cell from map coordinates ?

asked 2018-03-11 11:01:40 -0600

Developer gravatar image


I have the (x,y,z) position of the map. From that information, how can I find the cell index and also costmap value(free, obstacle ...) related to this coordinates ?


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2018-03-12 12:18:55 -0600

David Lu gravatar image
edit flag offensive delete link more


Hi David, I could not understand your solution proposal. Let me explain the case better. I have a position(x,y,z) of a map on Rviz. And from that position information, I want to first find related cell index(I m no sure, if gridcell or costmap).Than I want to change this cost value manually.

Developer gravatar imageDeveloper ( 2018-03-12 14:11:12 -0600 )edit

Do you have a Costmap2dROS object that you are manipulating in code?

David Lu gravatar imageDavid Lu ( 2018-03-13 16:38:37 -0600 )edit

No I don t have. I try to get the position of the related grid from the position of the interactive marker that I put on the Rviz (map). And change the value of this grid.

Developer gravatar imageDeveloper ( 2018-03-14 18:29:19 -0600 )edit

answered 2018-03-14 01:24:11 -0600

David is right , in detail , you can see the code in worldToMap below:

   * @brief  Given two map coordinates... compute the associated index
   * @param mx The x coordinate
   * @param my The y coordinate
   * @return The associated index
  inline unsigned int getIndex(unsigned int mx, unsigned int my) const
    return my * size_x_ + mx;
edit flag offensive delete link more


thanks man !

Developer gravatar imageDeveloper ( 2018-03-14 18:27:58 -0600 )edit

This only works if the unsigned ints are already in map coordinates. You first have to run worldToMap or the equivalent math operations

David Lu gravatar imageDavid Lu ( 2018-03-14 20:43:48 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-03-11 11:01:40 -0600

Seen: 289 times

Last updated: Mar 14 '18