It is often desirable to run simulation on a remote computer, such as a computer managed by cloud provider, in order to paralellize work or access specific compute resources. Simulated sensors that require GPU access have historically been difficult to use on a remote computer due to OpenGL's X server requirement on linux systems. This issue can be resolved through installation and proper configuration of X, but the steps can be complex and error prone.
An easier solution is through the use of EGL, which allows for the the creation of rendering surfaces without an X server. Gazebo has added support for EGL via the --headless-rendering
command line option. Use of EGL is only available with OGRE2.
Example usage:
If you are using Gazebo as a library, then you can configure the server to use headless rendering through the ServerConfig::SetHeadlessRendering(bool)
function. Make sure your SDF world uses OGRE2.
AWS Example
This example will guide you through the process of launching and configuring an AWS GPU instance with Gazebo running headless. A GPU instance is recommended when sensors that require a render engine are used. It is possible to use a machine without a GPU, in which case OGRE will revert to software rendering. You can read more about OGRE's EGL implementation here.
- Go to the AWS EC2 service
- Click the
Launch Instance
button in the upper right. - Select
Ubuntu Server
version 20.04 or greater from the AMI list. - Choose a GPU enabled instance type, such as
g3.4xlarge
. - Enable
Auto-assign Public IP
on theConfigure Instance Details
step. This is not the best practice, but it simplifies this tutorial. - Add around 200GB storage to your instance on the
Add Storage
step. - Enable ssh source
Anywhere
on theConfigure Security Group
step. - Review and launch your instance. Make sure to setup a key pair in the popup that appears after clicking
Launch
.- You can configure other options as needed. Review the AWS documentation for additional help.
- Select the newly launched instance on the EC2 dashboard, and take note of the
Public IPv4 address
. - SSH into your new machine instance. ssh -i SSH_PEM_FILE_USED_DURING_LAUNCH ubuntu@EC_INSTANCE_PUBLIC_IP
- Install Ubuntu drivers, which will install nvidia drivers: sudo apt-get updatesudo apt install ubuntu-drivers-commonsudo ubuntu-drivers install
- Add the
ubuntu
user to therender
group, which is required to access to the dri interfaces.sudo usermod -a -G render ubuntu - Reboot the machine and log back in. sudo reboot
- Install Gazebo.
- Run a Gazebo world that uses OGRE2 with camera sensors using headless rendering. This will enable EGL. gz sim -v 4 -s -r --headless-rendering sensors_demo.sdf
- Check that simulation is producing sensor data by ssh'ing into the EC2 instance from a new terminal and echoing a sensor topic. ssh -i SSH_PEM_FILE_USED_DURING_LAUNCH ubuntu@EC_INSTANCE_PUBLIC_IPgz topic -et /thermal_camera