mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 07:03:33 +08:00
docs(sim): restructure hardware sim pages and add SIH docs
Co-authored-by: Hamish Willee <hamishwillee@gmail.com> Signed-off-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
co-authored by
Hamish Willee
parent
01dd41b7e8
commit
1d80fc317e
@@ -12,10 +12,13 @@ See [Toolchain Installation](../dev_setup/dev_env.md) for information about the
|
||||
The tools have variable levels of support from their communities (some are well supported and others are not).
|
||||
Questions about these tools should be raised on the [discussion forums](../contribute/support.md#forums-and-chat)
|
||||
|
||||
| Simulator | Description |
|
||||
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| [Simulation-In-Hardware](../sim_sih/index.md) (SIH) | <p>A simulator implemented in C++ as a PX4 module directly in the Firmware [code](https://github.com/PX4/PX4-Autopilot/tree/main/src/modules/simulation/simulator_sih). It can be ran in SITL directly on the computer or as an alternative to HITL offering a hard real-time simulation directly on the hardware autopilot. </p><p><strong>Supported Vehicles:</strong> Quad, Hexa, Plane, Tailsitter, Standard VTOL, Ackermann Rover</p> |
|
||||
| [FlightGear](../sim_flightgear/index.md) | <p>A simulator that provides physically and visually realistic simulations. In particular it can simulate many weather conditions, including thunderstorms, snow, rain and hail, and can also simulate thermals and different types of atmospheric flows. [Multi-vehicle simulation](../sim_flightgear/multi_vehicle.md) is also supported.</p> <p><strong>Supported Vehicles:</strong> Plane, Autogyro, Rover</p> |
|
||||
| [JMAVSim](../sim_jmavsim/index.md) | <p>A simple multirotor/quad simulator. This was previously part of the PX4 development toolchain but was removed in favour of [Gazebo](../sim_gazebo_gz/index.md).</p> <p><strong>Supported Vehicles:</strong> Quad</p> |
|
||||
| [JSBSim](../sim_jsbsim/index.md) | <p>A simulator that provides advanced flight dynamics models. This can be used to model realistic flight dynamics based on wind tunnel data.</p> <p><strong>Supported Vehicles:</strong> Plane, Quad, Hex</p> |
|
||||
| [AirSim](../sim_airsim/index.md) | <p>A cross platform simulator that provides physically and visually realistic simulations. This simulator is resource intensive, and requires a significantly more powerful computer than the other simulators described here.</p><p><strong>Supported Vehicles:</strong> Iris (MultiRotor model and a configuration for PX4 QuadRotor in the X configuration).</p> |
|
||||
| Simulator | Description |
|
||||
| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| [FlightGear](../sim_flightgear/index.md) | <p>A simulator that provides physically and visually realistic simulations. In particular it can simulate many weather conditions, including thunderstorms, snow, rain and hail, and can also simulate thermals and different types of atmospheric flows. [Multi-vehicle simulation](../sim_flightgear/multi_vehicle.md) is also supported.</p> <p><strong>Supported Vehicles:</strong> Plane, Autogyro, Rover</p> |
|
||||
| [JMAVSim](../sim_jmavsim/index.md) | <p>A simple multirotor/quad simulator. This was previously part of the PX4 development toolchain but was removed in favour of [Gazebo](../sim_gazebo_gz/index.md).</p> <p><strong>Supported Vehicles:</strong> Quad</p> |
|
||||
| [JSBSim](../sim_jsbsim/index.md) | <p>A simulator that provides advanced flight dynamics models. This can be used to model realistic flight dynamics based on wind tunnel data.</p> <p><strong>Supported Vehicles:</strong> Plane, Quad, Hex</p> |
|
||||
| [AirSim](../sim_airsim/index.md) | <p>A cross platform simulator that provides physically and visually realistic simulations. This simulator is resource intensive, and requires a significantly more powerful computer than the other simulators described here.</p><p><strong>Supported Vehicles:</strong> Iris (MultiRotor model and a configuration for PX4 QuadRotor in the X configuration).</p> |
|
||||
|
||||
:::tip
|
||||
[Gazebo](../sim_gazebo_gz/index.md) and [SIH](../sim_sih/index.md) are the officially supported simulators. See the [Simulation](index.md) page for more information.
|
||||
:::
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# Hardware Simulation
|
||||
|
||||
PX4 can run simulation directly on a real flight controller, replacing real sensors with simulated data, while otherwise executing the full flight stack on actual autopilot hardware.
|
||||
|
||||
::: info
|
||||
Simulating PX4 on flight controller hardware exercises more flight stack code than SITL, and tests more of your hardware integration.
|
||||
It can surface issues with running PX4 that might hidden when running on a desktop OS and hardware, or even a different flight controller board.
|
||||
:::
|
||||
|
||||
Two simulation approaches are available, controlled by the [SYS_HITL](../advanced_config/parameter_reference.md#SYS_HITL) parameter:
|
||||
|
||||
- **[HITL Simulation](../simulation/hitl.md) (`SYS_HITL=1`):** An external simulator (Gazebo Classic or jMAVSim) runs physics on a companion computer and sends sensor data to the flight controller via MAVLink HIL messages. Requires a USB/UART connection and simulator setup.
|
||||
- **[SIH on Hardware](../sim_sih/hardware.md) (`SYS_HITL=2`):** A C++ physics model runs directly on the flight controller itself. No external simulator, no companion computer, no MAVLink sensor data. Just set the parameter and reboot.
|
||||
|
||||
## HITL vs SIH {#comparision}
|
||||
|
||||
| | HITL (`SYS_HITL=1`) | SIH (`SYS_HITL=2`) |
|
||||
| ----------------- | -------------------------------------------- | ---------------------------------------------------- |
|
||||
| Physics model | External simulator (Gazebo Classic, jMAVSim) | Internal C++ module |
|
||||
| Communication | MAVLink HIL messages | uORB (internal) |
|
||||
| External process | Required | Not required |
|
||||
| Setup complexity | Higher | Lower |
|
||||
| Sensor simulation | Camera, lidar, etc. (via simulator) | IMU, GPS, baro, mag, airspeed only |
|
||||
| Vehicle types | Quadcopter, Standard VTOL | Quad, Hex, FW, VTOL Tailsitter, Standard VTOL, Rover |
|
||||
|
||||
## When to Use Which
|
||||
|
||||
- Use **SIH** if you want the simplest possible setup. No external dependencies.
|
||||
- Use **HITL** if you need an external physics engine, 3D visualization from Gazebo Classic, or camera/lidar sensor simulation that SIH does not provide.
|
||||
+10
-12
@@ -12,20 +12,18 @@ This approach has the benefit of testing most of the actual flight code on the r
|
||||
|
||||
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>
|
||||
For a comparison of HITL and SIH on hardware, see [Hardware Simulation](../simulation/hardware.md).
|
||||
|
||||
## HITL-Compatible Airframes
|
||||
## HITL-Compatible Airframes {#compatible_airframe}
|
||||
|
||||
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 |
|
||||
| [HIL Standard VTOL QuadPlane](../airframes/airframe_reference.md#vtol_standard_vtol_hil_standard_vtol_quadplane) | 1002 | Y | |
|
||||
|
||||
<a id="simulation_environment"></a>
|
||||
|
||||
## HITL Simulation Environment
|
||||
## HITL Simulation Environment {#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.
|
||||
@@ -135,8 +133,8 @@ Make sure _QGroundControl_ is not running!
|
||||
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.
|
||||
2. Open the vehicle model's sdf file (e.g. **Tools/simulation/gazebo-classic/sitl_gazebo-classic/models/iris_hitl/iris_hitl.sdf**).
|
||||
3. 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`).
|
||||
@@ -144,7 +142,7 @@ Make sure _QGroundControl_ is not running!
|
||||
The correct device will be the last one shown.
|
||||
:::
|
||||
|
||||
1. Set up the environment variables:
|
||||
4. Set up the environment variables:
|
||||
|
||||
```sh
|
||||
source Tools/simulation/gazebo-classic/setup_gazebo.bash $(pwd) $(pwd)/build/px4_sitl_default
|
||||
@@ -156,7 +154,7 @@ Make sure _QGroundControl_ is not running!
|
||||
gazebo Tools/simulation/gazebo-classic/sitl_gazebo-classic/worlds/hitl_iris.world
|
||||
```
|
||||
|
||||
1. Start _QGroundControl_.
|
||||
5. Start _QGroundControl_.
|
||||
It should autoconnect to PX4 and Gazebo Classic.
|
||||
|
||||
#### jMAVSim (Quadrotor only)
|
||||
@@ -166,7 +164,7 @@ 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:
|
||||
2. Run jMAVSim in HITL mode:
|
||||
|
||||
```sh
|
||||
./Tools/simulation/jmavsim/jmavsim_run.sh -q -s -d /dev/ttyACM0 -b 921600 -r 250
|
||||
@@ -178,7 +176,7 @@ Make sure _QGroundControl_ is not running!
|
||||
On Windows (including Cygwin) it would be the COM1 or another port - check the connection in the Windows Device Manager.
|
||||
:::
|
||||
|
||||
1. Start _QGroundControl_.
|
||||
3. Start _QGroundControl_.
|
||||
It should autoconnect to PX4 and jMAVSim.
|
||||
|
||||
## Fly an Autonomous Mission in HITL
|
||||
|
||||
+61
-11
@@ -3,38 +3,79 @@
|
||||
Simulators allow PX4 flight code to control a computer modeled vehicle in a simulated "world".
|
||||
You can interact with this vehicle just as you might with a real vehicle, using _QGroundControl_, an offboard API, or a radio controller/gamepad.
|
||||
|
||||
:::tip
|
||||
Simulation is a quick, easy, and most importantly, _safe_ way to test changes to PX4 code before attempting to fly in the real world.
|
||||
It is also a good way to start flying with PX4 when you haven't yet got a vehicle to experiment with.
|
||||
:::
|
||||
|
||||
PX4 supports both _Software In the Loop (SITL)_ simulation, where the flight stack runs on computer (either the same computer or another computer on the same network) and _Hardware In the Loop (HITL)_ simulation using a simulation firmware on a real flight controller board.
|
||||
|
||||
Information about available simulators and how to set them up are provided in the next section.
|
||||
The other sections provide general information about how the simulator works, and are not required to _use_ the simulators.
|
||||
|
||||
:::tip
|
||||
Simulation is a quick, easy, and most importantly, _safe_ way to test changes to PX4 code before attempting to fly in the real world.
|
||||
It is also a good way to start flying with PX4 when you haven't yet got a vehicle to experiment with.
|
||||
:::
|
||||
|
||||
## Supported Simulators
|
||||
|
||||
The following simulators are supported by the PX4 core development team.
|
||||
|
||||
:::info
|
||||
Gazebo Classic is being downgraded to [community supported](../simulation/community_supported_simulators.md) and is no longer recommended as the default simulation solution.
|
||||
Use [Gazebo](../sim_gazebo_gz/index.md) (formerly Gazebo Ignition) for new projects.
|
||||
If you have an older workflow that does not yet work in newer Gazebo, Gazebo Classic remains available but will not receive core team maintenance going forward.
|
||||
See [PX4-Autopilot#23602](https://github.com/PX4/PX4-Autopilot/issues/23602) for the deprecation timeline and migration status.
|
||||
:::
|
||||
|
||||
| Simulator | Description |
|
||||
| ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [Gazebo](../sim_gazebo_gz/index.md) | Gazebo supersedes [Gazebo Classic](../sim_gazebo_classic/index.md), featuring more advanced rendering, physics and sensor models. It is the only version of Gazebo available from Ubuntu Linux 22.04<br><br>A powerful 3D simulation environment that is particularly suitable for testing object-avoidance and computer vision. It can also be used for [multi-vehicle simulation](../simulation/multi-vehicle-simulation.md) and is commonly used with [ROS](../simulation/ros_interface.md), a collection of tools for automating vehicle control. <br><br><strong>Supported Vehicles:</strong> Quad, VTOL (Standard, Tailsitter, Tiltroter), Plane, Rovers |
|
||||
| [Gazebo Classic](../sim_gazebo_classic/index.md) | A powerful 3D simulation environment that is particularly suitable for testing object-avoidance and computer vision. It can also be used for [multi-vehicle simulation](../simulation/multi-vehicle-simulation.md) and is commonly used with [ROS](../simulation/ros_interface.md), a collection of tools for automating vehicle control.<br><br>**Supported Vehicles:** Quad ([Iris](../airframes/airframe_reference.md#copter_quadrotor_x_generic_quadcopter)), Hex (Typhoon H480), [Generic Standard VTOL (QuadPlane)](../airframes/airframe_reference.md#vtol_standard_vtol_generic_standard_vtol), Tailsitter, Plane, Rover, Submarine |
|
||||
| [SIH](../sim_sih/index.md) | A lightweight, headless simulator that runs physics directly inside PX4 as a C++ module (no external dependencies). Headless by default for fastest iteration. Supports ROS 2 via uXRCE-DDS. Can also run on flight controller hardware (`SYS_HITL=2`).<br><br>**Supported Vehicles:** Quad, Hex, Plane, Tailsitter, Standard VTOL, Rover |
|
||||
|
||||
There are also a number of [Community Supported Simulators](../simulation/community_supported_simulators.md).
|
||||
|
||||
---
|
||||
### Simulator Comparison
|
||||
|
||||
The remainder of this topic is a "somewhat generic" description of how the simulation infrastructure works.
|
||||
It is not required to _use_ the simulators.
|
||||
| Feature | Gazebo | SIH |
|
||||
| ------------------------- | ----------------------------------------- | ------------------------------------------------------------------- |
|
||||
| **Default Mode** | GUI with 3D rendering | Headless (fastest iteration) |
|
||||
| **3D Visualization** | Built-in (photorealistic) | Optional: QGC map or jMAVSim display-only |
|
||||
| **Physics Engine** | External (gz-physics) | Internal (C++ module, uORB) |
|
||||
| **External Dependencies** | Gazebo packages, rendering libs | None |
|
||||
| **Vehicle Types** | Quad, VTOL, Plane, Rovers | Quad, Hex, Plane, Tailsitter, Std VTOL, Rover |
|
||||
| **Multi-vehicle** | Yes (documented) | Yes ([multi-vehicle](../sim_sih/index.md#multi-vehicle-simulation)) |
|
||||
| **Sensor Simulation** | Camera, LiDAR, depth, IMU, GPS, baro, mag | IMU, GPS, baro, mag, airspeed |
|
||||
| **Custom Worlds/Models** | Yes (SDF, large model library) | No |
|
||||
| **ROS 2 Integration** | Yes (uXRCE-DDS) | Yes (uXRCE-DDS) |
|
||||
| **Extensibility** | Plugins, custom sensors, environments | Modify C++ source, tune SIH\_\* parameters |
|
||||
| **Community/Ecosystem** | Large Gazebo community, model repos | PX4-internal |
|
||||
| **Faster-than-Realtime** | Yes | Yes |
|
||||
| **Runs on FC Hardware** | No | Yes (SYS_HITL=2) |
|
||||
| **macOS Apple Silicon** | Unstable (known issues) | Works natively |
|
||||
| **Lockstep** | Yes | Yes |
|
||||
|
||||
:::tip
|
||||
For a detailed analysis of PX4 simulation user needs, priorities, and pain points, see the [PX4 Simulation Integration Survey Report](https://www.mcguirerobotics.com/px4_sim_research_report/) (K. McGuire, Dronecode Foundation, Dec 2025, 120 respondents).
|
||||
:::
|
||||
|
||||
### Which Simulator Should I Use?
|
||||
|
||||
- **Full-featured simulation with 3D rendering, custom worlds, camera/lidar sensors, or rich sensor ecosystems:** Use [Gazebo](../sim_gazebo_gz/index.md). Largest ecosystem, custom models and plugins, photorealistic rendering, extensive sensor library, large community.
|
||||
- **Fast headless iteration, controls research, zero-dependency setup, or macOS:** Use [SIH](../sim_sih/index.md). Runs entirely inside PX4 with no external dependencies, headless by default for maximum speed, physics parameters directly tunable via `SIH_*` params. Supports ROS 2 via uXRCE-DDS.
|
||||
- **Hardware integration testing without propellers:** Use [SIH on flight controller hardware](../sim_sih/index.md#sih-on-flight-controller-hardware) (`SYS_HITL=2`).
|
||||
|
||||
:::info
|
||||
SIH is headless by default. For optional 3D visualization, you can use [jMAVSim in display-only mode](../sim_sih/index.md#visualization-optional) or monitor the vehicle in QGroundControl's map view.
|
||||
:::
|
||||
|
||||
## Simulator MAVLink API
|
||||
|
||||
All simulators except for Gazebo communicate with PX4 using the Simulator MAVLink API.
|
||||
Most external simulators communicate with PX4 using the Simulator MAVLink API.
|
||||
This API defines a set of MAVLink messages that supply sensor data from the simulated world to PX4 and return motor and actuator values from the flight code that will be applied to the simulated vehicle.
|
||||
The image below shows the message flow.
|
||||
|
||||
:::info
|
||||
SIH does not use the MAVLink simulator API. It runs physics internally via uORB messages. Gazebo communicates with PX4 via gz_bridge (Gazebo transport), not MAVLink.
|
||||
:::
|
||||
|
||||

|
||||
|
||||
::: info
|
||||
@@ -95,7 +136,7 @@ See [System Startup](../concept/system_startup.md) to learn more.
|
||||
|
||||
## SITL Simulation Environment
|
||||
|
||||
The diagram below shows a typical SITL simulation environment for any of the supported simulators that use MAVLink (i.e. all of them except Gazebo).
|
||||
The diagram below shows a typical SITL simulation environment for any of the supported simulators that use MAVLink (i.e. most external simulators, but not Gazebo or SIH).
|
||||
|
||||

|
||||
|
||||
@@ -149,8 +190,16 @@ make px4_sitl jmavsim
|
||||
|
||||
# Start PX4 with no simulator (i.e. to use your own "custom" simulator)
|
||||
make px4_sitl none_iris
|
||||
|
||||
# SIH (headless, zero dependencies)
|
||||
make px4_sitl_sih sihsim_quadx
|
||||
make px4_sitl_sih sihsim_airplane
|
||||
```
|
||||
|
||||
::: info
|
||||
Use `px4_sitl_sih` instead of `px4_sitl` to avoid building Gazebo dependencies.
|
||||
:::
|
||||
|
||||
The simulation can be further configured via environment variables:
|
||||
|
||||
- Any of the [PX4 parameters](../advanced_config/parameter_reference.md) can be overridden via `export PX4_PARAM_{name}={value}`.
|
||||
@@ -161,7 +210,7 @@ For more information see: [Building the Code > PX4 Make Build Targets](../dev_se
|
||||
|
||||
### Run Simulation Faster than Realtime {#simulation_speed}
|
||||
|
||||
SITL can be run faster or slower than real-time when using Gazebo, Gazebo Classic, or jMAVSim.
|
||||
SITL can be run faster or slower than real-time when using Gazebo, Gazebo Classic, jMAVSim, or SIH.
|
||||
|
||||
The speed factor is set using the environment variable `PX4_SIM_SPEED_FACTOR`.
|
||||
|
||||
@@ -175,6 +224,7 @@ For more information see:
|
||||
- Gazebo: [Change Simulation Speed](../sim_gazebo_gz/index.md#change-simulation-speed)
|
||||
- Gazebo Classic: [Change Simulation Speed](../sim_gazebo_classic/index.md#change-simulation-speed) and [Lockstep](../sim_gazebo_classic/index.md#lockstep)
|
||||
- jMAVSim: [Change Simulation Speed](../sim_jmavsim/index.md#change-simulation-speed) and [Lockstep](../sim_jmavsim/index.md#lockstep)
|
||||
- SIH: Supports `PX4_SIM_SPEED_FACTOR` for faster-than-realtime simulation.
|
||||
|
||||
### Startup Scripts
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ PX4 supports multi-vehicle simulation using the following simulators:
|
||||
- [Multi-Vehicle Sim with Gazebo Classic](../sim_gazebo_classic/multi_vehicle_simulation.md) (both with and without ROS)
|
||||
- [Multi-Vehicle Sim with FlightGear](../sim_flightgear/multi_vehicle.md)
|
||||
- [Multi-Vehicle Sim with JMAVSim](../sim_jmavsim/multi_vehicle.md)
|
||||
- [Multi-Vehicle Sim with SIH](../sim_sih/index.md#multi-vehicle-simulation)
|
||||
|
||||
The choice of the simulator depends on the vehicle to be simulated, how "good" the simulation needs to be (and for what features), and how many vehicles need to be simulated at a time:
|
||||
|
||||
@@ -18,5 +19,8 @@ The choice of the simulator depends on the vehicle to be simulated, how "good" t
|
||||
Note, this is the successor of [Gazebo Classic](../sim_gazebo_classic/index.md) (below).
|
||||
- [Gazebo Classic](../sim_gazebo_classic/index.md) is less accurate and less heavy-weight and supports many features and vehicles that aren't available for FlightGear.
|
||||
It can simulate many more vehicles at a time than FlightGear and it allows for different types of vehicles to be simulated at the same time.
|
||||
- JMAVSim is a very light-weight simulator that supports only quadcopters.
|
||||
- [JMAVSim](../sim_jmavsim/index.md) is a very light-weight simulator that supports only quadcopters.
|
||||
It is recommended if you need to support a lot of quadcopters, and the simulation only needs to be approximate.
|
||||
- [SIH](../sim_sih/index.md) is the lightest-weight option with zero external dependencies.
|
||||
Since SIH is headless and runs physics internally, it can launch many instances with minimal resource usage.
|
||||
It supports all 6 vehicle types (quad, hex, plane, tailsitter, standard VTOL, rover).
|
||||
|
||||
Reference in New Issue
Block a user