12 KiB
WSL Setup Guide for UAV-UGV Simulation
This guide walks you through setting up the GPS-denied UAV-UGV simulation on Windows Subsystem for Linux (WSL).
Prerequisites
- Windows 10 version 2004+ (Build 19041+) or Windows 11
- Administrator access to Windows
- At least 16GB RAM (8GB minimum)
- 50GB free disk space
- NVIDIA GPU (optional, for hardware acceleration)
Part 1: Install WSL2 with Ubuntu 22.04
Step 1.1: Enable WSL
Open PowerShell as Administrator and run:
# Enable WSL and Virtual Machine Platform
wsl --install
# Or if already installed, update to WSL2
wsl --set-default-version 2
Restart your computer after this step.
Step 1.2: Install Ubuntu 22.04
# List available distributions
wsl --list --online
# Install Ubuntu 22.04
wsl --install -d Ubuntu-22.04
When prompted, create a username and password for your Ubuntu installation.
Step 1.3: Verify WSL2
wsl --list --verbose
You should see Ubuntu-22.04 with VERSION 2:
NAME STATE VERSION
* Ubuntu-22.04 Running 2
If it shows VERSION 1, upgrade it:
wsl --set-version Ubuntu-22.04 2
Step 1.4: Configure WSL Memory
Create or edit %USERPROFILE%\.wslconfig (Windows path: C:\Users\YourName\.wslconfig):
[wsl2]
# Allocate memory (adjust based on your system)
memory=8GB
processors=4
# Swap file
swap=4GB
# Enable systemd (required for ROS 2)
[boot]
systemd=true
Restart WSL after creating this file:
wsl --shutdown
Part 2: Setup GUI Support for Gazebo
WSL2 supports GUI applications through WSLg (Windows 11) or X11 forwarding (Windows 10).
Option A: WSLg (Windows 11 - Recommended)
WSLg is built-in to Windows 11. No additional setup needed! GUI apps work out of the box.
Verify WSLg is working:
# Inside WSL Ubuntu
sudo apt update
sudo apt install -y x11-apps
xcalc # Should open a calculator window
Option B: X11 Server (Windows 10)
Install VcXsrv
- Download and install VcXsrv
- Launch XLaunch with these settings:
- Display: Multiple windows
- Start no client
- Check: Disable access control
- Save configuration for future use
Configure WSL to use X Server
Add to ~/.bashrc in WSL:
# X11 forwarding for WSL1/WSL2 (Windows 10)
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
export LIBGL_ALWAYS_INDIRECT=1
Apply changes:
source ~/.bashrc
Test X11:
sudo apt install -y x11-apps
xcalc # Should open a calculator
Part 3: Install ROS 2 Humble
Step 3.1: Setup ROS 2 Repository
# Update system
sudo apt update && sudo apt upgrade -y
# Install prerequisites
sudo apt install -y software-properties-common
sudo add-apt-repository universe
# Add ROS 2 GPG key
sudo apt install -y curl gnupg lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key \
-o /usr/share/keyrings/ros-archive-keyring.gpg
# Add repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] \
http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
Step 3.2: Install ROS 2 Humble
# Update package list
sudo apt update
# Install ROS 2 Desktop (includes RViz, demos, tutorials)
sudo apt install -y ros-humble-desktop
# Install development tools
sudo apt install -y \
ros-dev-tools \
python3-colcon-common-extensions \
python3-rosdep
Step 3.3: Initialize rosdep
sudo rosdep init
rosdep update
Step 3.4: Setup Environment
Add to ~/.bashrc:
# ROS 2 Humble
source /opt/ros/humble/setup.bash
# Optional: Auto-source workspace
if [ -f ~/ros2_ws/install/setup.bash ]; then
source ~/ros2_ws/install/setup.bash
fi
Apply changes:
source ~/.bashrc
Step 3.5: Verify ROS 2
ros2 --version
# Should output: ros2 cli version: 0.x.x
# Test with a demo (optional)
ros2 run demo_nodes_cpp talker
# Press Ctrl+C to stop
Part 4: Install Gazebo Classic 11
# Install Gazebo Classic
sudo apt install -y gazebo11 libgazebo11-dev
# Install ROS 2 Gazebo packages
sudo apt install -y \
ros-humble-gazebo-ros-pkgs \
ros-humble-gazebo-plugins
Test Gazebo
gazebo --verbose
A Gazebo window should open. Note: First launch may be slow.
Common Issues:
- Black screen: Wait 30-60 seconds for Gazebo to fully initialize
- Slow performance: Use software rendering (see below)
- Crashes: Check GPU drivers and memory allocation in
.wslconfig
Performance Tweaks
If Gazebo is slow, force software rendering:
export LIBGL_ALWAYS_SOFTWARE=1
gazebo
Add to ~/.bashrc to make permanent:
echo "export LIBGL_ALWAYS_SOFTWARE=1" >> ~/.bashrc
Part 5: Install ArduPilot SITL
Step 5.1: Install Dependencies
sudo apt install -y \
git \
gitk \
git-gui \
python3-dev \
python3-opencv \
python3-wxgtk4.0 \
python3-pip \
python3-matplotlib \
python3-lxml \
python3-pygame \
libxml2-dev \
libxslt1-dev \
python3-scipy
Step 5.2: Clone ArduPilot
cd ~
git clone https://github.com/ArduPilot/ardupilot.git
cd ardupilot
git submodule update --init --recursive
Step 5.3: Install ArduPilot Prerequisites
cd ~/ardupilot
Tools/environment_install/install-prereqs-ubuntu.sh -y
Reload your shell:
. ~/.profile
Step 5.4: Build ArduCopter SITL
cd ~/ardupilot
./waf configure --board sitl
./waf copter
Step 5.5: Test ArduPilot SITL
cd ~/ardupilot/ArduCopter
sim_vehicle.py --console --map
You should see MAVProxy console and a map window. Press Ctrl+C to exit.
Part 6: Install ardupilot_gazebo Plugin
# Clone the plugin
cd ~
git clone https://github.com/ArduPilot/ardupilot_gazebo.git
cd ardupilot_gazebo
# Build
mkdir build && cd build
cmake ..
make -j4
sudo make install
Configure Gazebo Paths
Add to ~/.bashrc:
# ArduPilot Gazebo
export GAZEBO_MODEL_PATH=$HOME/ardupilot_gazebo/models:$GAZEBO_MODEL_PATH
export GAZEBO_RESOURCE_PATH=$HOME/ardupilot_gazebo/worlds:$GAZEBO_RESOURCE_PATH
Apply changes:
source ~/.bashrc
Part 7: Install MAVROS
sudo apt install -y \
ros-humble-mavros \
ros-humble-mavros-extras
Install GeographicLib Datasets
sudo /opt/ros/humble/lib/mavros/install_geographiclib_datasets.sh
Part 8: Setup UAV-UGV Simulation Project
Step 8.1: Create ROS 2 Workspace
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
Step 8.2: Clone Project
# Replace with your repository URL
git clone https://git.sirblob.co/SirBlob/simulation.git uav_ugv_simulation
cd uav_ugv_simulation
Step 8.3: Install Python Dependencies
# Install system Python packages
sudo apt install -y \
python3-pip \
python3-venv \
python3-opencv \
libopencv-dev
# Install additional ROS packages
sudo apt install -y \
ros-humble-cv-bridge \
ros-humble-image-transport \
ros-humble-tf2 \
ros-humble-tf2-ros \
ros-humble-tf2-geometry-msgs
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install Python packages
pip install --upgrade pip
pip install -r requirements.txt
Step 8.4: Build ROS Package
cd ~/ros2_ws
colcon build --packages-select uav_ugv_simulation --symlink-install
source install/setup.bash
Step 8.5: Make Scripts Executable
cd ~/ros2_ws/src/uav_ugv_simulation
chmod +x scripts/*.sh
chmod +x setup.sh
chmod +x activate_venv.sh
Part 9: Test the Installation
Test 1: Gazebo
gazebo --verbose
Test 2: ROS 2
ros2 topic list
Test 3: ArduPilot SITL
cd ~/ardupilot/ArduCopter
sim_vehicle.py -v ArduCopter -f gazebo-iris --console --map
Test 4: Complete Simulation (Final Test)
Terminal 1 - Gazebo:
cd ~/ros2_ws/src/uav_ugv_simulation
source activate_venv.sh
gazebo --verbose worlds/empty_custom.world
Terminal 2 - ArduPilot:
cd ~/ardupilot/ArduCopter
sim_vehicle.py -v ArduCopter -f gazebo-iris --console --map -I0
Terminal 3 - MAVROS & Nodes:
cd ~/ros2_ws/src/uav_ugv_simulation
source activate_venv.sh
ros2 launch uav_ugv_simulation uav_only.launch.py
WSL-Specific Issues & Solutions
Issue 1: "Cannot open display"
Solution:
Windows 10:
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
Windows 11 (WSLg):
export DISPLAY=:0
Issue 2: Gazebo Black Screen
Solutions:
- Wait 30-60 seconds for initialization
- Use software rendering:
export LIBGL_ALWAYS_SOFTWARE=1 - Increase WSL memory in
.wslconfig
Issue 3: GPU Acceleration Not Working
For NVIDIA GPUs in WSL2:
- Install NVIDIA drivers on Windows (not in WSL)
- Install CUDA in WSL:
sudo apt install -y nvidia-cuda-toolkit - Verify:
nvidia-smi
Issue 4: "Permission denied" on Serial Ports
sudo usermod -aG dialout $USER
# Logout and login again
Issue 5: Slow Performance
- Increase memory in
.wslconfig - Close unnecessary Windows applications
- Use software rendering for Gazebo
- Reduce Gazebo real-time factor:
gazebo --verbose -u # Start paused
Issue 6: Network Issues (MAVROS connection)
Ensure localhost is working:
# Test connection
nc -zv 127.0.0.1 14550
# If fails, check WSL networking
cat /etc/resolv.conf
Quick Start After Installation
# 1. Navigate to project
cd ~/ros2_ws/src/uav_ugv_simulation
# 2. Activate environment
source activate_venv.sh
# 3. Run simulation
bash scripts/run_simulation.sh
Performance Optimization for WSL
1. Increase WSL Resources
Edit C:\Users\YourName\.wslconfig:
[wsl2]
memory=12GB
processors=6
swap=8GB
localhostForwarding=true
2. Enable Systemd
In .wslconfig:
[boot]
systemd=true
3. Disable Windows Defender for WSL
Add exclusion in Windows Security:
- Path:
C:\Users\YourName\AppData\Local\Packages\CanonicalGroupLimited*
4. Use Fast SSD
Move WSL to SSD if on HDD:
wsl --export Ubuntu-22.04 ubuntu-backup.tar
wsl --unregister Ubuntu-22.04
wsl --import Ubuntu-22.04 D:\WSL\Ubuntu ubuntu-backup.tar
Useful WSL Commands
# List WSL distributions
wsl --list --verbose
# Shutdown WSL (free resources)
wsl --shutdown
# Access WSL files from Windows
\\wsl$\Ubuntu-22.04\home\youruser
# Run Linux command from Windows
wsl ls -la
# Set default WSL distribution
wsl --set-default Ubuntu-22.04
Troubleshooting Resources
- WSL Issues: https://github.com/microsoft/WSL/issues
- Gazebo WSL: https://classic.gazebosim.org/tutorials?tut=wsl
- ROS 2 WSL: https://docs.ros.org/en/humble/How-To-Guides/Installing-on-Raspberry-Pi.html
- ArduPilot Forums: https://discuss.ardupilot.org/
Next Steps
After successful installation:
- Read the Usage Guide
- Understand GPS-Denied Navigation
- Review Architecture
- Try example missions in
docs/usage.md
Known Limitations in WSL
- Performance: ~70% of native Linux performance
- GPU: Limited DirectX translation in WSLg
- Real-time: WSL2 is not real-time capable
- USB: Direct USB forwarding requires usbipd-win
- GUI: Some OpenGL features may not work perfectly
For production work, consider dual-boot Ubuntu 22.04 or a native Linux installation.