0
$\begingroup$

Rosanswers logo

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


Original comments

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.

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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

$\endgroup$
0
$\begingroup$

Rosanswers logo

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

http://docs.ros.org/en/indigo/api/costmap_2d/html/classcostmap__2d_1_1Costmap2D.html#a061e2f97719abf41bc7c0426dad1c573


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

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by Paulidrobo on 2023-02-02:
It is not working like this. The value is always displaying 0. I think what @Mike mention might be true. Will try that.

Comment by mduz10 on 2023-03-01:
Hey Paul, I've tried to take costs with costmap_2d::Costmap2D::getCost but I couldn't. Which way is true to take the cost value of costmap?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.