Skip to main content

WSL 2 for Robotics

info

Despite most PCs and laptops running Windows, robotics is easier to tackle using Linux. Fear not!! The Windows Subsystem for Linux allows you to run Linux environment on your Windows machine without the hassle of dual booting or virtual machines.

Getting WSL 2 for your machine:

  • WSL2 frees up a chunk of the kernel and allows you run fully blown Linux environment
  • follow the official docs for latest installation instructions WSL2

Linux distros from Microsoft Store

tip

WSL 2 by default does not support running GUI apps however there are ways around it. One such is to use VcXsrv for running linux GUI apps.

VcXsrv server to run GUI apps

  • even though you might not want to run the Linux GUI this is still desirable for apps such as RViz, Gazebo or PlotJuggler
  1. Download and install VcXrv for Windows
    • follow the official instructions VcXsrv
    • make sure you launch the configuration tool in the last installation step
  2. Generate config file for VcXsrv
    • Display settings: Multiple windows
    • Display number: -1
    • Start no client
    • Extra settings:
      • select "Disable access control", rest leave default
      • additional parameters fo VcXsrv: type in "-nowgl"
    • save config file locally where you can easily find it to launch VcXsrv
danger

When VcXrv first starts it wants to access to public networks. You can allow the access and follow the next step to tweak the Windows firewall to only allow access to WSL 2

Firewall inbound rules

  • Virtual machines running in WSL 2 have their own IPs
  • this can be used to setup inbound rules, that allow VcXsrv to only your WSL2
  • launch Windows Defender Firewall with Advanced Security
  • create new inbound rule:
    • Rule Type: Program
    • Program: This program path: PATH-TO/vcxrv.exe
    • Allow the connection
    • select Domain, Private
    • name your new rule: VcXsrv
    • finish
  • delete automatically created rules
    • VcXSrv automatically creates its own rules during first launch
    • in inbound rules in Windows Defender Firewall with Advanced Security are two rules named VcXsrv windows xserver
    • find both and select disable in the right hand window
    • make sure only the rule that we created stays enabled for VcXsrv

Connecting virtual display

  • it is not possible to physically connect WSL 2 to a monitor
  • we can however use the DISPLAY environment variable to tell it to the one already connected to the PC
    • launch WSL 2
    • open .bashrc file using your favorite text editor e.g. nano ~/.bashrc
    • append export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
    • save and exit
  • Restart WSL 2

ROS2 setup

Continue according to the instructions in the ROS2 section