Skip to content

Conversation

@jonathanreeves
Copy link
Contributor

Summary Of Changes

This is the companion PR to the proto changes made here:
mavlink/MAVSDK-Proto#391

The PR implements the changes associated with the proto updates, and also adds support for the MAVLINK SET_MODE command

Justification For Changes

In addition to the notes provided in the proto PR, the main reason for adding the SET_MODE support is that this command is still the primary means by which QGroundControl sets flight mode on an autopilot, and in particular PX4. Since flight modes in MAVSDK are forced to be PX4 custom, in order to be interoperable with QGC in a straightforward way, we need to handle SET_MODE instead of DO_SET_MODE.

As a note about some of the stickier nuance here, QGC expects all custom flight modes to be represented as a single 32-bit value, which is indeed how the SET_MODE command treats it. DO_SET_MODE breaks this into two separate fields. QGroundControl could also be updated to expand this (and arguably should be), but there's also no reason that MAVSDK can't support this very standard MAVLINK message.

As always please don't hesitate to reach out with questions.

@jonathanreeves
Copy link
Contributor Author

Just FYI I'm working on the mavsdk_server fix, I thought I would be able to re-use datatypes in the proto but I was wrong. Will push fix soon

@jonathanreeves
Copy link
Contributor Author

Should be good to go now (I think)

if (allow_mode) {
px4_mode.main_mode = custom_mode;
px4_mode.sub_mode = sub_custom_mode;
uint8_t system_base_mode = get_base_mode();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting: I added this because the CUSTOM_MODE_ENABLED flag is required to correctly interpret the custom mode, but it's not set here. You can get into a situation where the default state is "non custom", but the ground station attempts to set a custom mode and it isn't actually recorded as custom.

@julianoes
Copy link
Collaborator

We'll have to wait until GitHub Actions are happy again.

@jonathanreeves
Copy link
Contributor Author

We'll have to wait until GitHub Actions are happy again.

Not the first time I've opened a PR on a github "down day". Starting to wonder if it's me 😅

@jonathanreeves
Copy link
Contributor Author

Looking better now

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 3, 2026

@julianoes julianoes merged commit b84eae3 into mavlink:main Feb 3, 2026
58 checks passed
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