How to identify the origin of a map

Hi,

The notebook write that: the origin is lower-left of image.

But how to identify where is the lower-left?

Thank

Hi @NguyenDuyDuc ,

The best way is to look at the yaml file that gets generated along with the map that you create.
That file has the origin coordinates. It is not easy to find the origin on a map image without external parameters. It can be done, but it won’t be exact.

Let me know if you still need more information.

Regards,
Girish

Could you explain more?

For example, I have a yaml file and a pgm file.
How to identify the position of origin of yaml file in image(pgm file)?

Hi @NguyenDuyDuc,

As I understand, you asked this:
Which byte in the pgm file is the bottom-left pixel on the map image?

This is an interesting question.

I think, that the origin of the map file is the bottom-left corner of the map image.
To find this point in the PGM file, lets open the PGM file in a text editor.
Here is the first 3 lines:

P5 [This is the magic number for PGM images]
55 50 [width and height in decimal] 
255 [Maximum grey value. Because this is less than 256, every pixel will be one byte in the next row]
[Here are strange characters, these are the grey values of every pixel. Every byte is one pixel]

The bytes of the image are stored in the 4th line of the file.
The first byte in this line is the top-left corner of the image.
The second byte in this line is the second pixel from the left in the first row.
The 55th byte in this line is the top-right pixel
The 56th byte is the left pixel in the second row.
Etc.
The pixel in the [row, column] coordinate (where row:[0…49] and column is [0…54] is in the position of
(row*55+column + 1), if you count the bytes from 1 not 0 in the line.

So the bottom-left corner of the map image is in the 49*55+1=2696 position of the line.
Or maybe I counted badly, so try to add ±1.

Here is an example of an 5x3 image where the "~’ represents the bottom-left corner:

P5
5 3
255
!!!!!!!!!!~!!!!

This is based on these infos:

https://netpbm.sourceforge.net/doc/pgm.html

PĂ©ter

1 Like

My case is:

I need my robot move to dock and undock. So I need its coordinate on the map.
Could I choose a point on the map then calculate the coordinate?

What would you do? Could you share your experience?

Dear @NguyenDuyDuc ,

There is a docking example in the course TF ROS2, especially in unit 5.

Please consider these in the future:

When you ask for help, it is better to start with your real problem (like “I can not dock-undock”).
Then it is helpful if you describe where exactly did you stuck and what did you do so far.
Also can be helpful if you describe what solving options did you try.
Use the “</>” button when providing code.
When you have an answer, please, click on the “Solution” button on the most helpful answer. (but do not forget to thank you for the others)

Regards
PĂ©ter

1 Like

I understood.

I will explain more:

  • I scaned a map
  • So now, I have a map but I want to have coordinates of points on the map to program my robot to move these points to dock and undock. But I don’t know how to calculate the coordinates of these points on the map?

Do you have any solution for that?

Thanks

Hi,

I think, that the easies way with rviz2.
Create a map_server and add your map into its config directory and you can check the coordinates with rviz2.
Click the “publish point” button of rviz2, then click onto the map and you will see in the log of rviz2 the coordinates of your clicked point.

PĂ©ter

1 Like

Hi,

I think, that I do not udnerstand your question.
But let say, that you want to have coordinates of a point on a scanned image.

I may do this:

  1. convert the scanned image to a ros2 map
  2. put this ros2 map into the config dir of a map_server
  3. run map server and rviz
  4. Use “publish button” to have the coordinates

Now I think, you stuck at the first step: Converting a scanned image to a ros2 map.
I may do this:

  1. With some software, I convert this image to grayscal with 256 levels
  2. Save the converted image as a PGM file as “my_map.pgm”
  3. Create a “my_map.pgm” yaml file:
image: my_map.pgm
mode: trinary
resolution: 0.05
origin: [-1.27, -1.83, 0]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.25

This map will not be right scaling. If you have the coordinates with this map, we can do the scaling also.

PĂ©ter

1 Like

I am using ROS1 now.

Can ROS1 use RVIZ2?

Dear @NguyenDuyDuc

I do not know. Maybe RVIZ is enough.

PĂ©ter

No, it can’t. The command to launch RViz in ROS 1 is:

rviz

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.