ESC check: Avoid unsigned timestamp underflow in telemtry timeout #24069
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.
Solved Problem
During several flights a warning of ESC telemetry missing appear.
Solution
Changing the logic of the if statement to avoid unsigned int underflow.
Test coverage
Tested on a drone with QGC
Context
The tasks are prioritized and the driver has a higher priority than the commander checks. If anything delays driver, then the difference between the absolute time
now
and the latest published sample time from the esc statusesc_status.timestamp
might cause an unsigned integer underflow as theesc_status.timestamp
becomes greater thannow
.To test this hypothesis a sleep was introduced as below:
with following printout:
By changing the formula as in the commit, the if statement would fail ones the
esc_status.timestamp
stop being published, and if there is a delay the new line of code will avoid the wrapping of the negative subtraction:Even with 1 s of sleep there was no telemetry missing message: