-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Altitude calculated from terrain data #11226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Branch Targeting SuggestionYou've targeted the
If This is an automated suggestion to help route contributions to the appropriate branch. |
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
c8f5b33 to
4b99b82
Compare
|
Integration to inav rewrittten by discusion on discord.
I found another bug. If the SD card is removed during operation and then inserted back, CDC gets broken and the DMA handlers stop being called. It's not terrain system issue, it's in inav for a long time. I can't find what happens there. However, the terrain system can detect this and will stop reading from the SD card. |
User description
Terrain ASL from SD Card
Description
Loads ASL (Above Sea Level) values from a file stored on an SD card.
This feature is supported only on MATEKH743 and is recommended to be used only on flight controllers that access the SD card via SDIO.
Terrain files can be generated at:
https://terrain.ardupilot.org/
Currently, INAV supports only SRTM1 (30 m spacing).
The terrain file must be copied to the root of the SD card. If SD seems full, delete FREESPACE file from root of SDCARD
This limitation will be addressed later and is not critical at the moment.
Technical Notes
1. Blackbox interaction
When the terrain feature is enabled, blackbox is disabled.
All SD card access is handled in a single function using a state machine. All
asyncfatfshandlers are processed correctly, which allows implementing proper locking.Blackbox uses a more complex state machine and accesses the SD card from multiple locations. Many
asyncfatfshandlers are not handled correctly or are missing.Running blackbox and terrain simultaneously would require refactoring (rewriting) the blackbox implementation.
2. SD card failure handling
Any SD card failure disables the terrain feature.
This behavior protects the UAV and prevents infinite loops in
asyncfatfs. If an invalid state of the terrain state machine is detected, the entire subsystem is disabled.3. File open retry limit
If the terrain file cannot be opened three times, it is marked as invalid and loading is stopped.
Testing
Outdoor testing was successful, especially regarding precision.
Maximum deviation was approximately ±5 meters, which is more than sufficient for this use case.
https://www.youtube.com/watch?v=BHLAbzi2vbY
PR Type
New Feature
Description
Implements terrain altitude feature using SD card data
Integrates terrain as virtual rangefinder device
Loads SRTM1 terrain data with grid caching system
Disables blackbox when terrain feature is active on SDCARD
Adds terrain support exclusively to MATEKH743 target
Diagram Walkthrough
File Walkthrough
8 files
Core terrain altitude calculation and rangefinder integrationTerrain data structures and grid definitionsSD card file I/O state machine for terrain dataTerrain I/O state machine and file handling definitionsGrid cache management and location calculationsGrid utility function declarationsGPS location offset and distance calculationsLocation utility function and constant definitions4 files
Add terrain rangefinder type detection and initializationAdd RANGEFINDER_TERRAIN enum valueExport terrain virtual rangefinder vtableInitialize SD card before blackbox when terrain enabled1 files
Prevent blackbox and terrain simultaneous SD card usage3 files
Enable terrain feature for MATEKH743 with SDIOAdd TERRAIN option to rangefinder hardware settingsAdd terrain source files to build system2 files
Unit tests for terrain grid calculationsConfigure terrain unit test build dependencies