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

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

asked 2012-07-12 04:36:01 -0500

IFLORbot gravatar image

updated 2012-07-12 07:43:41 -0500

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 flag offensive close merge delete

Comments

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....

IFLORbot gravatar image IFLORbot  ( 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.

Lorenz gravatar image Lorenz  ( 2012-07-12 07:45:27 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-07-12 04:47:25 -0500

Lorenz gravatar image

updated 2012-07-12 07:45:47 -0500

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.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-07-12 04:36:01 -0500

Seen: 684 times

Last updated: Jul 12 '12