How to run Skybrush with SITL on Windows
Published: 2023-10-18 05:08:46

## Prerequisites
* Windows11(Windows10 should be work)
* WSL2
  * [Installation](https://learn.microsoft.com/en-us/windows/wsl/install#install-wsl-command)
* VSCode
  * [Installation](https://code.visualstudio.com/download)

## Conceptual scheme

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a4cngvwirhj5zlv32ees.png)

## Setup Linux Distro
1.Install VSCode Extension

* Open VSCode, search WSL extension from marketplace and install


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x7n6w7lfjablnlhlcufv.png)



2.Setup Ubuntu22.04

* Create Distor from VSCode


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yf1lninwg53ly28tfcxk.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/450wr1kg9ixvqpw5p0a4.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vtwfg26b2mr1ns99kuf3.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/go2nsu8htii4scv5r8n2.png)



* Type Username and Password


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j4e58t4jroyjl3cb4gib.png)



3.Back to VSCode and connect to Ubuntu

* Select Ubuntu22.04 from `Connect to WSL using Distro...`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atv6rbzhung6ha1bszvy.png)



* If you see `WSL:Ubuntu-22.04` at left-bottom corner, you successfully connect to it.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p382u9rzqb31vmmrfp3o.png)

4.Update and Upgrade Registry
* Popup console using `ctrl + j`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ilvjbwrkd6dcydv6xtc4.png)

* Update and Upgrade Registry

```
sudo apt update && sudo apt upgrade
```

## Build Python3.11
1.Follow below commands and build python.
```
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
wget https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tgz
tar -xzvf Python-3.11.3.tgz
cd Python-3.11.3
./configure --enable-optimizations
make -j 12
sudo make altinstall
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.11 1
```

2.Check if you can see the version of python is 3.11. 
```
skybrush@MyComputer:~/Python-3.11.3$ python --version
Python 3.11.3
```

## Install Poetry
1.install poetry using pip3.

```
sudo apt install python3-pip
pip3 install poetry

```

## Build skybrush server
1.Clone source code and install using poetry.

```
git clone https://github.com/skybrush-io/skybrush-server.git
cd ~/skybrush-server/
python3 -m poetry install
```
2.Launch skybrush server
```
python3 -m poetry run skybrushd -c etc/conf/skybrush-outdoor.jsonc
```

* If you correctly launch it, the result will be like below.

```
skybrush@MyComputer:~/skybrush-server$ python3 -m poetry run skybrushd -c etc/conf/skybrush-outdoor.jsonc
[13:32:13]   server                 Starting Skybrush server 2.15.0
           ✔ skybrush               Loaded configuration from '/home/skybrush/skybrush-server/etc/conf/skybrush-outdoor.jsonc'
             logging                Storing logs in '/home/skybrush/.cache/Skybrush Server/log'
             logging                Logging started
             http_server            Starting HTTP server on :5000
           ▲ insomnia               Cannot prevent sleep mode on this platform
             mavlink     mav        Routing primary traffic to mav
             mavlink     mav        Routing RTK corrections to mav
             mavlink     mav        Routing RC overrides to mav
             mavlink     mav        Connection at :14550 up and running
```

## Build SITL
1.Press `+` button and create new console and switch to it.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gc66g6ulkyodgnf5gssz.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mmb20hv5jp2mxtop0y56.png)


2.Build SITL

```
git clone https://github.com/skybrush-io/ardupilot.git
cd ardupilot/
git checkout CMCopter-4.2
git submodule update --init --recursive
sudo apt install python3.10-venv
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip wheel
pip install future empy intelhex pexpect
./waf configure --debug --board sitl
./waf copter
```

3.Test SITL
```
build/sitl/bin/arducopter
```

## Build ap-swarm-launcher
1.Build ap-swarm-launcher 
```
deactivate
cd ~
git clone https://github.com/skybrush-io/ap-swarm-launcher
cd ap-swarm-launcher
python3 -m poetry install

```

2.Launch ap-swarm-launcher
```
python3 -m poetry run ap-sitl-swarm -n 20 --num-drones-per-row 5 --spacing 5 --pos-noise 0.5 --yaw-noise 10 ../ardupilot/build/sitl/bin/arducopt
er
```

* If you correctly launch it, the result will be like below.
```
skybrush@MyComputer:~/ap-swarm-launcher$ python3 -m poetry run ap-sitl-swarm -n 20 --num-drones-per-row 5 --spacing 5 --pos-noise 0.5 --yaw-noise 10 ../ardupilot/build/sitl/bin/arducopter
    1 | Setting SIM_SPEEDUP=1.000000
    1 | Suggested EK3_BCOEF_* = 16.288, EK3_MCOEF = 0.209
    1 | Home: -35.363254 149.165234 alt=584.000000m hdg=345.000000
    1 | Starting sketch 'ArduCopter'
    1 | Starting SITL input
    1 | Using Irlock at port : 9005
    1 | UDP connection 127.0.0.1:14550
    1 | Loaded defaults from /tmp/sitl-swarm-kkeeabzu/drones/001/default.param
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kkeeabzu/drones/019/default.param
   20 | validate_structures:476: Validating structures
   20 | Loaded defaults from /tmp/sitl-swarm-kkeeabzu/drones/020/default.param
```

## Launch Skybrush live
1.Back to Host OS(wiundows11), download Skybrush live [Installer](https://skybrush.io/modules/live/) and install.

2.Launch Skybrush live
* If you can see drones, it's showtime!
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s9sw5zt7xnvakicfdh7n.png)