Install ROS2 + Carla on WSL2
Author: Yunhao Cao
In this article I will be describing how to install a Ubuntu Image on WSL2 and how to install ROS2 and connect to a native running instance of Carla on Windows 10 / 11.
Reference: ROAR ROS Setup Doc
Preview:
Install WSL
Fire up a new terminal and hit the following demand to see if you have a valid WSL setup
wsl --install
Then we want to make sure we’re using WSL2, and also make sure that the WSL runtime is updated to the newest version
wsl --update
wsl --set-default-version 2
Now we’re ready to install the ubuntu distro. Make sure you have at least 5GB of space in your C:\ disk. You can move your WSL image to a new disk later on.
wsl --install -d Ubuntu
You will be prompted to enter a username and password for the default user.
After installing, runnning
wsl -l -v
should show the following
NAME STATE VERSION
* Ubuntu Stopped 2
Make sure your VERSION of Ubuntu Distro says 2. The star(*) symbol can be missing here. We just need to run the following command to make it the default distro.
wsl -s Ubuntu
Now you’ve done WSL installable, you can follow this step to move WSL to another drive if wanted.
Install Carla On Windows
This step assumes that you have installed appropriate graphics drivers for your GPU. Since it is easy to install GPU in a Windows setup, the steps will not be covered.
Then download Carla for Windows (you don’t need to build it yourself, as on the github page they usually ship with Windows Binaries)
Then fire up CarlaUE4.exe, it will automatically start listening to 0.0.0.0:2000, and 0.0.0.0:2001, I added the following param to boost performance since my GPU is a trash MX350
CarlaUE4.exe -quality-level=Low -fps=5 -windowed -ResX=300 -ResY=200
Install ROS on WSL
Fire up WSL prompt, and follow the instructions to install WSL using Debian Packages
Install Carla on WSL
The reason we want to install Carla is because we want the PythonAPI provided by the Carla installation, we don’t actually need to fire up Carla in our WSL environment.
Plus in the near future if Vulkan API is supported by Dozen in Mesa3D, we could potentially potentially fire up Carla in the WSL environment.
Install ROS Bridge for CARLA
Firing up ROS Bridge
First you need to open up Carla on your host OS.
Then add a new file under home(~) directory called launchROSBridge.sh
Here below should be the content you add to the shell file.
parent_host=`grep -oP '(?<=nameserver ).+' /etc/resolv.conf`
echo Exporting Environmental Variables
export CARLA_ROOT=/opt/carla-simulator
export PYTHONPATH=$PYTHONPATH:$CARLA_ROOT/PythonAPI/carla/dist/carla-0.9.12-py3.7-linux-x86_64.egg:$CARLA_ROOT/PythonAPI/carla
echo Launching...Parent Host is $parent_host
ros2 launch carla_ros_bridge carla_ros_bridge.launch.py host:=$parent_host timeout:=5000
In this script, parent_host
variable is obtained by grepping contents of the /etc/resolv.conf
file, and we can use this IP to connect to our host OS’s listening ports.
Sanity Check for OpenGL/Vulkan
To run OpenGL / Vulkan APPs in your WSL environment, you want to run the following scripts
export DISPLAY=:0 #this makes the graphics output go to our host os
And runing glxinfo -B
should export something similar to the following
name of display: :0
display: :0 screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
Vendor: Microsoft Corporation (0xffffffff)
Device: D3D12 (NVIDIA GeForce MX350) (0xffffffff)
Version: 22.0.2
Accelerated: yes
Video memory: 10086MB
Unified memory: no
Preferred profile: core (0x1)
Max core profile version: 3.3
Max compat profile version: 3.3
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.1
OpenGL vendor string: Microsoft Corporation
OpenGL renderer string: D3D12 (NVIDIA GeForce MX350)
OpenGL core profile version string: 3.3 (Core Profile) Mesa 22.0.2 - kisak-mesa PPA
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL version string: 3.3 (Compatibility Profile) Mesa 22.0.2 - kisak-mesa PPA
OpenGL shading language version string: 3.30
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 22.0.2 - kisak-mesa PPA
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10
If you have your physical graphics card name displaying here, you are in good shape. Also you want to update your driver by running the following
sudo add-apt-repository ppa:kisak/kisak-mesa
sudo apt-get update
To verify that WSLg is working, run the following
sudo apt install mesa-utils vulkan-tools
glxgears
vkcube
running glxgears
and vkcube
should each pop up a window in your host OS.
Further Readings
ML Acceleration using CUDA and DirectML on WSL2