Repository navigation
Terrain: take the height reference where the aircraft arms, no higher than the GPS altitude - #12283
joshuabardwell wants to merge 3 commits into
Conversation
Height above ground is the estimated altitude minus the terrain's rise above a reference height. The reference was the map height at the GPS origin, which is where the first fix came in and never moves, while the altitude zero is set where the aircraft arms (inav_reset_altitude). An aircraft carried from where it got its fix to the launch spot, or armed a second time somewhere else with EACH_ARM, had every terrain height off by the difference in ground height between the two places. The map is now read where the aircraft stands while it is disarmed, and kept with the altitude it has there. Arming keeps the last such point for the flight; an emergency re-arm in the air keeps the flight's point, as the position estimator keeps its altitude zero. terrain.c and terrain_nav.c share the one reference instead of each latching the origin's map height. SITL (3D cruise + TERRAIN AGL HOLD engaged at 50 m over flat ground, minimum 60 m, so the hold levels off at 70 m): - first fix on ground 30 m higher, then carried to the launch spot: levelled at 49.6 m and reported 79.6 m; now 70.0 m - EACH_ARM, second arm on ground 30 m higher: levelled at 100.0 m; now 69.9 m - FIRST_ARM second arm, and a re-arm in the air: unchanged Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The height reference was the map height under the take-off spot alone, so an error of the map there shifted every terrain height of the flight. A map that reads x m too high at take-off made the aircraft fly x m lower than it believed, everywhere. The GPS altitude of the altitude zero (the GPS origin's altitude) is a second reading of the same height. The lower of the two is now used: a reference that is too high puts the aircraft closer to the ground than it believes, a reference that is too low only makes it fly higher. The GPS reading counts only with a 3D fix and an EPV under inav_max_eph_epv when the aircraft armed; otherwise the map alone is used, as before. What changes in flight: - map too high at take-off: was that much too low, now correct - map too low at take-off, or launched from above the mapped ground: flies that much higher, as before - GPS altitude reads high: nothing changes - GPS altitude reads low: flies that much higher SITL (3D cruise + TERRAIN AGL HOLD engaged at 50 m over flat ground, minimum 60 m, so the hold levels off at 70 m): - map 15 m too high round the take-off spot: levelled at 49.7 m and reported 65.7 m; now 70.0 m - GPS altitude 10 m low: 80.0 m (was 70.0 m) - map 15 m too low (85.0 m), GPS 10 m high (70.0 m), a second arm with FIRST_ARM and EACH_ARM, and a re-arm in the air: unchanged Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… at take-off With the hold engaged, "TERRAIN: MAP/GPS ALT DIFFER" shows when the two readings of the take-off height are more than 5 m apart: the map is wrong at the take-off spot, the GPS altitude was off at arming, or the aircraft armed well above the mapped ground. The lower reading is in use either way, so the message tells the pilot why the heights may be off, and that the hold errs toward flying higher. Adds the message to the table in Navigation Terrain Following.md. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoTerrain: take height reference at arming, capped at GPS altitude
AI Description
Merge Risk
|
Code Review by Qodo
1. Quick re-arms use the old terrain height
|
|
RAM / Flash usage vs. base commit
See RAM/flash optimization guide for techniques to reduce usage. |
Problem
The terrain code works out height above ground as the estimated altitude minus how far the
terrain rises above a reference height. That reference is the map height at the GPS origin
(
terrainNavUpdateHomeHeight()interrain_nav.c, and the data layer's own AGL interrain.c). Two things go wrong with it:never moves. The altitude zero is set where the aircraft arms (
inav_reset_altitude). Ifthe aircraft is carried after its first fix, or armed a second time somewhere else with
EACH_ARM, every terrain height is off by the difference in ground height between thetwo places.
height says map-datum errors cancel. That holds for an offset that is the same
everywhere. It does not hold for an error that is local to the take-off spot (the map is
a smoothed 30 m grid, so a mesa edge, a cut or a building is enough). If the map reads
x m too high where the aircraft arms, the aircraft flies x m lower than it believes for
the whole flight, which is the wrong direction for a terrain floor.
Changes
Three commits. Each builds on the one before, and the first stands on its own if you would
rather keep a map-only reference.
fix(terrain): take the height reference where the aircraft arms. The map is readwhere the aircraft stands while it is disarmed, together with its altitude there.
Arming keeps the last such point for the flight. An emergency re-arm in the air keeps
the flight's point, as the position estimator keeps its altitude zero.
terrain.candterrain_nav.cnow share one reference (terrainGetReferenceHeightM()), which replacesterrainNavGetHomeTerrainHeight().fix(terrain): height reference no higher than the GPS altitude. The GPS altitude ofthe altitude zero is a second reading of the same height, and the lower of the two is
used. A reference that is too high puts the aircraft closer to the ground than it
believes; one that is too low makes it fly higher. The GPS reading counts only if the
aircraft had a 3D fix and an EPV under
inav_max_eph_epvwhen it armed. Otherwise themap alone is used, as before. This commit changes the choice described in the comment
above, so it is kept separate.
feat(terrain): OSD message when the map and the GPS altitude disagree at take-off.While the hold is engaged,
TERRAIN: MAP/GPS ALT DIFFERshows if the two readings aremore than 5 m apart (
TERRAIN_REFERENCE_DISAGREE_M). That means the map is wrong at thetake-off spot, the GPS altitude was off at arming, or the aircraft armed well above the
mapped ground. The message and a short note on where heights are measured from are added
to
docs/Navigation Terrain Following.md.What changes in flight:
EACH_ARMTesting
Unit tests.
ninja checkpasses (635 tests) on the branch merged with the currentmaintenance-10.x. The existingterrain_unittestbuildsterrain_location.candterrain_utils.conly, so no unit test covers the files this changes.SITL. 3D cruise with TERRAIN AGL HOLD engaged at 50 m over flat ground, minimum 60 m, so
the hold levels off at 70 m. Synthetic
.TERdata and a simulated GPS:EACH_ARM, second arm on ground 30 m higherFIRST_ARMsecond arm; re-arm in the airHITL. X-Plane 12, TBS Lucid H743 Wing, Sedona AZ (KSEZ, on a mesa). This was a build of
my fork that carries these three commits and also flies terrain-protected waypoint legs,
which take their heights from the same reference. The cruise hold itself was flown in SITL
only. Heights compared with X-Plane's own position and ground:
ground was 14.5 m more than the true height (median over the flight).
matches X-Plane: median +0.1 m.
TERRAIN: MAP/GPS ALT DIFFERshowed while the terrain legswere flown.
🤖 Generated with Claude Code