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

How to find Xmin, Xmax, Ymin and Ymax after creating a map?

asked 2020-10-15 20:17:23 -0500

Redhwan gravatar image

I am trying to find Xmin, Xmax, Ymin and Ymax from the map in order to use them as constraints using python.

image description

Please your suggestion.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-10-15 23:41:12 -0500

JackB gravatar image

When you created the map, assuming you did it within ROS, it should have generated an image file (read: .png or .pgm), and a .yaml description file. In this description file, a parameter will be "resolution". That value is the size of the pixels in meters.

If you have access to the map image file, you can right click on it, and under the "properties" you can get the size pixels. If the picture is 50 pixels x 50 pixels and the resolution is 0.25m/pixel. Then the map is 12.5m X 12.5m.

Usually the convention is to specify the axis origin at the bottom left hand corner of the file and distances will be measured from there.

edit flag offensive delete link more


Thank you so much for your help. I created it within ROS in a long corridor and some rooms on both sides from the corridor. I see the picture is as the map.pgm and found (608 pixels x 1312 pixels). I also opened .yaml description file finding those information.

image: /home/map.pgm
resolution: 0.050000
origin: [-10.000000, -45.200000, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196

how to find them using python?

Redhwan gravatar image Redhwan  ( 2020-10-16 00:07:38 -0500 )edit

So I am not sure how Python can handle that information, but if I were you to start, I would hardcode the dimensions and resolution into some variables, or pass them as command line arguments.

JackB gravatar image JackB  ( 2020-10-16 08:42:23 -0500 )edit

Thank you for your tips @JackB.

Redhwan gravatar image Redhwan  ( 2020-10-16 08:45:55 -0500 )edit

Happy I could help! @Redhwan

JackB gravatar image JackB  ( 2020-10-16 09:23:24 -0500 )edit

If you're trying to read the parameters from a file, I would use PyYAML to load it. If you're trying to use the parameters in real time, I would write a node to listen to the map topic (assuming that's where this comes from) as that meta data is also contained in an OccupancyGrid message.

tryan gravatar image tryan  ( 2020-10-16 10:20:45 -0500 )edit

Question Tools



Asked: 2020-10-15 20:17:23 -0500

Seen: 462 times

Last updated: Oct 15 '20