Webots is a physics environment created by Cyberbotics. This guide details how to set up Webots. It gives instructions on setting up Ubuntu (WSL) inside Windows for Windows users, and the rest of the guide is aimed at Ubuntu users (including Windows WSL Ubuntu users).
Prerequisites
Windows
Follow the instructions for setting up Ubuntu in WSL on the Getting Started NUbook page under the Windows tab in the Docker section.
Since Webots uses a GUI, we will need to set up a way to launch and display the program. Use these instructions which is for a similar scenario, but with GitKraken instead of Webots. Take note of the following changes:
You can ignore installing and launching GitKraken. Instead, we will use the Webots instructions later in this guide to install and launch Webots.
When running XLaunch configuration, uncheck 'Native opengl' on the third window.
To prevent having to set the DISPLAY environment variable every time, run the following command in Ubuntu:
echo 'export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '\''{print $2; exit;}'\''):0.0' >> ~/.bashrc
To be able to copy and paste into the Ubuntu terminal, right-click on the bar at the top of the Ubuntu window. Then click on Properties, and enable Use Ctrl+Shift+C/V as Copy/Paste in the Options tab. Note that this is Ctrl+Shift+C/V not Ctrl+C/V.
In Ubuntu run
sudo apt-get updatesudo apt-get install libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-render-util0 libxcb-xfixes0 libxcb-xinerama0 libxcb-xkb1 libxkbcommon-x11-0 libxkbcommon0
You will need XLaunch running every time you want to run Webots.
Follow the rest of the steps on this page within Ubuntu.
Arch Linux
Run the following to obtain the required dependencies.
pacman -S --needed git lsb-release cmake swig glu glib2 freeimage freetype2 libxml2 libzip boost-libs gd libgcrypt libzip readline pbzip2 pciutils wget zip unzip jdk-openjdk libusbDownload our usb patch which helps the makefile link
libusb
properly.After you do the clone step below, move the patch file
webots_usb.patch
into your webots install folder, and rungit apply webots_usb.patch
inside that folder to apply it. After that, you should be able to runmake -j$(nproc)
as usual.
Install libraries for cmake, protobuf, eigen, yaml-cpp, ninja-build, and clang-tidy:
sudo apt-get updatesudo apt-get install cmake-curses-gui libprotobuf-dev protobuf-compiler libeigen3-dev libyaml-cpp-dev ninja-build clang-tidy python3-dev libjpeg9-dev
Install Webots
Open a terminal and swap to your home directory (note that Webots should be cloned in your home directory). Then clone the repository and change into the cloned directory:
cd ~git clone --branch nubots-changes --single-branch --recurse-submodules -j$(nproc) https://github.com/NUbots/webots.gitcd webotsBy using these commands, you'll be on the correct branch (
nubots-changes
) and you'll have the required submodules.Install Webots build dependencies:
sudo ./scripts/install/linux_compilation_dependencies.shBuild Webots:
make -j$(nproc)Add the
WEBOTS_HOME
env variable to your.bashrc
file:echo WEBOTS_HOME=$HOME/webots >> ~/.bashrcInstall dependencies for the referee:
cd ~/webots/projects/samples/contests/robocup/controllers/refereepip3 install -r requirements.txtBuild the Robocup controllers:
cd ~/webots/projects/samples/contests/robocupWEBOTS_HOME=$HOME/webots make -j$(nproc)
Install Game Controller
Install the ant build tool:
sudo apt-get install ant default-jdkClone the Robocup TC GameController repo:
cd ~git clone https://github.com/RoboCup-Humanoid-TC/GameController.gitChange into the cloned directory and build the GameController:
cd GameControllerant
Get and Build the NUbots Environment
Open a terminal. Clone the NUbots/NUWebots repository and move into it by running
cd ~git clone https://github.com/NUbots/NUWebots.gitcd NUWebotsInstall the python dependencies:
pip3 install -r requirements.txtConfigure the codebase by running
./b configureOptional Flags
We can configure with several optional flags as follows:./b configure [-i] [-- <flags>]where
-i
runs an interactive configuration withccmake
, and<flags>
can be any valid cmake command line flag. Some useful cmake flags are:Flag Effect Default -DUSE_ASAN=ON
Compile with address sanitizer OFF
-DUSE_UBSAN=ON
Compile with undefined behaviour sanitizer OFF
-DENABLE_CLANG_TIDY=ON
Analyse the code being compiled with clang-tidy OFF
-DWEBOTS_HOME=path/to/webots
Tells the compiler where webots is (usually implicitly set by environment variable) /usr/local/webots
-DCMAKE_BUILD_TYPE=<build type>
Tells the compiler what type of build type to use, out of { Release
,Debug
,MinSizeRel
,RelWithDebInfo
}Release
Build the codebase by running
./b build
Running Webots
Navigate to the Webots folder
cd ~/webotsLaunch Webots by running
./webotsOpen the NUbots world file inside Webots.
Click on
File->Open World...
.In the pop-up, navigate to the NUbots/NUWebots repository on your computer and open the
worlds/kid.wbt
world file.
Running Webots with GameController
Find your primary local IP address by running the following.
hostname -IYour primary IP address will usually be the first of the addresses in the output returned. For example, if
hostname -I
returns10.1.0.207 10.1.0.139 172.17.0.1
, use10.1.0.207
.Set the
GAME_CONTROLLER_UDP_FILTER
env variable to your local IP address from step 1, to ensure your instance of GameController is not affected by other instances of GameController on the network.export GAME_CONTROLLER_UDP_FILTER=<IP_ADDRESS> # replace <IP_ADDRESS> with your IP address from step 1Run the following to open Webots with the Robocup world and the GameController:
JAVA_HOME=/usr/lib/jvm/default-java WEBOTS_HOME=$HOME/webots GAME_CONTROLLER_HOME=$HOME/GameController ~/webots/webots ~/webots/projects/samples/contests/robocup/worlds/robocup.wbtSometimes closing Webots doesn't properly close the GameController subprocess. If this happens you'll get an error about GameController when you next launch Webots. To fix, run the following command which terminates the GameController process, then start Webots again:
kill -9 $(pgrep -fi GameControllerSimulator.jar)
Creating a New Controller
From the root of the NUWebots repository run
./b controller generate <name of controller>
Where <name of controller>
is the name you want to use for the new controller. A folder and files will be created with this name, so they must be valid file names (don't use spaces in your controller name).