Repository navigation
mavlink_wifi: set our own ATTITUDE and GLOBAL_POSITION_INT rates - #6
peterbarker wants to merge 1 commit into
Conversation
Previous review (2026-11-15)Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head 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
Minor (3)
The extra WiFi broadcasts from forwarding 50 Hz ATTITUDE were considered and not counted as a defect. |
0a30920 to
1fdd95a
Compare
Previous review (2026-11-15)Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head 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
Minor (1)
The extra WiFi traffic from forwarding 50 Hz ATTITUDE is still not counted as a defect. |
1fdd95a to
269a608
Compare
Previous review (2026-11-15)Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head 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
Minor (1)
The extra WiFi traffic from forwarding 50 Hz ATTITUDE is still not counted as a defect. |
269a608 to
e4cbe0f
Compare
Previous review (2026-11-16)Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head 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)
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.
e4cbe0f to
dbe4dd0
Compare
|
Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting. Reviewed at head 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 |
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_OPTIONSNOSTREAMOVERRIDE bit, which older ArduPilots don't have. Without that bit, aREQUEST_DATA_STREAMresets the interval of every message in the streams it names: ATTITUDE is in EXTRA1, GLOBAL_POSITION_INT in POSITION, andMAV_DATA_STREAM_ALLcovers both. So:REQUEST_DATA_STREAMcovering 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)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 itSET_MESSAGE_INTERVALis unsupported, and leaves alone any message the flight controller refusesCOMMAND_ACKdoesn'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'sSET_MESSAGE_INTERVALhas 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 statuson 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_OPTIONS0), measured at a GCS on WiFi, built together with #5 so broadcast loss doesn't cloud the figures:REQUEST_DATA_STREAMfor EXTRA3 onlyREQUEST_DATA_STREAMfor all streams at 2 HzREQUEST_DATA_STREAMfor all streams every 0.3 s for 6 sSET_MESSAGE_INTERVALATTITUDE at 10 Hz, to the camera componentSET_MESSAGE_INTERVALATTITUDE at 10 Hz, to the autopilotmavlink_message_send(COMMAND_LONG,1,1,511,0,30,100000)(ATTITUDE at 10 Hz)REQUEST_DATA_STREAMfor all streams at 2 HzSET_MESSAGE_INTERVALSYS_STATUS off (-1), to the autopilotREQUEST_DATA_STREAMfor all streams at 0 HzNot 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.