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

Get cost value of a point in local costmap

asked 2022-01-01 23:49:57 -0500

N.N.Huy gravatar image

updated 2022-01-01 23:50:59 -0500

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 !

edit retag flag offensive close merge delete

Comments

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?

N.N.Huy gravatar image N.N.Huy  ( 2022-01-04 02:49:36 -0500 )edit

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.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-01-04 08:46:14 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-01-02 09:28:17 -0500

Mike Scheutzow gravatar image

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.

edit flag offensive delete link more
1

answered 2022-01-02 07:45:56 -0500

osilva gravatar image

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/cos...

edit flag offensive delete link more

Comments

It is not working like this. The value is always displaying 0. I think what @Mike mention might be true. Will try that.

Paulidrobo gravatar image Paulidrobo  ( 2023-02-02 05:27:31 -0500 )edit

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?

mduz10 gravatar image mduz10  ( 2023-03-01 01:48:08 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-01-01 23:49:57 -0500

Seen: 615 times

Last updated: Jan 02 '22