Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Solved Problem
When uploading missions to be flown with RTL_TYPE=2 as a return path, PX4 sometimes claims there is no mission when RTL is triggered:
Solution
Turns out that when these specific RTL handlers are initialized, they don't initialize their mission member variable. Because of that the RTL handlers essentially work with an empty mission where the index is -1, hence the dataman error.
The solution is to load the existing mission after initializing the handlers. I decided to pass the variables via constructor to contain the logic of obtaining the mission from the uORB queue all in rtl.cpp. This way the information flow is more visible in my opinion.
Changelog Entry
For release notes:
Test coverage
Tested with SITL where mission 1 is executed, mission 2 uploaded and then RTL triggered.
Bug on main branch: https://logs.px4.io/plot_app?log=6af3f82a-ec03-4f8e-95d7-f949697ecd00
Fix from this PR: https://logs.px4.io/plot_app?log=03c990f1-0601-4142-8a9b-f6b42b9cc1ef