ArduPilotPlugin: auto-detect 16/32 servo packet via magic - #161
Open
tetano02 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Updates ArduPilotPlugin to auto-detect whether incoming SITL servo packets contain 16 or 32 channels by inspecting the packet magic at runtime, reducing reliance on static SDF configuration that can drift from SITL settings.
Changes:
- Always receive into the 32-channel packet buffer and infer 16/32 channel mode from packet magic.
- Add size/magic coherence checks and normalize PWM data into a 32-element array.
- Update docs/comments to clarify
<have_32_channels>is now a compatibility/debug hint.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ArduPilotPlugin.cc | Implements runtime magic-based 16/32 detection, size checks, unified PWM normalization, and safer socket drain initialization. |
| include/ArduPilotPlugin.hh | Updates comments to reflect runtime channel auto-detection and re-scopes <have_32_channels> as a hint. |
| README.md | Documents the new 16/32 servo-channel behavior and a manual verification procedure. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
This PR updates
ArduPilotPluginto auto-detect 16 vs 32 servo output channels from packet magic at runtime, instead of relying on static<have_32_channels>configuration.Problem
Current behavior can drop valid packets when SITL channel mode (
SERVO_32_ENABLE) does not match SDF<have_32_channels>, causing protocol magic mismatch warnings and actuator desync.Changes
servo_packet_32) and detect protocol variant from magic:18458-> 16 channels29569-> 32 channels<have_32_channels>for compatibility/debug, but override runtime state when packet magic disagrees.std::array<uint16_t, 32>:pkt_frame_countusesuint32_t, matching thepacket format), avoiding false reset / missed-frame warnings caused by 16-bit wrap.
reinterpret_casttoservo_packet_16).README.md: add Servo Channels behavior and tested procedureArduPilotPlugin.hh: clarify<have_32_channels>as optional compatibility/debug hintWhy this approach
SIM_JSONmagic values) as source of truth.<have_32_channels>.TODOinArduPilotPlugin.hh:handle 16 or 32 based on magic.Manual Testing
Gazebo with log capture:
MAVProxy sequence:
Log check:
rg -n "ArduPilot|magic|Overriding|Connected" /tmp/gz.logObserved in logs:
<have_32_channels>=0 ... detected 32 channels ... Overriding from packet.<have_32_channels>=1 ... detected 16 channels ... Overriding from packet.ArduPilot controller has resetaround SITL reboot (expected transient behavior).Compatibility
No public API changes. Existing SDF files remain valid.