Gazebo supports the use of real world latitude and longitude coordinates in its simulations using the WGS84 geodetic system.
Gazebo's simulation is always performed in Cartesian coordinates (good old XYZ). Therefore, in order to use spherical coordinates, it's necessary to project coordinates expressed in the
WGS84 frame to Cartesian and back.
This tutorial will go over how to:
- Define what latitude / longitude the world origin corresponds to
- Query the world origin or an entity's coordinates in latitude / longitude
- Spawn entities at given latitude / longitude
- Teleport entities based on a given latitude / longitude
Coordinates for the world origin
The world's Cartesian coordinates correspond to a local tangent plane at a given point on the planetary surface. By default, this plane follows the ENU (East-North-Up) convention, as shown on the image below:
Users can define where the origin of the ENU coordinates sits on the surface of the planet in three different ways: through the SDF file, the GUI, or through an Ignition Transport service call.
Changing the world origin will only affect operations performed afterwards. For example, models already in the world will not be moved when the world origin's coordinates change.
On the SDF file, it's possible to define the world origin's spherical coordinates with the
At the moment, the only surface model supported is WGS84 and the only world frame orientation is ENU.
Try out an example world that ships with Gazebo and has the coordinates above as follows:
On the component inspector, expand the
Spherical Coordinates component to see that the coordinates were set correctly:
To change the world origin through the GUI, edit values within the component inspector shown above, and these changes will be reflected on simulation.
It's also possible to change the coordinates for the world origin at runtime through the
Loading the world above, try calling for example:
You should see the coordinates changing on the GUI.
See the Entity creation tutorial for an introduction to creating entities.
In order to create an entity at a given spherical coordinate using the
/world/<world_name>/create service, omit the
pose field from the
ignition::msgs::EntityFactory message and use the
spherical_coordinates field instead.
For example, you can spawn a sphere into the
spherical_coordinates.sdf world as follows:
It's also possible to move entities to a given spherical coordinate. Just use the
set_spherical_coordinate service that was used to set the world origin, but specify the entity to be moved.
For example, to move the sphere created above:
Querying entities' coordinates
When writing plugins, developers can use the
ignition::gazebo::sphericalCoordinates helper function to query the current coordinates for any entity that has a pose.