Robotics StackExchange | Archived questions

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

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.

Asked by Redhwan on 2020-10-15 20:17:23 UTC

Comments

Answers

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.

Asked by JackB on 2020-10-15 23:41:12 UTC

Comments

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?

Asked by Redhwan on 2020-10-16 00:07:38 UTC

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.

Asked by JackB on 2020-10-16 08:42:23 UTC

Thank you for your tips @JackB.

Asked by Redhwan on 2020-10-16 08:45:55 UTC

Happy I could help! @Redhwan

Asked by JackB on 2020-10-16 09:23:24 UTC

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.

Asked by tryan on 2020-10-16 10:20:45 UTC