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

wrong map position

asked 2021-08-07 13:39:39 -0500

dinesh gravatar image

updated 2021-08-08 02:10:48 -0500

I am using the map file generated by the hector slam in qt quick applicatino. Here when i click on the map location the x coordintates are accurate but the y value are not comming accurate. The forumula i'm using is:

        onPressed: {
            fnameFieldX.text = point1.x * resolution-map_origin.x
            fnameFieldY.text = point1.y * resolution-map_origin.y

For example when i press at center i.e 0,0 location of popular turtlebot3 world map. The x,y data is comming as: 0.04,0.9. image description

Here the orign is 10,10 and resolution is 0.05 acording to map.yaml file.

image: ./map.pgm
resolution: 0.050000
origin: [-10.000000, -10.000000, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196
edit retag flag offensive close merge delete


In this map 384x384 pixel and if you calculate your map dimensions 384x0.05 = 19.2 meter

bekirbostanci gravatar image bekirbostanci  ( 2021-08-07 16:31:46 -0500 )edit

What are the point.x and point.y values when you press the upper left corner? What are the point.x and point.y values when you press the bottom right corner?

bekirbostanci gravatar image bekirbostanci  ( 2021-08-08 03:19:56 -0500 )edit

Its 0,0 as expected. Their is no problem in pixel position as i confirmed. eg. If i click on bottom right corner the x and y coms as the height and widht of the image itself.

dinesh gravatar image dinesh  ( 2021-08-08 07:10:48 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-08-08 14:52:25 -0500

image description

If you look the gray area at the right bottom corner is -10,-10 and the center is also looks like 0,0 this coordinate system is cartesian coordinate system. In this system maps x values increase from left to right and and y values increase from bottom to top. Generally mobile and web application coordinate system is little bit different. In that type of applications origin point accepted left top point and y axis value is increase from top to bottom.

So that you can calculate your click position on the map with this formula

  • x = click.x(px)*map_resolution(meter/px) + origin.x(meter)
  • y = (map.height(px) - click.y(px))*map_resolution(meter/px) + origin.y(meter)

If we make a check - Our click position (200,184)(px) (this is center point on this map you can check it with paint or other app) our map size (384,384)(px) and origin (-10,-10)(meter) and resolution 0.05

  • x (200*0.05) + (-10) = 0
  • y = ((384-184)*0.05) + (-10) = 0

I hope that has been revealing

edit flag offensive delete link more

Question Tools



Asked: 2021-08-07 13:39:39 -0500

Seen: 237 times

Last updated: Aug 08 '21