Hamish Willee 88d623bedb
Move PX4 Guide source into /docs (#24490)
* Add vitepress tree

* Update existing workflows so they dont trigger on changes in the docs path

* Add nojekyll, package.json, LICENCE etc

* Add crowdin docs upload/download scripts

* Add docs flaw checker workflows

* Used docs prefix for docs workflows

* Crowdin obvious fixes

* ci: docs move to self hosted runner

runs on a beefy server for faster builds

Signed-off-by: Ramon Roche <mrpollo@gmail.com>

* ci: don't run build action for docs or ci changes

Signed-off-by: Ramon Roche <mrpollo@gmail.com>

* ci: update runners

Signed-off-by: Ramon Roche <mrpollo@gmail.com>

* Add docs/en

* Add docs assets and scripts

* Fix up editlinks to point to PX4 sources

* Download just the translations that are supported

* Add translation sources for zh, uk, ko

* Update latest tranlsation and uorb graphs

* update vitepress to latest

---------

Signed-off-by: Ramon Roche <mrpollo@gmail.com>
Co-authored-by: Ramon Roche <mrpollo@gmail.com>
2025-03-13 16:08:27 +11:00

166 lines
7.6 KiB
Markdown

# Hardware in the Loop Simulation (HITL)
:::warning
HITL is [community supported and maintained](../simulation/community_supported_simulators.md).
It may or may not work with current versions of PX4.
See [Toolchain Installation](../dev_setup/dev_env.md) for information about the environments and tools supported by the core development team.
:::
Hardware-in-the-Loop (HITL or HIL) is a simulation mode in which normal PX4 firmware is run on real flight controller hardware.
This approach has the benefit of testing most of the actual flight code on the real hardware.
PX4 supports HITL for multicopters (using [jMAVSim](../sim_jmavsim/index.md) or [Gazebo Classic](../sim_gazebo_classic/index.md)) and VTOL (using Gazebo Classic).
<a id="compatible_airframe"></a>
## HITL-Compatible Airframes
The set of compatible airframes vs simulators is:
| Airframe | `SYS_AUTOSTART` | Gazebo Classic | jMAVSim |
| ---------------------------------------------------------------------------------------------------------------- | --------------- | -------------- | ------- |
| [HIL Quadcopter X](../airframes/airframe_reference.md#copter_simulation_hil_quadcopter_x) | 1001 | Y | Y |
| [HIL Standard VTOL QuadPlane](../airframes/airframe_reference.md#vtol_standard_vtol_hil_standard_vtol_quadplane) | 1002 | Y |
| [Generic Quadrotor x](../airframes/airframe_reference.md#copter_quadrotor_x_generic_quadcopter) copter | 4001 | Y | Y |
<a id="simulation_environment"></a>
## HITL Simulation Environment
With Hardware-in-the-Loop (HITL) simulation the normal PX4 firmware is run on real hardware.
JMAVSim or Gazebo Classic (running on a development computer) are connected to the flight controller hardware via USB/UART.
The simulator acts as gateway to share MAVLink data between PX4 and _QGroundControl_.
::: info
The simulator can also be connected via UDP if the flight controller has networking support and uses a stable, low-latency connection (e.g. a wired Ethernet connection - WiFi is usually not sufficiently reliable).
For example, this configuration has been tested with PX4 running on a Raspberry Pi connected via Ethernet to the computer (a startup configuration that includes the command for running jMAVSim can be found [here](https://github.com/PX4/PX4-Autopilot/blob/main/posix-configs/rpi/px4_hil.config)).
:::
The diagram below shows the simulation environment:
- A HITL configuration is selected (via _QGroundControl_) that doesn't start any real sensors.
- _jMAVSim_ or _Gazebo Classic_ are connected to the flight controller via USB.
- The simulator is connected to _QGroundControl_ via UDP and bridges its MAVLink messages to PX4.
- _Gazebo Classic_ and _jMAVSim_ can also connect to an offboard API and bridge MAVLink messages to PX4.
- (Optional) A serial connection can be used to connect Joystick/Gamepad hardware via _QGroundControl_.
![HITL Setup - jMAVSim and Gazebo Classic](../../assets/simulation/px4_hitl_overview_jmavsim_gazebo.svg)
## HITL vs SITL
SITL runs on a development computer in a simulated environment, and uses firmware specifically generated for that environment.
Other than simulation drivers to provide fake environmental data from the simulator the system behaves normally.
By contrast, HITL runs normal PX4 firmware in "HITL mode", on normal hardware.
The simulation data enters the system at a different point than for SITL.
Core modules like commander and sensors have HITL modes at startup that bypass some of the normal functionality.
In summary, HITL runs PX4 on the actual hardware using standard firmware, but SITL actually executes more of the standard system code.
## Setting up HITL
### PX4 Configuration
1. Connect the autopilot directly to _QGroundControl_ via USB.
1. Enable HITL Mode
1. Open **Setup > Safety** section.
1. Enable HITL mode by selecting **Enabled** from the _HITL Enabled_ list:
![QGroundControl HITL configuration](../../assets/gcs/qgc_hitl_config.png)
1. Select Airframe
1. Open **Setup > Airframes**
1. Select a [compatible airframe](#compatible_airframe) you want to test.
Then click **Apply and Restart** on top-right of the _Airframe Setup_ page.
![Select Airframe](../../assets/gcs/qgc_hil_config.png)
1. Calibrate your RC or Joystick, if needed.
1. Setup UDP
1. Under the _General_ tab of the settings menu, uncheck all _AutoConnect_ boxes except for **UDP**.
![QGC Auto-connect settings for HITL](../../assets/gcs/qgc_hitl_autoconnect.png)
1. (Optional) Configure Joystick and Failsafe.
Set the following [parameters](../advanced_config/parameters.md) in order to use a joystick instead of an RC remote control transmitter:
- [COM_RC_IN_MODE](../advanced_config/parameter_reference.md#COM_RC_IN_MODE) to "Joystick/No RC Checks". This allows joystick input and disables RC input checks.
- [NAV_RCL_ACT](../advanced_config/parameter_reference.md#NAV_RCL_ACT) to "Disabled". This ensures that no RC failsafe actions interfere when not running HITL with a radio control.
:::tip
The _QGroundControl User Guide_ also has instructions on [Joystick](https://docs.qgroundcontrol.com/master/en/qgc-user-guide/setup_view/joystick.html) and [Virtual Joystick](https://docs.qgroundcontrol.com/master/en/qgc-user-guide/settings_view/virtual_joystick.html) setup.
:::
Once configuration is complete, **close** _QGroundControl_ and disconnect the flight controller hardware from the computer.
### Simulator-Specific Setup
Follow the appropriate setup steps for the specific simulator in the following sections.
#### Gazebo Classic
::: info
Make sure _QGroundControl_ is not running!
:::
1. Build PX4 with [Gazebo Classic](../sim_gazebo_classic/index.md) (in order to build the Gazebo Classic plugins).
```sh
cd <Firmware_clone>
DONT_RUN=1 make px4_sitl_default gazebo-classic
```
1. Open the vehicle model's sdf file (e.g. **Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/iris_hitl/iris_hitl.sdf**).
1. Replace the `serialDevice` parameter (`/dev/ttyACM0`) if necessary.
::: info
The serial device depends on what port is used to connect the vehicle to the computer (this is usually `/dev/ttyACM0`).
An easy way to check on Ubuntu is to plug in the autopilot, open up a terminal, and type `dmesg | grep "tty"`.
The correct device will be the last one shown.
:::
1. Set up the environment variables:
```sh
source Tools/simulation/gazebo-classic/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default
```
and run Gazebo Classic in HITL mode:
```sh
gazebo Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds/hitl_iris.world
```
1. Start _QGroundControl_.
It should autoconnect to PX4 and Gazebo Classic.
#### jMAVSim (Quadrotor only)
::: info
Make sure _QGroundControl_ is not running!
:::
1. Connect the flight controller to the computer and wait for it to boot.
1. Run jMAVSim in HITL mode:
```sh
./Tools/simulation/jmavsim/jmavsim_run.sh -q -s -d /dev/ttyACM0 -b 921600 -r 250
```
::: info
Replace the serial port name `/dev/ttyACM0` as appropriate.
On macOS this port would be `/dev/tty.usbmodem1`.
On Windows (including Cygwin) it would be the COM1 or another port - check the connection in the Windows Device Manager.
:::
1. Start _QGroundControl_.
It should autoconnect to PX4 and jMAVSim.
## Fly an Autonomous Mission in HITL
You should be able to use _QGroundControl_ to [run missions](https://docs.qgroundcontrol.com/master/en/qgc-user-guide/fly_view/fly_view.html#missions) and otherwise control the vehicle.