Skip to content

mocap: wire up reset_counter, estimator_type, quality fields#2791

Open
alireza787b wants to merge 2 commits intomavlink:mainfrom
alireza787b:mocap-wire-up-new-fields
Open

mocap: wire up reset_counter, estimator_type, quality fields#2791
alireza787b wants to merge 2 commits intomavlink:mainfrom
alireza787b:mocap-wire-up-new-fields

Conversation

@alireza787b
Copy link
Contributor

@alireza787b alireza787b commented Mar 10, 2026

Problem

The Mocap plugin hardcodes several fields when packing MAVLink messages,
ignoring values that PX4's EKF2 can use for better sensor fusion:

send_vision_position_estimate:

0); // FIXME: reset_counter not set   ← line 119

send_vision_speed_estimate:

0); // FIXME: reset_counter not set   ← line 170

send_odometry:

0,                        // reset_counter hardcoded
MAV_ESTIMATOR_TYPE_MOCAP, // estimator_type hardcoded (wrong for VIO users)
0);                       // quality hardcoded

Additionally, static_cast<uint8_t>(odometry.frame_id) sends the proto enum
value (0) instead of the MAVLink value (14 = MAV_FRAME_MOCAP_NED), because
the proto enum uses sequential values rather than MAVLink values.

Changes

  1. Wire up reset_counter in send_vision_position_estimate — resolves
    the FIXME comment

  2. Wire up reset_counter in send_vision_speed_estimate — resolves
    the FIXME comment

  3. Wire up reset_counter, estimator_type, quality in send_odometry
    — replaces all three hardcoded values with the proto fields

  4. Fix frame_id mapping — add switch to map proto MavFrame enum values
    to correct MAVLink MAV_FRAME constants (14 for MOCAP_NED, 20 for LOCAL_FRD)

  5. Backward compatibility — when estimator_type is UNKNOWN (proto3 default),
    fall back to MAV_ESTIMATOR_TYPE_MOCAP to preserve existing behavior

Dependencies

Related PRs

Testing

After proto submodule update:

cmake -Bbuild/default -S. -DBUILD_MAVSDK_SERVER=ON -DWERROR=ON
cmake --build build/default -j$(nproc)

Verified: all changes maintain backward compatibility — existing users who
don't set the new fields get identical MAVLink output (reset_counter=0,
estimator_type=MOCAP, quality=0, frame_id=MOCAP_NED).

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.
Match proto rename from MAVSDK-Proto PR mavlink#395 review feedback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@alireza787b
Copy link
Contributor Author

Hi — just a note that the CI failures here are expected: this PR references reset_counter, estimator_type, and quality_percent fields that were added in MAVSDK-Proto PR #395, which hasn't been merged yet.

Once #395 is merged and the proto submodule pointer is updated, the build should pass.

Dependency chain:

  1. MAVSDK-Proto fly_qgc_mission: link to json11 #395 (merge) → update proto submodule in MAVSDK → this PR's CI passes
  2. Then MAVSDK-Python Trying out GitLab CI #820 can use the new fields

Happy to rebase or address anything else in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants