Skip to content

2. Setting up your environment

Imad Issafras edited this page Jul 27, 2024 · 22 revisions

Virtual Machines for tool set and Gazebo server + Gazebo-classic client running natively

Virtual Machines

Windows

In Windows, we need to install Ubuntu 22.04 (Jammy) under WSL 2. This is only possible on Windows 10 version 2004 and higher or Windows 11. To do so, open the Windows command prompt as administrator and run wsl --install. Once that's done, restart your computer and open the Terminal application (Use the search bar if you need to, I also recommend pinning it to your taskbar once its open). Click on the "v" next to the "+" in the top bar, go to settings, and change "Default profile" to "Ubuntu" (If Ubuntu doesn't appear as a possible choice, it was not installed properly, try wsl --install again). Then, under the "Profiles" section, find your Ubuntu profile, and enable "Run this profile as Administrator". Finally, press the "+" to open your Ubuntu terminal. Run cd && git clone https://github.com/mcgill-robotics/drone to be on the same page as Mac users.

Mac

In Mac, we don't have WSL and thus have to go through the normal means of getting a virtual machine. Install VirtualBox, this will be our virtual machine's type 2 hypervisor. Depending on if you have an Intel chip (amd64) or an Apple Silicon chip (M1/M2) (arm64), you will need to install a different image (.iso) file of Ubuntu 22.04 (Jammy). For Intel chips, download the x86_64/amd64 image. Otherwise, download the arm64 image. Open VirtualBox, go to Machine -> New, give your vm a name and select the ISO file you just downloaded. Enter a new username and password (or keep the default). Allocate as much Base memory and as many Processors as you can while still staying in the green zone. Give the vm around 70 GB for the Disk Size. Then press Finish. This should launch the vm, which may launch an installer, follow the steps of the installer if you need to do so. Once at the installer is done, you should be prompted to enter your username and password. Once you have your command prompt, run cd && git clone https://github.com/mcgill-robotics/drone && cd drone/setup_scripts && source setup_ubuntu.sh. This will install a graphical user interface, which is going to make your life easier and make it possible for you to run the Gazebo server. The user interface the script installs is the i3 window manager, which is a tiling window manager. For now all you need to know is that to run a terminal emulator (get a shell prompt), you press <Alt>+<Enter>, but there are plenty of other key combinations to perform various actions. More information can be found here and it's configuration file is under ~/.config/i3/config.

Tool set

We need to clone the PX4 repo and to install ROS2 humble, Gazebo classic 11.10.2 and PX4's build dependencies. These can be done through the setup_tools.sh script under setup_scripts. Run cd ~/drone/setup_scripts && source setup_tools.sh. This will take a while so carry on to the next section while it's running. Avoid killing the virtual machine in the meanwhile or turning off your computer.

sudo apt remove gz-garden
sudo apt install aptitude
sudo apt autoremove
sudo aptitude install gazebo libgazebo11 libgazebo-dev

Gazebo

We need Gazebo version 11.10.2 running natively, Gazebo is the simulator we use. We will do so by using the Conda package manager.

  1. Install MiniConda by selecting the right installer for your OS, make sure to check the add to PATH box during the installation to not have to do it manually later
  2. Open the command prompt
    • Search for cmd.exe on Windows
    • Search for Terminal on MacOS
  3. Run conda install git in the prompt if you don't have git
  4. Once that's done, run conda create -n ros_env && conda activate ros_env
    • This creates a Conda environment which is self-contained, similar to a python venv, named "ros_env"
    • Then you run conda activate to enter said environment
    • This should prefix your prompt with "(ros_env)"
    • Later, you can run conda deactivate to exit the environment
    • More on managing conda environments here
  5. Run
conda config --env --add channels conda-forge
conda config --env --add channels robostack-staging
conda config --env --remove channels defaults
  • This ensures packages are installed from conda-forge or robostack-staging
  1. Install Gazebo 11.10.2 by running conda install gazebo=11.10.2
  2. Once the install is done, close your terminal
  3. From a new terminal, run conda activate ros_env, then try running gazebo --version
    • This should not throw an error
  4. Run gazebo in your terminal, this should open a GUI
  5. Close the GUI (either CTR+C from the terminal or press the x at the top right of the gazebo GUI)
  6. From the terminal change directory into your home directory
  • In Mac and Linux, this can be done with cd ~
  • In Windows, cd %userprofile%
  1. Run cd .gazebo && git clone https://github.com/PX4/PX4-gazebo-models.git
  • We need the various meshes and scripts inside this repository so that our gazebo client can render the simulation properly
  1. Move all of the files and folders of the cloned repository to the .gazebo directory

Running Sim (TO REMOVE, put here for self)

Run the docker container using docker run -it --privileged -e DISPLAY:=0 -p 14570:14570/udp -p 11345:11345 unhappysquid/drone_a1. From the docker container, run HEADLESS=1 GAZEBO_IP=$(ip a | grep 'eth0' -A 3 -m 1| grep 'inet' | awk '{print $2}' | awk -F"/" '{print $1}') make px4_sitl gazebo-classic_standard_vtol. From the native environment, open your terminal, activate your conda environment, run gzclient --verbose

Getting Git, ROS 2, Gazebo simulator, PX4 firmware, QGroundControl, Tmux

Optional tools

Considered approaches (For future lead's reference)

We want a way to have our system run the simulation smoothly to make development enjoyable, this requires GPU accelerated graphics. In the case of a graphics card that is within the same chip as the CPU, a virtual machine or WSL should work fine. The issue arises when the computer has a dedicated GPU, thus making it complicated for the simulator to access the GPU from a virtual machine. Without a hypervisor type 1, only one OS can use the GPU at a time, meaning only the host OS uses the GPU, meaning no GPU for our virtual machine. Not to mention that a good proportion of students use mac, so our solution should be OS agnostic. In the bellow list, + means a positive aspect, - means a negative aspect, X means a dealbreaker

  1. Dual booting
    • - Non-trivial to set up
    • X Not universal, notably, complicated on Mac.
    • - Trickier to restart from 0 than virtual machines
    • + Bare metal performance
  2. WSL by itself
    • X Requires Windows machine
    • - Doesn't work with some GPUs, notably Intel Iris Xe GPU
    • + Supports most GPUs
    • + As easy to experiment with as any virtual machine, can always scrap it and restart from new
  3. Virtual machine by itself
    • X Doesn't work with GPUs at all
  4. Docker for tool set + Gazebo ignition running natively
    • + Can easily share an image with all the tools needed for development
    • Supported platforms for gazebo
    • X Gazebo's Windows support doesn't include the GUI at the time of writing
    • - Untested on Mac
  5. Docker for tool set + AirSim running natively
    • + Can easily share an image with all the tools needed for development
    • + Runs on top of Unreal Engine, making it ideal for realistic computer vision
    • X AirSim doesn't work on MacOS
    • - Microsoft, AirSim's developers, have stopped working on it since 2022
      • Colosseum is a successor to AirSim which supports PX4, sadly only for multi rotors as well
    • - Only supports PX4 multi rotor, no VTOL
  6. Docker for tool set Gazebo server + Gazebo-classic client running natively
    • + Can easily share an image with all the tools needed for development
    • - Gazebo-classic is reaching end of life in 2025
      • Hopefully by the time it reaches end of life, gazebo ignition will work on more than just Linux
    • + Easy to setup
    • + Uses Conda for Gazebo which is cross-platform
    • + Gazebo classic works on all platforms (supposedly), meaning simulation is running natively
    • X Docker desktop doesn't support x11 which is needed by Gzserver
      • No way around Docker desktop on Windows and Mac
  7. (WSL for windows, VM for mac) for tool set and Gazebo server + Gazebo-classic client running natively
    • - A bit more complicated to setup
    • + Uses Conda for Gazebo which is cross-platform
    • + Gazebo classic works on all platforms (supposedly), meaning simulation is running natively
Clone this wiki locally