MRC/Tutorials/Using a custom simulator map

From Control Systems Technology Group
Jump to navigation Jump to search

By default, the simulator loads an indoor environment. Fortunately, you can change the simulation environment very easily! You just have to create a heightmap: an image that specifies for each pixel how 'high' the world has to be at that point. Since the laser only scans at one height, we can use two extremes here: flat (ground level) or high enough to be detected by the laser.

To create an image, simply open your favourite image editor and create a black-and-white image. If you don't know how to create an image, have a look at the section below. White corresponds to the floor, black to the walls (i.e., which will be detected by the laser). You have to keep the following things in mind:

The robot always starts in the center of the image. So, if you want to robot to start at the edge of your maze / corridor, just create a bigger image and move the black pixels to the upper part of the image.

You'll get the best result if the lines drawn are at least 2 pixels wide. Store your image lossless, i.e. using the png format (which is recommended by the way!), instead of the jpg format.

We will also need to create a file with meta information. An example is shown below

image: <YOUR_IMAGE_FILE>.png

resolution: 0.025

origin: [0.0, 0.0, -1.570796]

occupied_thresh: 0.9

free_thresh: 0.1

negate: 0

Here we specify how the computer should interpret our heightmap. This is a .yaml file with the following fields.

- image: Path to the image file containing the occupancy data; can be absolute, or relative to the location of the YAML file

- resolution: Resolution of the map, meters / pixel

- origin: The 2-D pose of the lower-left pixel in the map, as (x, y, yaw), with yaw as counterclockwise rotation (yaw=0 means no rotation). This parameter only affects visualization.

- occupied_thresh, free_thresh, negate: these parameters are currently unused by the simulator but they are part of the standard map metadata.

Once you have created an image, simply run the simulator and provide the yaml file as argument:

mrc-sim --map ./relative/path/to/<YOUR_METADATA_FILE>.yaml

That's it!

Create a heightmap image

There are many linux applications that you use to create images. We suggest using Gimp, an open-source alternative to Photoshop. Although it might be a bit overkill to use for our application, it has great support and the thing we want to do (draw black lines on a white background) isn't hard. To install Gimp, run:

sudo apt-get install gimp

And run it using:

gimp

Then to create a simple image:

  • Select File -> New (or ctrl-N)
  • Specify the size of your image. Remember, 40 pixels = 1 meter, and the robot starts in the center
  • Select the Pencil Tool. (left click on the paintbrush tool, or press 'N' on your keyboard)
  • Set the pencil size in the lower left pane to something sensible, e.g. 2 pixel

Now, if you click left on the image, a dot is drawn, but we want lines! To draw a line:

  • - left click, then hold shift, then left click again.
  • - While holding the shift button, you can click more times to create a sequence of lines
  • - To create nice, axis-aligned lines, also hold ctrl

There is two types of saving in Gimp. The first one is the using File -> Save. However, this will only generate an xcf-file, something that can only be read by Gimp. Instead, you should use the File -> Export option:

  • - File -> Export
  • - Provide a name for your file. If you put '.png' as extension, it will be saved as png
  • - Use the default png export settings

That's it! Don't forget to make a yaml file for your map.