mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-12-04 07:50:56 +08:00
feat(sih): add optional support for non-flat terrain for MC, FW and VTOL (#29619)
* feat(simulator_sih): add a GeoTIFF terrain elevation model for SITL SIH only simulates flat ground. This adds the loader for a terrain elevation model (DEM) in a GeoTIFF file, the base for non-flat terrain in SITL. The DEM is read with libtiff and libgeotiff. A DEM in a projected CRS is resampled once at load time with PROJ onto a WGS84 lat/lon grid, so a lookup in the simulation loop is a plain bilinear interpolation. It is built only for px4_sitl and only when the three libraries are found, so hardware builds and SITL without them are unchanged. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Beniamino Pozzan <beniamino.pozzan@auterion.com> * feat(simulator_sih): use the terrain DEM for ground contact and the rangefinder With PX4_SIH_TERRAIN set to a GeoTIFF DEM, SIH in SITL places the vehicle on the terrain at start, lands it on the terrain, ray-casts the downward distance sensor against it, and publishes it as the groundtruth terrain_alt. Outside the DEM the ground stays flat at SIH_LOC_H0. Terrain is only used for multicopters, VTOLs and fixed-wing; other vehicle types keep flat ground. The DEM is loaded in task_spawn() so a bad file fails the start command, and because the SIH task stack is too small for libtiff and PROJ. The groundtruth terrain_alt now holds the WGS84 terrain altitude, as the message documents, instead of the height above the origin. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Beniamino Pozzan <beniamino.pozzan@auterion.com> * build(setup): install the SIH terrain dependencies with the simulation tools Install libtiff, libgeotiff and PROJ so SITL builds SIH with terrain elevation (DEM) support. They are optional: without them SIH builds as before. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Beniamino Pozzan <beniamino.pozzan@auterion.com> * docs(sim_sih): document terrain elevation from a GeoTIFF DEM Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Beniamino Pozzan <beniamino.pozzan@auterion.com> * docs(sim_sih): fix and clarify the terrain elevation section Address review findings on the new terrain section: list the sample types the loader actually reads, note that the prebuilt px4 package and px4io/px4-sitl container are built without terrain support, and say when SIH_LOC_H0 still sets the start altitude. Also add a version badge, link GeoTIFF, EPSG and GDAL, mention the dist_bottom groundtruth field, and correct the GLO-30 coverage. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Hamish Willee <hamishwillee@gmail.com> * fix: cast to double for MAC builds Signed-off-by: Beniamino Pozzan <beniamino.pozzan@auterion.com> * chore: implement TerrainBase interface Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Beniamino Pozzan <beniamino.pozzan@auterion.com> * chore: improve isolation of terrain logic from sih core Signed-off-by: Beniamino Pozzan <beniamino.pozzan@auterion.com> * refactor(simulator_sih): move DEM handling into the terrain classes SIH should only use the terrain, not manage it. TerrainFlat becomes the base class, since flat ground is what every terrain model builds on, and TerrainDem falls back to it until a DEM is loaded. Terrain.hpp picks the model at compile time, so SIH holds the terrain by value with no #ifdef, new/delete or pointer handover, and NuttX builds only get the flat model. Tracking whether the vehicle is inside the DEM, and the matching warnings and status, move from SIH into TerrainDem. The DEM is still loaded in task_spawn() because the SIH task stack is too small for libtiff and PROJ, so the terrain is a static member that the instance uses directly instead of moving it. A terrain file with an unsupported vehicle type now fails the start like a bad file instead of silently using flat ground. --------- Signed-off-by: Beniamino Pozzan <beniamino.pozzan@auterion.com> Signed-off-by: Hamish Willee <hamishwillee@gmail.com> Co-authored-by: Hamish Willee <hamishwillee@gmail.com> Co-authored-by: Matthias Grob <maetugr@gmail.com>
This commit is contained in:
13 files changed
+1462
-32
No files matched your search
@@ -163,6 +163,49 @@ Run it from the PX4 shell, or the [MAVLink shell](../debug/mavlink_shell.md), af
|
||||
|
||||
`orient` is only built for SITL: sensor calibration is rejected when SIH runs on flight controller hardware.
|
||||
|
||||
#### Terrain Elevation (DEM) {#terrain}
|
||||
|
||||
<Badge type="tip" text="main (PX4 v2.0)" />
|
||||
|
||||
By default SIH simulates flat ground at [`SIH_LOC_H0`](../advanced_config/parameter_reference.md#SIH_LOC_H0).
|
||||
SIH can instead load the terrain elevation from a digital elevation model (DEM) [GeoTIFF](https://www.ogc.org/standards/geotiff/) file, set with the `PX4_SIH_TERRAIN` environment variable:
|
||||
|
||||
```sh
|
||||
PX4_SIH_TERRAIN=/path/to/dem.tif make px4_sitl_sih sihsim_quadx
|
||||
```
|
||||
|
||||
The terrain is then used for:
|
||||
|
||||
- Ground contact: the vehicle starts, lands and rests on the terrain.
|
||||
It is placed at the terrain elevation below [`SIH_LOC_LAT0`](../advanced_config/parameter_reference.md#SIH_LOC_LAT0)/[`SIH_LOC_LON0`](../advanced_config/parameter_reference.md#SIH_LOC_LON0) (`PX4_HOME_LAT`/`PX4_HOME_LON`).
|
||||
`SIH_LOC_H0` (`PX4_HOME_ALT`) sets the start altitude only when that point is outside the DEM.
|
||||
- The downward facing distance sensor, which measures the range to the terrain along the vehicle body z axis (up to [`SIH_DISTSNSR_MAX`](../advanced_config/parameter_reference.md#SIH_DISTSNSR_MAX)).
|
||||
- The `terrain_alt` field of the `vehicle_global_position_groundtruth` topic.
|
||||
- The `dist_bottom` field of the `vehicle_local_position_groundtruth` topic.
|
||||
|
||||
Outside the area covered by the DEM, or over cells without data, the ground is flat at `SIH_LOC_H0` and a warning is printed.
|
||||
Terrain is supported for multicopters, VTOLs and fixed-wing vehicles; with any other vehicle type (such as Ackermann rovers), setting `PX4_SIH_TERRAIN` stops SIH from starting with an error.
|
||||
`simulator_sih status` shows the loaded DEM and whether the vehicle is inside it.
|
||||
|
||||
The DEM must be a single-band GeoTIFF whose coordinate reference system has an [EPSG code](https://epsg.io/), either geographic (such as WGS84, `EPSG:4326`) or projected (such as UTM or the Swiss `EPSG:2056`).
|
||||
8, 16 and 32-bit integer and 32 and 64-bit floating point samples are supported with any TIFF compression, and the [_GDAL_](https://gdal.org/) nodata value is respected.
|
||||
Elevations are used as they are, as altitude above mean sea level.
|
||||
Free sources include [Copernicus GLO-30](https://registry.opendata.aws/copernicus-dem/) (near-global, 30 m, including buildings and vegetation) and national elevation models such as [swissALTI3D](https://www.swisstopo.admin.ch/en/height-model-swissalti3d) (2 m).
|
||||
Crop large files to the area you fly in, for example with _GDAL_:
|
||||
|
||||
```sh
|
||||
gdal_translate -projwin 8.48 47.44 8.61 47.35 Copernicus_DSM_COG_10_N47_00_E008_00_DEM.tif zurich.tif
|
||||
```
|
||||
|
||||
Files in other formats, with other sample types or without an EPSG code can be converted with `gdalwarp -t_srs EPSG:4326 -ot Float32 in.tif out.tif`.
|
||||
|
||||
::: info
|
||||
Terrain support is optional and only available in SITL, not when [running SIH on flight controller hardware](#sih-on-flight-controller-hardware).
|
||||
The [prebuilt](../simulation/px4_sitl_prebuilt_packages.md) `px4` package and `px4io/px4-sitl` container are built without it, and SIH reports an error and does not start if `PX4_SIH_TERRAIN` is set.
|
||||
When building from source, the [setup scripts](../dev_setup/dev_env.md) install the required libraries with the simulation tools.
|
||||
The CMake output shows `SIH terrain (DEM) support enabled` when it is available.
|
||||
:::
|
||||
|
||||
### ROS 2 Integration
|
||||
|
||||
SIH works with ROS 2 via the [uXRCE-DDS](../middleware/uxrce_dds.md) client, which auto-starts in SITL mode.
|
||||
|
||||
Reference in new issue
Block a user