Skip to content

mavlink_wifi: set our own ATTITUDE and GLOBAL_POSITION_INT rates - #6

Open
peterbarker wants to merge 1 commit into
ArduPilot:masterfrom
peterbarker:fc-message-intervals
Open

peterbarker wants to merge 1 commit into
ArduPilot:masterfrom
peterbarker:fc-message-intervals

Conversation

@peterbarker

@peterbarker peterbarker commented Nov 15, 2026 •

Copy link
Copy Markdown

Summary

Ask the flight controller for ATTITUDE at 50 Hz and GLOBAL_POSITION_INT at 10 Hz with SET_MESSAGE_INTERVAL, and keep those rates in place on any ArduPilot, whatever stream rates a GCS on WiFi asks for.

Description

The video telemetry wants a fresh attitude for every frame, but every rate on our link came from REQUEST_DATA_STREAM: ours at 4 Hz, or whatever a GCS asked for. At 4 Hz, a frame's attitude was a median 130 ms old (at most 256 ms).

The Sonix now sets per-message intervals for ATTITUDE (50 Hz) and GLOBAL_POSITION_INT (10 Hz). It doesn't depend on the link's MAVn_OPTIONS NOSTREAMOVERRIDE bit, which older ArduPilots don't have. Without that bit, a REQUEST_DATA_STREAM resets the interval of every message in the streams it names: ATTITUDE is in EXTRA1, GLOBAL_POSITION_INT in POSITION, and MAV_DATA_STREAM_ALL covers both. So:

  • the intervals are sent again after a REQUEST_DATA_STREAM covering them, ours or a GCS's passing through from WiFi, and whenever the flight controller restarts (a gap of over 3 s in its own heartbeats, or its SYSTEM_TIME going backwards)
  • the Sonix checks they arrive at about the rates asked for, and sends them again if not (at most every 5 s). This is needed at boot: ArduPilot sets every interval from its stream rates the first time it sends, which can come after it has acked us, so an acked interval can be lost
  • a message a GCS on WiFi or a web client sets itself with SET_MESSAGE_INTERVAL (addressed to the autopilot) is left to it until the flight controller restarts, and a request of ours still waiting for its ack isn't retried over it
  • it stops if SET_MESSAGE_INTERVAL is unsupported, and leaves alone any message the flight controller refuses
  • the 4 Hz stream request now goes out when SYS_STATUS stops arriving, instead of ATTITUDE, which no longer stops (unless a GCS has set SYS_STATUS's interval itself, perhaps to off), and is retried every 5 s instead of 15, since a request made while the flight controller is starting can be lost the same way

COMMAND_ACK doesn't say which message an ack is for, so only one request is outstanding at a time, an ack is only taken while one is, and after a request sent more than once is acked, any further acks are waited out before the next is sent. Our acks are told from a GCS's by their target. ArduPilot before 4.2 (and MAVLink 1) acks without one, so an untargeted ack is taken as ours while we are waiting, unless a GCS's SET_MESSAGE_INTERVAL has passed through in the last 2 s. A web client's goes out with our own system and component IDs, so ArduPilot 4.2+ acks it to us; for 2 s after one, an ack targeted at us isn't taken either. The retry covers both cases.

mavlink status on the console shows the state of each interval.

The Sonix still assumes the flight controller is system 1 here, as it does for its other commands.

Testing

On a SkyViper (MAV2_OPTIONS 0), measured at a GCS on WiFi, built together with #5 so broadcast loss doesn't cloud the figures:

Step Result
Sonix boot ATTITUDE 50 Hz, GLOBAL_POSITION_INT 10 Hz, other streams 4 Hz
GCS REQUEST_DATA_STREAM for EXTRA3 only ATTITUDE and GLOBAL_POSITION_INT unaffected
GCS REQUEST_DATA_STREAM for all streams at 2 Hz ATTITUDE and GLOBAL_POSITION_INT back at their rates within about 1 s
GCS REQUEST_DATA_STREAM for all streams every 0.3 s for 6 s rates degraded during, back within 2 s after
GCS SET_MESSAGE_INTERVAL ATTITUDE at 10 Hz, to the camera component ignored; the Sonix keeps ATTITUDE at 50 Hz
GCS SET_MESSAGE_INTERVAL ATTITUDE at 10 Hz, to the autopilot stays at 10 Hz; the Sonix leaves it alone
Web client mavlink_message_send(COMMAND_LONG,1,1,511,0,30,100000) (ATTITUDE at 10 Hz) stays at 10 Hz for 20 s; the Sonix leaves it alone; back to 50 Hz after a flight controller reboot
Web client sets GLOBAL_POSITION_INT to 5 Hz, then at once a GCS REQUEST_DATA_STREAM for all streams at 2 Hz ATTITUDE back at 50 Hz within about 1 s, and its request completes without giving up; GLOBAL_POSITION_INT left at the web client's 5 Hz
GCS SET_MESSAGE_INTERVAL SYS_STATUS off (-1), to the autopilot SYS_STATUS stays off for 18 s, with no stream request from the Sonix; ATTITUDE and GLOBAL_POSITION_INT unaffected; all back after a flight controller reboot
GCS REQUEST_DATA_STREAM for all streams at 0 Hz streams asked for again at 4 Hz within about 3 s; ATTITUDE unaffected
Flight controller rebooted, twice all rates back as soon as it returns. Before the rate check was added, one reboot left ATTITUDE off until the next stream request, which is how the boot problem above was found

Not exercised on the bench: duplicate acks, and ArduPilot older than 4.2 or using MAVLink 1 (untargeted acks).

With 50 Hz ATTITUDE, 99% of 20 fps frames carried a fresh attitude (median age 10 ms, at most 40 ms), for about 2 kB/s more on SERIAL1. With #5, the GCS received ATTITUDE at 49.99 Hz with 0.1% of messages lost.

@AP-Review

AP-Review commented Nov 15, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-15)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 713af8bf51.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/skyrockettoys-sonix/6/1.html#prSkyRocketToys-Sonix-6

This adds a working SET_MESSAGE_INTERVAL manager for ArduPilot 4.2 and later, but on older firmware and MAVLink 1 links it never recognises its own acks, so it never gives up.

Should fix

  • mavlink_wifi.c:1791: our acks are matched only by target_system/target_component. ArduPilot fills those only from 4.2, and a MAVLink 1 frame decodes them as zero. On 3.x the UNSUPPORTED ack is never seen, so the manager cycles forever through retries, skips and the rate check, sending about 10 COMMAND_LONGs and 3 console lines every 12 s, and the UNSUPPORTED acks are forwarded to WiFi. On 4.0/4.1 every message needs 5 unacked retries before it is skipped. Only one of ours is outstanding at a time, so a targetless SET_MESSAGE_INTERVAL ack from the FC could be accepted while ours is pending (as long as no GCS request passed through meanwhile), or the manager could give up after a bounded number of unacked cycles.
Minor (3)
  • mavlink_wifi.c:1302: an ack is consumed even when none of ours is outstanding. After a retry, two ATTITUDE acks arriving before the next tick move past GLOBAL_POSITION_INT without ever sending it, and if they were refusals it stays marked refused. Ignore the ack when msg_interval_sent_ms == 0.
  • mavlink_wifi.c:1710: restart detection takes SYSTEM_TIME from any sender. A companion's shorter uptime routed onto this link looks like an FC reboot and overrides a GCS's own interval. Check fc_sysid/MAV_COMP_ID_AUTOPILOT1, as the arrival counter does.
  • mavlink_wifi.c:1275: a refused interval is skipped by the rate check but not by the send loop, so it is sent again after every stream request, despite the commit's "stop for good". Skip msg_interval_refused[] entries here as well.

The extra WiFi broadcasts from forwarding 50 Hz ATTITUDE were considered and not counted as a defect.

@peterbarker
peterbarker force-pushed the fc-message-intervals branch 2 times, most recently from 0a30920 to 1fdd95a Compare November 15, 2026 10:12
@AP-Review

AP-Review commented Nov 15, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-15)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 1fdd95a017.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/skyrockettoys-sonix/6/2.html#prSkyRocketToys-Sonix-6

This now handles older ArduPilot acks correctly. Two low-severity cases remain where our own rate request can override one a GCS or web client set.

Since 713af8b, all four earlier points are fixed. Untargeted acks are accepted and unacked requests give up, stray acks are ignored, SYSTEM_TIME restart detection checks the sender, and refused intervals are no longer resent.

Should fix

  • mavlink_wifi.c:1301: a retry of our outstanding SET_MESSAGE_INTERVAL ignores msg_interval_gcs[]. If a GCS sets the same message while ours is waiting for its ack (on pre-4.2 its untargeted ack is held back for 2 s, or a 4.2+ ack is lost), our retry overwrites the GCS's interval, and the rate check then leaves it alone. In the retry branch, drop the request (current = -1, plus a quiet period) when msg_interval_gcs[msg_interval_current] is set.
Minor (1)
  • mavlink_wifi.c:1040: only UDP input is observed. A SET_MESSAGE_INTERVAL sent through APWeb's mavlink_message_send goes via mavlink_fc_send and the queue drain without being seen, so the rate check puts 50 Hz back. Call message_intervals_gcs_msg() on queued messages before _mavlink_resend_uart(). The bundled web UI doesn't send this command, so only custom web clients are affected.

The extra WiFi traffic from forwarding 50 Hz ATTITUDE is still not counted as a defect.

@AP-Review

AP-Review commented Nov 15, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-15)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 269a6085bc.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/skyrockettoys-sonix/6/3.html#prSkyRocketToys-Sonix-6

Re-reviewed at 269a608: one low-severity case remains, where a web client's interval command can be acked as ours.

Since 1fdd95a, both earlier points are fixed: a retry no longer overrides a GCS that has taken the message, and SET_MESSAGE_INTERVAL from the web queue is now observed.

Should fix

  • mavlink_wifi.c:1859: on ArduPilot 4.2+, the FC acks a web client's SET_MESSAGE_INTERVAL to APWeb's 67/72, the same IDs ours use. So while ours is still waiting (its ack lost or delayed), that ack is taken as ours: a DENIED or FAILED marks our ATTITUDE or GLOBAL_POSITION_INT refused until the FC restarts, and UNSUPPORTED stops the manager. The 2 s hold-off at mavlink_wifi.c:1346 only covers untargeted acks. Fix: apply it to targeted acks too, after a command from mavlink_system's IDs passes the queue drain. Only custom web clients are affected; the bundled UI doesn't send this command.
Minor (1)
  • mavlink_wifi.c:1405: if a GCS turns SYS_STATUS off, its absence now triggers REQUEST_DATA_STREAM(ALL,4). On FCs without NOSTREAMOVERRIDE, that resets the GCS's own intervals (ATTITUDE included), and they are not put back. Base did the same when ATTITUDE stopped, so this mostly moves an existing edge case. Fix: skip the fallback once a GCS has set SYS_STATUS's interval.

The extra WiFi traffic from forwarding 50 Hz ATTITUDE is still not counted as a defect.

@AP-Review

AP-Review commented Nov 16, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-16)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head e4cbe0f27f.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/skyrockettoys-sonix/6/4.html#prSkyRocketToys-Sonix-6

Re-reviewed at e4cbe0f: no blocking or should-fix issues remain, only one rarely-hit minor point.

Since 269a608, both earlier points are fixed: a web client's ack is no longer taken as ours, and a GCS-set SYS_STATUS interval now turns off the stream-request fallback.

Minor (1)
  • mavlink_wifi.c:1334: the quiet-period test is signed, and msg_interval_quiet_until_ms stays 0 or stale. After about 24.9 days of uptime it reads as quiet forever, so a stream request or FC reboot leaves ATTITUDE and GLOBAL_POSITION_INT at stream rates until the clock wraps at about 49.7 days. Fix: use an unsigned elapsed or remaining time (e.g. msg_interval_quiet_until_ms - now - 1U < 1000U), or clear the deadline once it passes.

The extra WiFi traffic from forwarding 50 Hz ATTITUDE is still not counted as a defect.

The video telemetry wants an attitude for every frame, but the rates
on our link came from REQUEST_DATA_STREAM: ours at 4Hz, or whatever a
GCS on WiFi asked for.

Ask for ATTITUDE at 50Hz and GLOBAL_POSITION_INT at 10Hz with
SET_MESSAGE_INTERVAL.  This must work on any ArduPilot, including
those without the MAVn_OPTIONS NOSTREAMOVERRIDE bit, where a
REQUEST_DATA_STREAM resets the interval of every message in the
streams it names: ATTITUDE is in EXTRA1, GLOBAL_POSITION_INT in
POSITION, and MAV_DATA_STREAM_ALL covers both:

 - send them again after a REQUEST_DATA_STREAM covering them, ours
   or one passing through from WiFi, and whenever the flight
   controller restarts (a gap of over 3 seconds in its own
   heartbeats, or its SYSTEM_TIME going backwards)
 - check they arrive at about the rates asked for, and send them
   again if not, at most every 5 seconds: ArduPilot sets every
   interval from its stream rates the first time it sends, which can
   come after it has acked us at boot
 - leave a message that a GCS on WiFi or a web client sets with
   SET_MESSAGE_INTERVAL (to the autopilot) to it until the flight
   controller restarts, without retrying ours if it was still waiting
   for its ack; and stop if SET_MESSAGE_INTERVAL is unsupported or a
   message is refused
 - ask for the 4Hz streams when SYS_STATUS stops arriving, rather
   than ATTITUDE, which no longer stops, unless a GCS has set
   SYS_STATUS's interval itself, and every 5 seconds rather than 15,
   as a request made while the flight controller is starting can be
   lost the same way

COMMAND_ACK doesn't say which message an ack is for, so only one
request is outstanding at a time, an ack is only taken while one is,
and after a request sent more than once is acked, any further acks
are waited out before the next is sent.  Our acks are told from a
GCS's by their target.  ArduPilot before 4.2 (and MAVLink 1) acks
without one, so an untargeted ack is taken as ours while we are
waiting, unless a GCS's SET_MESSAGE_INTERVAL has passed through in
the last 2 seconds.  A web client's goes out with our system and
component IDs, so for 2 seconds after one, an ack targeted at us
isn't taken either.  "mavlink status" shows the state of each
interval.

On the bench, 50Hz gave 99% of 20fps frames a fresh attitude (median
age 10ms, at most 40ms, against 130ms and 256ms at 4Hz), for about
2kB/s more on SERIAL1.  Stream requests (for all streams, one other
stream, and repeated every 0.3s), a GCS's own interval, and two
flight controller reboots all left the rates as intended.
@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: ACCEPT

Reviewed at head dbe4dd0628.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/skyrockettoys-sonix/6/5.html#prSkyRocketToys-Sonix-6

Re-reviewed at dbe4dd0: no blocking, should-fix or minor issues remain.

Since e4cbe0f, the last open point is fixed: the quiet period (mavlink_wifi.c:1342) now uses a flag and an unsigned elapsed time, so it no longer stalls the interval manager after about 24.9 days of uptime.

I looked at the + 2000 overflow in the SYSTEM_TIME restart check (mavlink_wifi.c:1803) and dropped it: the FC's own clock wrap two seconds later reads as a restart with any comparison, so no change is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants