offboard: give watchdog grace period from when setpoints start#2927
Merged
Conversation
process_heartbeat() stops setpoint streaming when the vehicle is not in offboard mode more than 3 seconds after _last_started. However, _last_started is only ever written in start(), so before the first start() it is still default-initialized (epoch 0) and the 3-second guard is always satisfied: any heartbeat arriving between the first set_*() and start() resets the setpoint state, and start() then fails with NoSetpointSet. In real-time use the window between set_*() and start() is rarely hit at 1 Hz heartbeats. In lockstep simulation with a speed factor this becomes frequent: at 30x, PX4's heartbeats arrive every ~33 ms of wall time, and the PX4 SITL integration tests failed on Offboard::start() roughly one run in three. Stamp _last_started whenever streaming transitions out of NotActive, so the watchdog's grace period covers the gap between the first setpoint and start(), as intended by the existing 'don't stop too eagerly' comment. We also rename _last_started because the name isn't quite right. Signed-off-by: Julian Oes <julian@oes.ch>
julianoes
force-pushed
the
fix-offboard-premature-watchdog
branch
from
July 15, 2026 21:41
7453dcc to
dfc69b5
Compare
julianoes
added a commit
that referenced
this pull request
Jul 16, 2026
Backport of dfc69b5 (#2927). process_heartbeat() stops setpoint streaming when the vehicle is not in offboard mode more than 3 seconds after the grace start. That timestamp was only written in start(), so before the first start() it was still epoch 0 and the guard always passed: any heartbeat between the first set_*() and start() reset the setpoint state, and start() then failed with NoSetpointSet. Frequent under lockstep SITL with a speed factor. Stamp the grace start whenever streaming transitions out of NotActive so the watchdog covers the gap between the first setpoint and start().
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.
Problem
OffboardImpl::process_heartbeat()stops setpoint streaming when the vehicle is not in offboard mode more than 3 seconds after_last_started:However,
_last_startedis only ever written instart(). Before the firststart()call it is still default-initialized (epoch 0), so the 3-second guard is always satisfied. Any heartbeat that arrives between the firstset_*()andstart()therefore resets the setpoint state, andstart()fails withNoSetpointSet— even though the caller followed the documented sequence (set a setpoint, then start).How it was found
In real-time use the window between
set_*()andstart()is almost never hit by a 1 Hz heartbeat. In lockstep simulation with a speed factor it becomes frequent: at speed factor 30, PX4's heartbeats arrive every ~33 ms of wall time, and the PX4 SITL integration tests ('Offboard attitude control') failed onOffboard::start()returningNoSetpointSetroughly one run in three.Fix
Stamp
_last_startedwhenever streaming transitions out ofNotActive(newnote_setpoints_started()helper, called at each mode transition under the existing lock). The watchdog's grace period then covers the gap between the first setpoint andstart(), matching the intent of the existing "we make sure we don't stop too eagerly" comment. Watchdog behaviour is otherwise unchanged: streaming without a successfulstart()still gets stopped, just 3 seconds after it began rather than on the next heartbeat.