# Translate/transform map.data to x,y coordinates to send to move_base

So I'm working on moving to a random location on the map while GMapper is running. So, I'm choosing a random int in map.data and making sure it's not unoccupied or explored. I then want to translate this position in the list to an x,y coordinate goal that I send to move base. Is there a transform or function that converts the map.data[point] into an X,Y coordinate? I know it's in row-major order, but because of the offset of the origin, there needs to be negative values as well.

Edit: Basically, I'm trying to get the robot to move to a randomly chosen, known area.

Edit2 : Thanks Lorenz,

It was this: x = map.map.info.origin.position.x + int(point%map.map.info.width) * map.map.info.resolution y = map.map.info.origin.position.y + int(point/map.map.info.width) * map.map.info.resolution

Width is not what I was expecting it to be.

Thanks

edit retag close merge delete

Thanks Lorenz. That should do it. I THOUGHT it was straight forward, but was not getting it right. I haven't tested it yet, but I think I was mixing up the order of ops with the resolution, as in adding the origin first then multiplying by the resolution.

The orientation shouldn't matter....

( 2012-07-12 05:11:52 -0500 )edit

Sorry. My bad. Of course it needs to be width and not height when calculating y. I updated my answer.

( 2012-07-12 07:45:27 -0500 )edit

Sort by » oldest newest most voted

Given the width, height and the origin of the map, it should be fairly trivial:

x = map.info.origin.position.x + (point % map.info.width) * map.info.resolution;
y = map.info.origin.position.y + static_cast<int>(point / map.info.width) * map.info.resolution;


Node that this discards the orientation of the origin. However, I haven't seen it used so far. If you want to have a really clean solution, you need to first calculate the x and y coordinates without taking into account the origin transform, put it into a pose and multiply the origin with that pose.

more