# Agile flight with optimization embedded networks

## 1. Setup

All the tests are conducted in the Linux environment on a computer equipped with an Intel Core i7-10700 CPU and a GeForce RTX 2060 GPU.

Moreover, our software is developed and tested in Ubuntu 18.04, 20.04 with ROS installed.

ROS can be installed here: [ROS Installation](http://wiki.ros.org/ROS/Installation).

To build this project, ensure that you have the following dependencies installed:&#x20;

-[Eigen](https://eigen.tuxfamily.org/index.php?title=Main_Page): A high-level C++ library for linear algebra operations.

-[CUDNN](https://developer.nvidia.com/cudnn): A GPU-accelerated library of primitives for deep neural networks

Furthermore, as we necessitate invoking models generated by [PyTorch](https://pytorch.org/get-started/locally/) in C++, we require the utilization of [LibTorch](https://pytorch.org/cppdocs/installing.html). Within this project, we are utilizing PyTorch version **2.0.1** alongside [CUDA](https://developer.nvidia.com/cuda-toolkit) **11.7**. Hence, it is imperative to install the corresponding version of LibTorch, as discrepancies in versions might render the models inoperable. To facilitate your workflow, we have already prepared the compatible version of LibTorch ([here](https://github.com/agile-flight-with-opt-embedded-nets/models/releases/download/libtorch/libtorch-2.0.1-cu117.zip)) within this project ,**strongly advocating for its direct usage to circumvent version incompatibilities**.

## 2. Test it in ROS.

1. Download our [Libtorch](https://github.com/agile-flight-with-opt-embedded-nets/models/releases/download/libtorch/libtorch-2.0.1-cu117.zip) and extract it in your home directory, then add the corresponding paths to `~/.bashrc` :

​     `export Torch_DIR=/home/your_usrname/libtorch/share/cmake/Torch`. Then, source it:

```bash
source ~/.bashrc
```

2. Unzip the project and go to the corresponding directory.

```bash
cd ~/AFOEN
```

3. Compile it.

```bash
catkin_make -DCMAKE_BUILD_TYPE=Release
```

Note: In case errors related to CUDA or LibTorch arise during the compilation process, kindly review the following two CMakeLists files: `src/planner/plan_manage/CMakeLists.txt` and `src/uav_simulator/local_sensing/CMakeLists.txt`, to ensure that the paths for CUDA and LibTorch are accurately configured as per your setup. We recommend aligning your use of CUDA versions with ours. The corresponding compilation information is as follows:

**NOTE:** Please refer to [cuda wiki](https://en.wikipedia.org/wiki/CUDA) to select  right version of compute capability. For example, RTX2060 corresponds to version 75.

![compile](figs/compile.png)

4. Download the simulation point cloud and the  model.

   Download the [point cloud](https://github.com/agile-flight-with-opt-embedded-nets/models/blob/master/env.pcd) and put it in `src/uav_simulator/map_generator/env/env.pcd`.

   Download the [model file](https://github.com/agile-flight-with-opt-embedded-nets/models/blob/master/full_jit_muti_tune.pt) and put it in `src/planner/plan_manage/models/full_jit_muti_tune.pt`.

   ps: If you want to run Iplanner in this project, you  also need to download the corresponding [model file](https://github.com/agile-flight-with-opt-embedded-nets/models/blob/master/full_jit_iplanner.pt) and place it:

   `src/planner/plan_manage/models/full_jit_iplanner.pt`

5. Run it.

Open a new terminal window, `cd ` to `cd ~/AFOEN` and type:

```bash
source devel/setup.bash
```

Then, run the script:

```bash
./src/run.sh 
```


If all goes well, after about ten seconds of waiting, you can see our method of controlling the drone navigating through the environment at high speed!

![demo](figs/demo.png)

