ROS — creating .world file from existing .yaml

Ivan Gavran
3 min readMar 13, 2016

--

When I recently started with ROS I was amazed by the number of packages available and the possibilities they offer for quick start with robots. It shows a great power of community gathered around the idea. However, too often I ran into problems that were caused simply by gluing different parts of ROS together and a lack of (precise, understandable, newbie-friendly) tutorials. Let me describe one of these problems and the solution, so that my wandering through documentation, mailing lists and second pages of search results brings some benefit to the others.

Here is the situation: following a (great) tutorial on getting started with turtlebots, I created a map of my room (using a gmapping package). The result was two files: the image and the corresponding .yaml file.

image of my room as mapped by turtlebot (cropped)

Now I wanted to use it in Stage simulator to try out some other ideas. But stage simulator needs a description of the world in the .world file format. The question is: how to create a .world file that would correspond to .yaml file? (Having their coordinate systems aligned.)

.yaml file

Yaml file contains these fields:
- image: a (relative) link to image file
- resolution: resolution of the map, in meters per pixel (resolution of 0.05 for image of size 960x480 means that the map represents world of 48m x 24m)
- origin: origin gives coordinates (x, y, yaw) of lower-left point of image in coordinate system. the value [0, 0, 0] means that there is no rotation and that point (0,0) is in the lower-left point of image. Similarly, value [-24, -12,0] for the same image of size 960x240 would mean that the origin is in the centre of the image (because the lower-left point has coordinates (-24,-12))
- negate, occupied_thresh, free_thresh: values describing how to read intensities of black color in the map, more on that — here

.world file

.world file takes some other parameters (link). The coordinate system is defined in floorplan section. It contains these fields:
- bitmap: a link to the image created by gmapping
- size: size of map in meters — [x, y, z] (in our example, that would be [48, 24, 2], note that height is not important for aligning coordinate systems)
- pose: coordinates of the centre of the map (x, y, z, yaw), x, y, z again in meters. If in the .yaml file we chose [0,0,0] for the origin parameter, then pose should be [24,12,0,0].

a border

With .yaml and .world files defined like this, coordinate systems should be aligned. However, they are not! The reason is that Stage trims white portions of the map (setting the farthest black pixel of the image as the final point in the map) — link. In order to avoid it, it is good idea to place a thin black border around the map image (using image editor, gimp, for example)

Hopefully this post will be helpful to some readers. If you notice a mistake or that there was an easier way to accomplish the goal, let me know.

--

--