mocap: add reset_counter, quality, estimator_type to odometry messages#395
Merged
julianoes merged 2 commits intomavlink:mainfrom Mar 29, 2026
Merged
Conversation
Add fields that PX4's EKF2 uses for better sensor fusion but were previously hardcoded in the C++ implementation: - reset_counter: EKF2 uses this to detect estimator re-initialization and perform state resets (currently hardcoded to 0, with FIXME in C++) - estimator_type: Allows distinguishing VIO from MOCAP estimators (currently hardcoded to MAV_ESTIMATOR_TYPE_MOCAP) - quality: Confidence metric (0-100%) that EKF2 can use to scale measurement noise (currently hardcoded to 0) Also adds MavEstimatorType enum matching MAVLink's MAV_ESTIMATOR_TYPE, and reset_counter to VisionPositionEstimate. All new fields use proto3 defaults (0), preserving backward compatibility.
alireza787b
pushed a commit
to alireza787b/MAVSDK
that referenced
this pull request
Mar 10, 2026
Replace hardcoded values with the corresponding proto fields added in mavlink/MAVSDK-Proto#395: - send_vision_position_estimate: use reset_counter field instead of hardcoded 0 (resolves the FIXME comment) - send_odometry: use reset_counter, estimator_type, quality fields instead of hardcoded 0/MAV_ESTIMATOR_TYPE_MOCAP/0 Also fixes frame_id mapping: the proto MavFrame enum uses values that don't match MAVLink (0 instead of 14 for MOCAP_NED), so add a switch to map to correct MAVLink MAV_FRAME values. For backward compatibility, estimator_type defaults to MAV_ESTIMATOR_TYPE_MOCAP when set to UNKNOWN.
alireza787b
pushed a commit
to alireza787b/MAVSDK
that referenced
this pull request
Mar 10, 2026
Replace hardcoded values with the corresponding proto fields added in mavlink/MAVSDK-Proto#395: - send_vision_position_estimate: use reset_counter field instead of hardcoded 0 (resolves the FIXME comment) - send_vision_speed_estimate: use reset_counter field instead of hardcoded 0 (resolves the FIXME comment) - send_odometry: use reset_counter, estimator_type, quality fields instead of hardcoded 0/MAV_ESTIMATOR_TYPE_MOCAP/0 Also fixes frame_id mapping: the proto MavFrame enum uses values that don't match MAVLink (0 instead of 14 for MOCAP_NED), so add a switch to map to correct MAVLink MAV_FRAME values. For backward compatibility, estimator_type defaults to MAV_ESTIMATOR_TYPE_MOCAP when set to UNKNOWN.
Collaborator
JonasVautherin
left a comment
There was a problem hiding this comment.
Thanks for the contribution! Looks fine to me, though I'm not knowledgeable regarding the mocap stuff. I'll let @julianoes be the judge of that 😇
| Covariance velocity_covariance = 8; // Velocity cross-covariance matrix. | ||
| uint32 reset_counter = 9; // Estimate reset counter, for PX4 EKF2 fusion reset detection. | ||
| MavEstimatorType estimator_type = 10; // Type of estimator (defaults to UNKNOWN, C++ impl falls back to MOCAP). | ||
| int32 quality = 11; // Estimate quality in percent (0-100), -1 for invalid/unknown. |
Collaborator
There was a problem hiding this comment.
I think we usually add the unit to the name:
Suggested change
| int32 quality = 11; // Estimate quality in percent (0-100), -1 for invalid/unknown. | |
| int32 quality_percent = 11; // Estimate quality in percent (0-100), -1 for invalid/unknown. |
Contributor
Author
There was a problem hiding this comment.
Good catch, thanks Jonas! Renamed to quality_percent (int32, -1 for unknown). Updated in the latest push.
Apply review feedback: rename quality to quality_percent with unit in name, change type to int32 so -1 can indicate invalid/unknown. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
JonasVautherin
approved these changes
Mar 11, 2026
julianoes
approved these changes
Mar 12, 2026
julianoes
approved these changes
Mar 29, 2026
Collaborator
|
I tried this, and it doesn't build at all: I'm not sure what to do with the frame stuff, especially because you are using I'm reverting this one and leave this to you to try to fix, given you have the context. |
julianoes
added a commit
to alireza787b/MAVSDK
that referenced
this pull request
Apr 1, 2026
…oto fields Replace hardcoded values with the corresponding proto fields added in mavlink/MAVSDK-Proto#395: - send_vision_position_estimate: use reset_counter field instead of hardcoded 0 - send_vision_speed_estimate: use reset_counter field instead of hardcoded 0 - send_odometry: use reset_counter, estimator_type, quality_percent fields instead of hardcoded 0/MAV_ESTIMATOR_TYPE_MOCAP/0 For backward compatibility, estimator_type defaults to MAV_ESTIMATOR_TYPE_MOCAP when set to Unknown. Co-authored-by: Julian Oes <julian@oes.ch>
julianoes
added a commit
to alireza787b/MAVSDK
that referenced
this pull request
Apr 1, 2026
…oto fields Replace hardcoded values with the corresponding proto fields added in mavlink/MAVSDK-Proto#395: - send_vision_position_estimate: use reset_counter field instead of hardcoded 0 - send_vision_speed_estimate: use reset_counter field instead of hardcoded 0 - send_odometry: use reset_counter, estimator_type, quality_percent fields instead of hardcoded 0/MAV_ESTIMATOR_TYPE_MOCAP/0 For backward compatibility, estimator_type defaults to MAV_ESTIMATOR_TYPE_MOCAP when set to Unknown. Co-authored-by: Julian Oes <julian@oes.ch>
julianoes
added a commit
to mavlink/MAVSDK
that referenced
this pull request
Apr 1, 2026
…oto fields (#2791) Replace hardcoded values with the corresponding proto fields added in mavlink/MAVSDK-Proto#395: - send_vision_position_estimate: use reset_counter field instead of hardcoded 0 - send_vision_speed_estimate: use reset_counter field instead of hardcoded 0 - send_odometry: use reset_counter, estimator_type, quality_percent fields instead of hardcoded 0/MAV_ESTIMATOR_TYPE_MOCAP/0 For backward compatibility, estimator_type defaults to MAV_ESTIMATOR_TYPE_MOCAP when set to Unknown. Co-authored-by: alireza787b <alireza787b@gmail.com> Co-authored-by: Julian Oes <julian@oes.ch>
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
The Mocap plugin's
OdometryandVisionPositionEstimatemessages are missingfields that PX4's EKF2 can use for better sensor fusion. In the C++ implementation
(
mocap_impl.cpp), these values are hardcoded:reset_counter: Hardcoded to0with// FIXME: reset_counter not setcomments.EKF2 uses this to detect when the external estimator has re-initialized, so it can
perform its own state reset rather than trying to fuse a discontinuous measurement.
estimator_type: Hardcoded toMAV_ESTIMATOR_TYPE_MOCAP. For VIO users, thisshould be
MAV_ESTIMATOR_TYPE_VIO. PX4's EKF2 can use this to select appropriatenoise models.
quality: Hardcoded to0. PX4 can scale measurement noise based on thisconfidence metric — low quality = high noise = less influence on state estimate.
Changes
MavEstimatorTypeenum (nested inOdometry) matching MAVLink'sMAV_ESTIMATOR_TYPEreset_counter(field 9),estimator_type(field 10),quality(field 11) toOdometryreset_counter(field 5) toVisionPositionEstimateBackward Compatibility
All new fields use proto3 defaults (0), preserving existing behavior:
reset_counter = 0→ same as current (no resets reported)estimator_type = UNKNOWN (0)→ C++ impl can default to MOCAP for backward compatquality = 0→ PX4 already handles 0 as "unknown quality"This is a non-breaking, additive change. Existing users are unaffected.
Related PRs
mocap_impl.cppreset_counter,estimator_type,quality