Repository navigation
Conversation
wait_gps_fix(), motors_armed_wait() and motors_disarmed_wait() block until the condition is met, so a script hangs for ever if the vehicle never gets a fix, never arms or the link drops. Each now takes an optional timeout in seconds. wait_gps_fix() returns None on timeout and the GPS_RAW_INT message otherwise. The arm and disarm waits return False on timeout and True otherwise. With no timeout they behave as before. The new tests drive a connection over local UDP with fake heartbeat, VFR_HUD and GPS_RAW_INT messages and check both outcomes, including a wait with nothing on the other end of the link.
Author
|
Related to #1008: that script sends the arm command and then calls |
With a timeout and no heartbeat at all, motors_disarmed_wait() checked the default arm state. That default is disarmed, so it returned True. The arm state waits now return False as soon as wait_heartbeat() times out, so a match always comes from a real heartbeat. Added a test for a disarmed wait with nothing on the other end of the link.
zaccesss
force-pushed
the
mavutil-wait-timeouts
branch
from
November 5, 2026 13:28
4e633da to
848a0b6
Compare
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.
wait_gps_fix(),motors_armed_wait()andmotors_disarmed_wait()block until their condition is met, so a script hangs for ever if the vehicle never gets a fix, never arms or the link drops.I ran into this in a SITL mission script for a university team project. The first arm command is often refused while the EKF settles after the GPS fix, so I had to write my own arm and GPS fix loops with deadlines because
motors_armed_wait()andwait_gps_fix()would otherwise wait for ever.Each now takes an optional
timeoutin seconds:wait_gps_fix(timeout=None)returnsNoneon timeout and theGPS_RAW_INTmessage once there is a 3D fixmotors_armed_wait(timeout=None)andmotors_disarmed_wait(timeout=None)returnFalseon timeout andTrueonce the arm state matchesWith no timeout they still block exactly as before. The only difference for existing callers is that they now return a value (the message or
True) instead ofNone. The one caller inside pymavlink,location(), ignores it.The arm state waits only report a match from a real
HEARTBEAT. If the timeout passes with no heartbeat at all they returnFalse, rather than reading the default arm state (disarmed), which would otherwise makemotors_disarmed_wait()report success with no vehicle connected. That is the second commit.How I checked it
tests/test_mavutil_wait.py(8 tests) drives a real connection over local UDP. A second connection plays the vehicle and sendsHEARTBEAT,VFR_HUDandGPS_RAW_INTmessages. Each helper is tested for returning on time and for timing out. Both arm state waits are also tested with nothing on the other end of the link.pip install ., run from outside the source tree so the installed copy is imported). They pass with this change. With the oldmavutil.pyswapped back in, the new tests fail, so they test the change and not something else.gccand fail on macOS with or without this change.flake8is clean on the new test file. The changedmavutil.pylines pass the CI syntax check (--select=E9,F63,F7,F82).timeout=Nonepaths:recv_match()withblocking=Trueand no timeout never returnsNone, so the old blocking behaviour is unchanged.