This page is describing the upcoming ROS2 version of the MRS UAV System (however, it may be still outdated). If you are looking for ROS1 version of the docs, follow to https://ctu-mrs.github.io/docs/1.5.0/introduction/.
How to create a real world elevation map in Gazebo
We will create a 3D model in Blender using BlenderGIS plugin and elevation data from opentopography.org. We will then export the model as a .dae
file and a texture as .tif
to be used in Gazebo. Finally, we will create a simple Gazebo .sdf
to view the created model.
1. Getting Blender and the plugin
Download BlenderGIS plugin as zip
In Blender, go to Edit
-> Preferences
-> Add-ons
-> Install
(under v
at the rop right corner of the window). Then select the downloaded zip file
The plugin should now appear in the addons list. Make sure it's enabled (checkbox is checked).
2. Creating the textured plane
Once the plugin is installed, you should see the GIS button available. Press it, then select Web geodata
-> Basemap
You can change the source (for example to use Bing maps) if you want. Press OK
.
The 2D map view should appear. You can drag the map and zoom to go the location you want, or you can press G
to then enter a specific location.
Once you're satisfied with the location and zoom level, press E
to create a new plane with the texture applied to it.
3. Aligning the map to the correct coordinates
By default, the map's origin will typically not be at the lattitude/longitude coordinates that you enter using the G
command. This would cause the created mesh to be misaligned in Gazebo by some offset. To fix this, open the GIS -> Web geodata
-> Basemap
dialog again. Now, you should see a subdialog Scene georeferencing
(see below).
Select the Geo
option and enter the lattitude/longitude coordinates of your world origin (this are the same numbers you will put into your Gazebo world's spherical_coordinates
tag). This will move Blender's origin to these lat/lon coordinates so that the mesh is aligned when you import it to gazebo.
Note that if you use GPS in your Gazebo simulation and you move the world's origin, you also need to set the simulated_rtk
parameter of mrs_uav_px4_api
via a custom config (see here).
4. Adding elevation data
To import the elevation data, we use OpenTopography API. We will need an API key to feed into the plugin. It's free.
Got to OpenTopography
Create an account. Select Affiliation: Academia, Organization: Czech Technical University in Prague.
Then login with the created account. You can request the API key here
Now in Blender, select the plane object we've created.
Go to GIS
-> Web geodata
-> Get elevation (SRTM)
. Select a server, enter your API key and press OK
. This can take some time.
5. Adjusting the elevation
Usually we want to adjust our map model so that its origin is at zero. To do that we:
Apply the modifiers: select the plane object, press Ctrl+A
and select Apply
-> Visual Geometry to Mesh
Now, because the plugin is creating a plane based on the screen ratio, the plane will not be a perfect rectangle. What we can do is:
-
Select the plane
-
Go to the edit mode, you can press tab to toggle it
-
Select the top view
-
Select a vertex that is the closest one to the origin and press
n
to toggle the sidebar -
Now we can see its global coordinates. We want to move all of our vertices so that this point moves to the origin.
-
To do that we can copy the
X
position, then select all vertices (a
), then subtract the copied value from the median'sX
: -
Repeat the same for the
Y
andZ
.
6. Exporting the model
You can export the world using the legacy .dae
format or the newer .glb
6.1 dae
We export our model as Collada .dae
file. Select the plane object, go to File
-> Export
-> Collada (.dae)
.
Check Selection Only
, check Global Orientation
-> Apply
, and select X
as forward axis and Z
as up axis:
Press Export COLLADA
and save the file somewhere. There should be two files created: the .dae
and the .tif
texture.
6.2 glb
Check the Selected Objects
include option and deselect the +Y Up
transform option:
After pressing Export glTF
you will get a single file with the texture included in it.
7. Importing to the Gazebo world.
Assuming you exported a .dae
file, create a test.sdf
file with the following content:
<?xml version="1.0"?>
<sdf version="1.6">
<world name="default">
<include>
<uri>model://sun</uri>
</include>
<model name="myModel">
<pose>0 0 0 0 0 0</pose>
<static>true</static>
<link name="body">
<visual name="visual">
<geometry>
<mesh>
<uri>file://myModel.dae</uri>
</mesh>
</geometry>
</visual>
</link>
</model>
</world>
</sdf>
Place the myModel.dae
and the corresponding .tif
texture files in the same folder as the test.sdf
file.
Finally, run Gazebo with the test.sdf
file (you may want to zoom out a bit):
gz sim test.sdf