> For the complete documentation index, see [llms.txt](https://cloudkerneltech.gitbook.io/kerlouduav/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cloudkerneltech.gitbook.io/kerlouduav/userguide/tutorial/airsim_hil_sim.md).

# Hardware-in-the-loop Simulation in Airsim Environment

**Note: This tutorial is part of our** [Kerloud DASA service](https://kerloud-dasa.readthedocs.io/)

## Background

![](/files/ASVPWyOpmQaRYQcrUB4q)

[Airsim](https://microsoft.github.io/AirSim/) is an open source project created by Microsoft in 2017, and it serves as a simulation platform that supports autonomous drones and cars. The platform is built on [Unreal Engine](https://www.unrealengine.com) with superior 3D visualization effect and high fidelity physics engine. So it offers high-end users an alternative solution to existing tools like Gazebo and jMAVsim, and enables fantastic simulation scenarios that are comparable with those in games and movies.

The hardware-in-the-loop (HIL) simulation is another simulation mode supported by PX4 firmware. Different with the SITL simulation mentioned in the previous [offboard control tutorial](https://cloudkerneltech.gitbook.io/kerlouduav/userguide/tutorial/offboard), the flight control firmware is run on the real autopilot, hence all code can be tested onboard. The simulation method can accelerate greatly our software development and reduce experiment risks.

This tutorial provides a starting point for interested users to familiarize the Airsim environment and interface with our Kerloud autopilots in the hardware level.

## Prerequisites

Necessary tools are listed as below with full test:

* [Kerloud autopilot](http://cloudkernel-tech.gitee.io/kerloud-autopilot/) : firmware version >= v1.10.0
* A RC receiver and a transmitter
* A powerful personal computer

The recommended PC hardware requirement can be referred [here](https://docs.unrealengine.com/4.27/en-US/Basics/InstallingUnrealEngine/RecommendedSpecifications/). In our case, the hardware details are: CPU (Intel i7-13700KF), video card (Nvidia Geforce RTX 3060), hard drive (1TB SSD) and 32GB RAM memory. The PC is installed with Ubuntu 18.04 and Unreal Engine 4.27 plus.

## Experiment Setup

### Autopilot Setup

The HIL mode of the Kerloud autopilot can be set up following the instruction in <https://docs.px4.io/main/en/simulation/hitl.html>. For short, the HIL mode is enabled, and the QGroundcontrol station should be configured with UDP communication only. The autopilot will communicate mavlink messages with the airsim platform via its USB port.

### Airsim Software

The airsim platform is built from source in our PC following the [guide](https://microsoft.github.io/AirSim/build_linux/). Here we use the source code from the latest main branch (commit date: 2022-7-21). Users are suggested to play with the Block environment for initial test. We use a customized environment using the landscape mountain content from the marketplace in Epic Games, and the details can be referred in <https://microsoft.github.io/AirSim/unreal_custenv/>. The environment view is shown as below:

![](/files/ejJf4pviErGNZ1lc2CQK)

After copying the Airsim plugin folder to the customized project, we can start the simulation with simply a click on the "Play" button. The default quadrotor vehicle can show up just like real.

![](/files/Jg6f3Rmz1CDEDyPlXVCX)

## Demonstration

The demonstration of remote manual control in the airsim platform can be viewed in the video below:

[video link](https://www.bilibili.com/video/BV1CT411y7CJ)

{% embed url="<https://www.bilibili.com/video/BV1CT411y7CJ>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cloudkerneltech.gitbook.io/kerlouduav/userguide/tutorial/airsim_hil_sim.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
