Skip to content

feat: Adding and implementing set_mavlink_version function in mavutil.py#1207

Open
noahredon wants to merge 3 commits into
ArduPilot:masterfrom
noahredon:feat/set_mavlink_version
Open

feat: Adding and implementing set_mavlink_version function in mavutil.py#1207
noahredon wants to merge 3 commits into
ArduPilot:masterfrom
noahredon:feat/set_mavlink_version

Conversation

@noahredon

Copy link
Copy Markdown
Contributor

Hi! I thought having a simple function capable of changing the MAVLink version could be useful. For example, if you create a custom MAVLink dialect for MAVLink 2 only and don't change the version before setting the dialect, the script will try to import the default MAVLink 1 dialect, which will crash.

I've tested it, and it works as expected.

I also implemented it in mavfile.auto_mavlink_version for better readability.

@g-ampo

g-ampo commented Apr 30, 2026

Copy link
Copy Markdown

Tested with a v2-only dialect :

  set_mavlink_version(2.0); set_dialect('fooz')  -> OK
  set_mavlink_version(1.0)                       -> FileNotFoundError on '../message_definitions/v1.0/fooz.xml'

set_dialect's auto-gen fallback hits an XML lookup that appearently doesn't exist for a single-version dialect... its not a bug in this PR that you made (existing set_dialect behaviour) but the new docstring is the obvious place to flag it since you are adding it :)

something like an alert/warning would be nice to see

@noahredon noahredon force-pushed the feat/set_mavlink_version branch from ddd09aa to 453c3c8 Compare April 30, 2026 13:43
@noahredon noahredon force-pushed the feat/set_mavlink_version branch from 5d01363 to 9c07a2e Compare April 30, 2026 13:46
@noahredon

Copy link
Copy Markdown
Contributor Author

Thanks for testing this and for the feedback!

I just updated the PR to add a warning in the docstring about this specific edge case.

To be honest, this is actually the behavior I was aiming for. It makes sense that the script fails and stops execution if it tries to load a dialect that doesn't exist for the newly selected MAVLink version. In this case, you only need to set the MAVLink version before the dialect, which makes sense. And for most cases (for example when using a common dialect like ardupilotmega), it works perfectly fine.

Let me know if the updated docstring looks good to you!

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