> For the complete documentation index, see [llms.txt](https://dennisbaldwin.gitbook.io/airsim-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dennisbaldwin.gitbook.io/airsim-notes/px4-hitl-testing.md).

# PX4 HITL Testing w/ AirSim

Notes on using Pixhawk and PX4 firmware for hardware-in-the-loop testing with AirSIM

There are few important key steps that need to be done to ensure success:

* Load PX4 firmware onto Pixhawk with [QGroundControl](http://qgroundcontrol.com/). As of 1/20/2021 [PX4 firmware version 1.9.2](https://github.com/PX4/PX4-Autopilot/releases/tag/v1.9.2) has been confirmed to work. Use any newer versions at your own risk.
* After loading firmware Pixhawk will reboot and QGC will reconnect. Go to Airframe and select **HIL Quadcopter X** Airframe:

![](https://770603035-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQhVAJGyUbmqdAExB6g%2F-MRVgOGqDLXUrKM_QiTB%2F-MRVhFZqxbKzljS1UmLZ%2Fhil_quadcopter_x.jpg?alt=media\&token=0fca6faf-232a-42aa-93b7-d8ebb7a9cb30)

* Bind your RX/TX (In my case this is Taranis QX7 and FrSky RX4R)
* Calibrate your radio in QGroundControl (this tutorial was tested with Taranis QX7)
* Setup flight modes in QGC. These are ones that I used for testing purposes and setup on Channel 5:
  * Stabilize
  * Altitude
  * Land
  * RTL

![](https://770603035-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQhVAJGyUbmqdAExB6g%2F-MRVhp4b6XjC2I642j9b%2F-MRViMEHA6p0msjrY7MC%2Fflight_modes.jpg?alt=media\&token=264a3239-8781-4b57-8f86-564699a8cb49)

* Download one of the AirSim builds and open it then close it. This will create a [settings.json](https://microsoft.github.io/AirSim/settings/#using-px4) file in your user documents directory. You'll then need to modify it with the following params:

```
{
  "SeeDocsAt": "https://github.com/Microsoft/AirSim/blob/master/docs/settings.md",
  "SettingsVersion": 1.2,
  "LogMessagesVisible": true,
  "SimMode": "Multirotor",
  "Vehicles": {
    "PX4": {
      "VehicleType": "PX4Multirotor",
      "UseSerial": true,
      "Parameters": {
          "NAV_RCL_ACT": 0,
          "NAV_DLL_ACT": 0,
          "LPE_LAT": 47.641468,
          "LPE_LON": -122.140165,
          "COM_OBL_ACT": 1
      }
    }
  }
}
```

* Make sure AirSim is still closed and power up your TX
* Connect Pixhawk via USB to your computer
* Launch AirSim and voila!

![](https://770603035-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MQhVAJGyUbmqdAExB6g%2F-MRfBdfJS-zurFzdbEEB%2F-MRfEdwd__DohYBscjx6%2Fready_for_takeoff.jpg?alt=media\&token=6fd03503-f263-4d21-a4a5-7b8f4d295b68)
