feat(navigator): Implement a mission route cache #27707
Conversation
|
Hey @bkueng, would you have time to review this PR please? |
🔎 FLASH Analysispx4_fmu-v5x [Total VM Diff: 3600 byte (0.18 %)]px4_fmu-v6x [Total VM Diff: 3584 byte (0.19 %)]Updated: 2026-07-10T06:37:12 |
|
State machine summary:
On mission identity change,
Once loading stops, Only after that validation does Planner/provider reads call |
| if (!success) { | ||
| /* not supposed to happen unless the datamanager can't access the SD card, etc. */ | ||
| mavlink_log_critical(_navigator->get_mavlink_log_pub(), "Mission land item could not be read.\t"); | ||
| events::send(events::ID("rtl_failed_to_read_land_item"), events::Log::Error, | ||
| "Mission land item could not be read"); | ||
| } | ||
| const bool land_item_pending = mission_route_cache != nullptr | ||
| && mission_route_cache->missionLandItemUpdatePending(); | ||
|
|
||
| if (!land_item_pending) { | ||
| /* Not supposed to happen unless the datamanager can't access the SD card, etc. */ | ||
| mavlink_log_critical(_navigator->get_mavlink_log_pub(), "Mission land item could not be read.\t"); | ||
| events::send(events::ID("rtl_failed_to_read_land_item"), events::Log::Error, | ||
| "Mission land item could not be read"); | ||
| } |
There was a problem hiding this comment.
Hey @bkueng,
I'm not sure how to handle the case where the land item cache is still pending. In that case it's not a read error so sending the critical warning can be misleading.
On the other hand, re-evaluating setRtlTypeAndDestination does not seem right because we've already fell back to home / safepoint.
Any thoughts on how to handle this corner case?
There was a problem hiding this comment.
My preferred option is to remove: if (!land_item_pending) { and have pending equivalent to SD card read failure. This is the simplest option and in practice the land item should not be pending since on_inactive() we call updateDatamanCache.
There was a problem hiding this comment.
removed if (!land_item_pending) { here 38ccd0d
|
I'll try to find some time for a review. |
… route-following RTL
…king it available
2cc49d9 to
ff46fd6
Compare
This PR was split from #27687 as a first step to simplify the review. This commit: 2e29d4f performed the split. It can be useful to understand the overall structure e.g. mission_route_types.h is very small in this PR, but it grows with the follow up.
Route Cache
Normal mission execution only keeps a small sliding window of mission items in RAM, but route planning needs random, non-blocking access to the whole mission to project points against every segment.
The cache provides that: it caches the full mission, the safe points, and the mission-land item into RAM,
Planner reads use a zero wait timeout, so a cache miss returns failure instead of blocking Navigator while dataman or the SD card catches up.
The cache tracks mission identity and reloads when the mission changes; if an item is missing it schedules a retry with bounded exponential backoff.
Safe points have their own asynchronous state machine, are reloaded when their source identity changes, and are never exposed as stale data while a reload is in progress.
Cache Size
CONFIG_RTL_MISSION_CACHE_SIZEsets the maximum number of mission items reserved for full-route planning.The default is
100forBOARD_TESTINGbuilds and0otherwise.A value of
0disables the cache and reserves no entries, so boards that enable a route-planning consumer must size it for their RAM budget. Each reserved item uses roughly 76 bytes of heap for the lifetime of Navigator.Note that
CONFIG_RTL_MISSION_CACHE_SIZEonly affects_dataman_cache_missionso the RTL behavior is not affectedCache Coherency
Navigator can hold more than one cache view of the same mission item:
E.g. mission_route_cache holds:
DatamanCache::updateCachedItem()lets a caller copy an already-written, stable value into another cache without issuing a second dataman request.MissionRouteCache::syncMissionItem()uses it to keep the planner-facing caches coherent after a mission item was written through another path.syncMissionItemis not used in this PR, but it is used in the follow up: feat(navigator): Add infrastructure for smart mission route planning #27687