Skip to content

frontend: Clean up MAVLink refresh rates on leave (store + vehicle setup) - #4047

Open
joaoantoniocardoso wants to merge 2 commits into
bluerobotics:masterfrom
joaoantoniocardoso:pr/mavlink-rate-cleanup
Open

frontend: Clean up MAVLink refresh rates on leave (store + vehicle setup)#4047
joaoantoniocardoso wants to merge 2 commits into
bluerobotics:masterfrom
joaoantoniocardoso:pr/mavlink-rate-cleanup

Conversation

@joaoantoniocardoso

@joaoantoniocardoso joaoantoniocardoso commented Jul 27, 2026

Copy link
Copy Markdown
Member

Summary

  • Allow setMessageRefreshRate to lower rates (not only raise), replacing the listener when the rate changes.
  • Vehicle setup / MainView / compass: ratchet rates down on destroy, discard position listeners, clear CompassDisplay render interval + GSAP tweens.

Test plan

  • Visit Home (ATTITUDE 10 Hz) then leave: rate drops to 1 Hz
  • Open compass configure, leave: render interval stops; IMU/ATTITUDE rates ratchet down
  • Gyro calib mount/unmount does not leave 10 Hz streams forever
  • Level horizon dialog open/close does not fight CompassDisplay ATTITUDE rate while both tabs are alive

Supersedes #4031 (recreated from fork joaoantoniocardoso/BlueOS-docker instead of same-repo head).

@github-actions

Copy link
Copy Markdown

Automated PR Review

0. Summary

  • Verdict: MINOR SUGGESTIONS ✏️

Tightens MavlinkStore.setMessageRefreshRate so it can now lower rates (not just raise), and adds cleanup hooks in MainView, CompassDisplay, GyroCalib, and AutoCoordinateDetector so intervals, GSAP tweens, MAVLink listeners, and requested refresh rates are released on unmount. LevelHorizonCalibration adds an explanatory comment about why it must not ratchet ATTITUDE down.

1. Correctness & Implementation Bugs

  • 1.1 [minor] core/frontend/src/store/mavlink.ts:34-49 — the store still has no reference counting: beforeDestroy in one component can lower a rate that another live component depends on. The PR papers over one instance in LevelHorizonCalibration.vue, but the same class of bug remains latent — for example, GyroCalib.beforeDestroy ratchets RAW_IMU/SCALED_IMU2/SCALED_IMU3 down to 1 Hz, and those exact three messages are also requested by CompassDisplay at 10 Hz. If a caller ever has both mounted concurrently (Vuetify's v-tabs-items cache, a dashboard widget, etc.) the surviving component silently drops to 1 Hz. Not a blocker for this PR, but worth tracking — a real fix would keep a per-message subscriber map and pick max(rate).
  • 1.2 [minor] core/frontend/src/store/mavlink.ts:38mavlink2rest.requestMessageRate used to be called on every setMessageRefreshRate; now it's skipped when frequency === refreshRate. If the autopilot ever loses stream state (reconnect, restart), we won't reissue the rate. Consider whether this is acceptable, or whether the wire request should still be sent as a periodic reassertion. Probably fine given the upstream retransmission, but a behavior change worth being explicit about.

4. Performance

  • 4.1 The core intent — stopping ATTITUDE/IMU streams that were previously stuck at 10 Hz forever — is exactly the right optimization. Good.

6. Code Quality & Style

  • 6.1 [nit] core/frontend/src/components/vehiclesetup/configuration/compass/CompassDisplay.vue:64render_interval is snake_case in a file whose other data properties are camelCase (canvasSize, renderVariables, yawAngleDegrees). Rename to renderInterval for consistency. (position_listener in AutoCoordinateDetector.vue matches that file's existing snake_case pattern, so it's fine.)
  • 6.2 [nit] core/frontend/src/components/vehiclesetup/configuration/compass/CompassDisplay.vue:41,57 — the newly extracted COMPASS_REFRESH_MESSAGES and GYRO_REFRESH_MESSAGES (in GyroCalib.vue) are duplicated between files; both include the IMU trio. If a future PR tackles the reference-counting issue mentioned in 1.1, this would be a natural place to consolidate.

7. Tests

  • 7.1 [minor] The PR body's test plan is entirely unchecked. No automated coverage is added for the store's new "equal-rate skip / different-rate replace" semantics, which is the load-bearing change. A small unit test on MavlinkStore.setMessageRefreshRate verifying that (a) equal rate skips the wire call, (b) lower rate discards and replaces, (c) negative rate returns early would guard against regressions.

8. Documentation

  • 8.1 The inline comments added in mavlink.ts ("Equal rate: keep existing listener…"), AutoCoordinateDetector.vue (markRaw: rationale), and LevelHorizonCalibration.vue (why ATTITUDE is not ratcheted) are exactly the "why" comments AGENTS.md asks for. Nice.

Generated by PR Review Bot. This is advisory, a human reviewer must still approve.

@joaoantoniocardoso joaoantoniocardoso added the move-to-stable Needs to be cherry-picked and move to stable label Jul 27, 2026
Replace listeners when the requested rate changes in either direction
so pages can ratchet streams down on destroy instead of only up.
…leave

Ratchet message rates down on destroy, discard position listeners, and
clear the CompassDisplay render interval plus GSAP tweens.
@joaoantoniocardoso
joaoantoniocardoso force-pushed the pr/mavlink-rate-cleanup branch from e54d12b to f0da846 Compare July 28, 2026 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

move-to-stable Needs to be cherry-picked and move to stable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant