vtol_tailsitter: copy cached ulog arrays before in-place mutation#338
Open
evanofficial wants to merge 1 commit into
Open
vtol_tailsitter: copy cached ulog arrays before in-place mutation#338evanofficial wants to merge 1 commit into
evanofficial wants to merge 1 commit into
Conversation
tailsitter_orientation() read angular rate and rates-setpoint arrays directly from cur_dataset.data and then wrote FW-corrected values back into them with boolean-mask assignment. Because load_ulog_file() uses lru_cache, the same ULog object is reused across page reloads, so the in-place writes corrupted the cached dataset. On each refresh the function re-derived the swapped FW values from the already-swapped arrays, which is why the yaw angular rate plot changed value on every refresh for tailsitter VTOL logs (PX4#324). Copy the source arrays once with np.copy() before the masking loop so the cache stays clean. Fixes PX4#324
bkueng
reviewed
May 18, 2026
Comment on lines
86
to
87
| w_r_fw = w_y*-1 | ||
| w_y_fw = w_r*1 # *1 to get python to copy not reference |
Member
There was a problem hiding this comment.
Can you use np.copy here too? And also below (setp_r_fw = ...)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #324.
Root cause
tailsitter_orientation()inapp/plot_app/vtol_tailsitter.pyreads the angular-rate and rates-setpoint arrays directly from the cached ULog dataset:cur_dataset.data['xyz[0]']is a reference to the underlying numpy array, andload_ulog_file()inhelper.pyis wrapped with@lru_cache, so the same ULog object is reused across page loads. The masked assignments mutate the cached arrays in place. On the next refresh the function re-derivesw_r_fw = w_y * -1andw_y_fw = w_r * 1from arrays that already have their FW segments swapped, producing a different (and progressively more corrupted) yaw angular rate each time.The author was aware of the reference/aliasing trap for the two derived arrays (the
# *1 to get python to copy not referencecomment), but missed thatw_randw_ythemselves are still references into the cache.The attitude block at the top of the same function is unaffected because it builds new arrays via
np.deg2rad(rpy[:, …])before mutating.Fix
np.copy()the source arrays once, right where they're pulled out of the dataset, for both thevehicle_angular_velocityandvehicle_rates_setpointblocks. The rest of the masking logic is unchanged.Test plan
No test infrastructure exists in this repo (no
tests/directory, no test runner in CI), so no regression test was added. Manual verification: load any tailsitter VTOL log on a flight-review instance and refresh the page repeatedly — yaw angular rate plot should now be stable instead of drifting.