# Get cost value of a point in local costmap

Hi everyone, I want to get cost value of a specific point in local costmap. For example, i have a point and the position of this point is taken relative to map tf frame. Can you tell me how to check cost value of the point in local costmap of robot ?

Thank you and happy new year !

Originally posted by N.N.Huy on ROS Answers with karma: 32 on 2022-01-02

Post score: 0

Comment by N.N.Huy on 2022-01-04:
Nice, thank you @Mike Scheutzow and @Osilva for your explanations. So I understand as the following steps:

1. I have to subscribe the /move_base/local_costmap/costmap
2. Then I have to transform the frame of the input coordination to the frame of costmap right ? Because my input is a coordination of map tf frame, but in the local costmap, I think it uses robot fame or something else, i am not sure.
3. Then I can use getCost() function as @osilva said.

So is the procedure I said above right ? And how can I do the transformation ? Can I use worldtomap to do the transformation?

Comment by Mike Scheutzow on 2022-01-04:
Take a look at the nav_msgs/OccupancyGrid message. It has all the info you need to calculate an index into the cell grid. (0,0) is the lower left corner of the grid. Since each cell value is an int8, cost probably scaled down to range 0-100 - you should verify that.

move_base should be publishing the latest values on a topic named /move_base/local_costmap/costmap. Your ros node should subscribe to this topic.

I would not use costmap_2d class to monitor this data. It is mainly used to create a costmap and apply sensor updates to that costmap.

Originally posted by Mike Scheutzow with karma: 4903 on 2022-01-02

This answer was ACCEPTED on the original site

Post score: 1

Hi @N.N.Huy you could access the cost from a specific cell using getCost() function:

unsigned char costmap_2d::Costmap2D::getCost (unsigned int mx, unsigned int my )    const


Get the cost of a cell in the costmap:

Parameters:

mx: The x coordinate of the cell

my: The y coordinate of the cell

Returns: The cost of the cell

Originally posted by osilva with karma: 1650 on 2022-01-02

This answer was NOT ACCEPTED on the original site

Post score: 1