Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ docs/node_modules/
docs/.vitepress/cache/
docs/.vitepress/dist/

# Fuzzing
fuzz_corpus
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ void | [set_always_send_heartbeats](#classmavsdk_1_1_mavsdk_1_1_configuration_1a
void | [set_component_type](#classmavsdk_1_1_mavsdk_1_1_configuration_1a06461b86734eaa9544e80a4a907c9754) ([ComponentType](namespacemavsdk.md#namespacemavsdk_1a20fe7f7c8312779a187017111bf33d12) component_type) | Set the component type of this configuration.
uint8_t | [get_mav_type](#classmavsdk_1_1_mavsdk_1_1_configuration_1aafe9e8fc11dd0b688a836c123357e9ba) () const | Get the mav type (vehicle type) of this configuration.
void | [set_mav_type](#classmavsdk_1_1_mavsdk_1_1_configuration_1a16db98d8802c3427b1be10f0b72b977b) (uint8_t mav_type) | Set the mav type (vehicle type) of this configuration.
[Autopilot](namespacemavsdk.md#namespacemavsdk_1aba05635d1785223a4d7b457ae0407297) | [get_autopilot](#classmavsdk_1_1_mavsdk_1_1_configuration_1a107d3f21ade989a58b976475ea7b7672) () const | Get the autopilot type for server identification in heartbeats.
void | [set_autopilot](#classmavsdk_1_1_mavsdk_1_1_configuration_1a9798ed5eb7fb64c492275e970fadc1e7) ([Autopilot](namespacemavsdk.md#namespacemavsdk_1aba05635d1785223a4d7b457ae0407297) autopilot) | Set the autopilot type for server identification.
[CompatibilityMode](namespacemavsdk.md#namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00) | [get_compatibility_mode](#classmavsdk_1_1_mavsdk_1_1_configuration_1abfe7d151a85c65dc6454ebeb645732ef) () const | Get the compatibility mode.
void | [set_compatibility_mode](#classmavsdk_1_1_mavsdk_1_1_configuration_1ab26137a0ead379a702b404f6e92d624f) ([CompatibilityMode](namespacemavsdk.md#namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00) mode) | Set the compatibility mode.


## Constructor & Destructor Documentation
Expand Down Expand Up @@ -202,4 +206,74 @@ Set the mav type (vehicle type) of this configuration.

**Parameters**

* uint8_t **mav_type** -
* uint8_t **mav_type** -

### get_autopilot() {#classmavsdk_1_1_mavsdk_1_1_configuration_1a107d3f21ade989a58b976475ea7b7672}
```cpp
Autopilot mavsdk::Mavsdk::Configuration::get_autopilot() const
```


Get the autopilot type for server identification in heartbeats.


**Returns**

 [Autopilot](namespacemavsdk.md#namespacemavsdk_1aba05635d1785223a4d7b457ae0407297) - The autopilot type used in outgoing heartbeats.

### set_autopilot() {#classmavsdk_1_1_mavsdk_1_1_configuration_1a9798ed5eb7fb64c492275e970fadc1e7}
```cpp
void mavsdk::Mavsdk::Configuration::set_autopilot(Autopilot autopilot)
```


Set the autopilot type for server identification.

When MAVSDK acts as an autopilot server, this determines the MAV_AUTOPILOT value sent in heartbeats.


Default: Autopilot::Unknown (maps to MAV_AUTOPILOT_GENERIC)

**Parameters**

* [Autopilot](namespacemavsdk.md#namespacemavsdk_1aba05635d1785223a4d7b457ae0407297) **autopilot** -

### get_compatibility_mode() {#classmavsdk_1_1_mavsdk_1_1_configuration_1abfe7d151a85c65dc6454ebeb645732ef}
```cpp
CompatibilityMode mavsdk::Mavsdk::Configuration::get_compatibility_mode() const
```


Get the compatibility mode.


**Returns**

 [CompatibilityMode](namespacemavsdk.md#namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00) - The current compatibility mode.

### set_compatibility_mode() {#classmavsdk_1_1_mavsdk_1_1_configuration_1ab26137a0ead379a702b404f6e92d624f}
```cpp
void mavsdk::Mavsdk::Configuration::set_compatibility_mode(CompatibilityMode mode)
```


Set the compatibility mode.

This determines which autopilot-specific quirks are used:
<ul>
<li><p>Auto: Use detected autopilot (default, current behavior)</p>
</li>
<li><p>Pure: Pure standard MAVLink, no autopilot-specific quirks</p>
</li>
<li><p>Px4: Force PX4 quirks regardless of detection</p>
</li>
<li><p>ArduPilot: Force ArduPilot quirks regardless of detection</p>
</li>
</ul>


Default: [CompatibilityMode::Auto](namespacemavsdk.md#namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00a06b9281e396db002010bde1de57262eb)

**Parameters**

* [CompatibilityMode](namespacemavsdk.md#namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00) **mode** -
42 changes: 42 additions & 0 deletions docs/en/cpp/api_reference/namespacemavsdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Namespace for all mavsdk types.
Type | Description
--- | ---
enum [Autopilot](#namespacemavsdk_1aba05635d1785223a4d7b457ae0407297) | Autopilot type.
enum [CompatibilityMode](#namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00) | Compatibility mode for MAVLink protocol behavior.
enum [ComponentType](#namespacemavsdk_1a20fe7f7c8312779a187017111bf33d12) | ComponentType of configurations, used for automatic ID setting.
enum [ConnectionResult](#namespacemavsdk_1a0bad93f6d037051ac3906a0bcc09f992) | Result type returned when adding a connection.
enum [ForwardingOption](#namespacemavsdk_1a7066729108eae8a605d4dd169e4581b9) | ForwardingOption for Connection, used to set message forwarding option.
Expand All @@ -71,6 +72,7 @@ Type | Name | Description
std::ostream & | [operator<<](#namespacemavsdk_1ad782054ca8c33116d0210acca8c55ce6) (std::ostream & os, const [Autopilot](namespacemavsdk.md#namespacemavsdk_1aba05635d1785223a4d7b457ae0407297) & autopilot) | Stream operator to print information about an `Autopilot`.
std::string | [base64_encode](#namespacemavsdk_1a57a9962be22a61e5c36a66bc17e6a2a7) (std::vector< uint8_t > & raw) | Encode raw bytes to a base64 string.
std::vector< uint8_t > | [base64_decode](#namespacemavsdk_1a34e7609c9e2ddcc72a74bbc79daf9c19) (const std::string & str) | Decode a base64 string into raw bytes.
std::ostream & | [operator<<](#namespacemavsdk_1aab2fde9b1e274959eb378afef9e0747f) (std::ostream & os, const [CompatibilityMode](namespacemavsdk.md#namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00) & mode) | Stream operator to print information about a `CompatibilityMode`.
std::ostream & | [operator<<](#namespacemavsdk_1a2aa91d8b846b07fe7f305b399375ce5f) (std::ostream & str, const [ConnectionResult](namespacemavsdk.md#namespacemavsdk_1a0bad93f6d037051ac3906a0bcc09f992) & result) | Stream operator to print information about a `ConnectionResult`.
&nbsp; | [overloaded](#namespacemavsdk_1a724e321aaff91eb2ba28279e0292e552) (Ts...)-> overloaded< Ts... > | Template deduction helper for `overloaded`
std::ostream & | [operator<<](#namespacemavsdk_1a3e7a55e89629afd2a079d79c047e8dbd) (std::ostream & os, const [Vehicle](namespacemavsdk.md#namespacemavsdk_1a9e3a3a502dc8313cb931a8a44cc6f95b) & vehicle) | Stream operator to print information about a `Vehicle`.
Expand All @@ -95,6 +97,24 @@ Value | Description
<span id="namespacemavsdk_1aba05635d1785223a4d7b457ae0407297a31e54e53a62995611ff9ccc0dd9cb510"></span> `Px4` |
<span id="namespacemavsdk_1aba05635d1785223a4d7b457ae0407297a1f79341042063f30812f2942a48d19ed"></span> `ArduPilot` |

### enum CompatibilityMode {#namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00}

```
#include: compatibility_mode.h
```


Compatibility mode for MAVLink protocol behavior.

This setting determines which autopilot-specific quirks and behaviors are used when communicating via MAVLink.

Value | Description
--- | ---
<span id="namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00a06b9281e396db002010bde1de57262eb"></span> `Auto` | Use detected autopilot (default, current behavior)
<span id="namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00ad30973809f2e4238b7eb2bac9241674c"></span> `Pure` | Pure standard MAVLink - no autopilot-specific quirks.
<span id="namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00a31e54e53a62995611ff9ccc0dd9cb510"></span> `Px4` | Force PX4 quirks regardless of detection.
<span id="namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00a1f79341042063f30812f2942a48d19ed"></span> `ArduPilot` | Force ArduPilot quirks regardless of detection.

### enum ComponentType {#namespacemavsdk_1a20fe7f7c8312779a187017111bf33d12}

```
Expand Down Expand Up @@ -269,6 +289,28 @@ Decode a base64 string into raw bytes.

&emsp;std::vector< uint8_t > - Raw bytes

### operator<<() {#namespacemavsdk_1aab2fde9b1e274959eb378afef9e0747f}

```
#include: compatibility_mode.h
```
```cpp
std::ostream & mavsdk::operator<<(std::ostream &os, const CompatibilityMode &mode)
```


Stream operator to print information about a `CompatibilityMode`.


**Parameters**

* std::ostream& **os** -
* const [CompatibilityMode](namespacemavsdk.md#namespacemavsdk_1af0f9146b2086797ae56671d20bd29d00)& **mode** -

**Returns**

&emsp;std::ostream & - A reference to the stream.

### operator<<() {#namespacemavsdk_1a2aa91d8b846b07fe7f305b399375ce5f}

```
Expand Down
21 changes: 21 additions & 0 deletions docs/en/cpp/guide/general_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ Similarly, other autopilots may well work, but, they are not explicitly supporte

Compatibility with ArduPilot is added piece by piece as functionality is used/tested with it.

### Compatibility Mode {#compatibility_mode}

MAVSDK supports different compatibility modes to handle autopilot-specific behaviors:

- **Auto** (default): Detects the autopilot type from heartbeat messages and applies appropriate quirks for PX4 or ArduPilot.
- **Pure**: Uses standard MAVLink behavior without autopilot-specific quirks. Useful for testing MAVLink standard compliance of autopilot implementations.
- **Px4**: Forces PX4-specific behavior regardless of detected autopilot.
- **ArduPilot**: Forces ArduPilot-specific behavior regardless of detected autopilot.

To set the compatibility mode:

```cpp
Mavsdk::Configuration config(ComponentType::GroundStation);
config.set_compatibility_mode(CompatibilityMode::Pure);
Mavsdk mavsdk(config);
```

::: info
In Pure mode, some features that rely on autopilot-specific parameters or protocols will return `Unsupported` (e.g., RTL altitude settings, calibration progress). Flight mode detection may also be limited as it requires MAVLink standard modes support.
:::

### Connection Strings {#connection_string}

MAVSDK monitors a specified port for vehicles, see [Connecting to Systems (Vehicles)](../guide/connections.md).
Expand Down
2 changes: 2 additions & 0 deletions src/mavsdk/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ target_sources(mavsdk
PRIVATE
autopilot.cpp
base64.cpp
compatibility_mode.cpp
call_every_handler.cpp
callback_tracker.cpp
connection.cpp
Expand Down Expand Up @@ -202,6 +203,7 @@ install(TARGETS mavsdk
install(FILES
include/mavsdk/autopilot.h
include/mavsdk/base64.h
include/mavsdk/compatibility_mode.h
include/mavsdk/component_type.h
include/mavsdk/connection_result.h
include/mavsdk/deprecated.h
Expand Down
21 changes: 21 additions & 0 deletions src/mavsdk/core/compatibility_mode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "compatibility_mode.h"

namespace mavsdk {

std::ostream& operator<<(std::ostream& os, const CompatibilityMode& mode)
{
switch (mode) {
case CompatibilityMode::Auto:
return os << "Auto";
case CompatibilityMode::Pure:
return os << "Pure";
case CompatibilityMode::Px4:
return os << "Px4";
case CompatibilityMode::ArduPilot:
return os << "ArduPilot";
default:
return os << "Unknown";
}
}

} // namespace mavsdk
2 changes: 2 additions & 0 deletions src/mavsdk/core/flight_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace mavsdk {

// TODO: Implement MAVLink standard modes (MAV_STANDARD_MODE) for Pure mode.
// Both PX4 and ArduPilot currently use custom/non-standard mode definitions.
FlightMode
to_flight_mode_from_custom_mode(Autopilot autopilot, MAV_TYPE mav_type, uint32_t custom_mode)
{
Expand Down
27 changes: 27 additions & 0 deletions src/mavsdk/core/include/mavsdk/compatibility_mode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <sstream>

namespace mavsdk {

/**
* @brief Compatibility mode for MAVLink protocol behavior.
*
* This setting determines which autopilot-specific quirks and behaviors
* are used when communicating via MAVLink.
*/
enum class CompatibilityMode {
Auto, ///< Use detected autopilot (default, current behavior)
Pure, ///< Pure standard MAVLink - no autopilot-specific quirks
Px4, ///< Force PX4 quirks regardless of detection
ArduPilot, ///< Force ArduPilot quirks regardless of detection
};

/**
* @brief Stream operator to print information about a `CompatibilityMode`.
*
* @return A reference to the stream.
*/
std::ostream& operator<<(std::ostream& os, const CompatibilityMode& mode);

} // namespace mavsdk
40 changes: 39 additions & 1 deletion src/mavsdk/core/include/mavsdk/mavsdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <vector>
#include <functional>

#include "autopilot.h"
#include "compatibility_mode.h"
#include "deprecated.h"
#include "handle.h"
#include "system.h"
Expand Down Expand Up @@ -260,15 +262,51 @@ class Mavsdk {
*/
void set_mav_type(uint8_t mav_type);

/**
* @brief Get the autopilot type for server identification in heartbeats.
* @return The autopilot type used in outgoing heartbeats.
*/
Autopilot get_autopilot() const;

/**
* @brief Set the autopilot type for server identification.
*
* When MAVSDK acts as an autopilot server, this determines
* the MAV_AUTOPILOT value sent in heartbeats.
*
* Default: Autopilot::Unknown (maps to MAV_AUTOPILOT_GENERIC)
*/
void set_autopilot(Autopilot autopilot);

/**
* @brief Get the compatibility mode.
* @return The current compatibility mode.
*/
CompatibilityMode get_compatibility_mode() const;

/**
* @brief Set the compatibility mode.
*
* This determines which autopilot-specific quirks are used:
* - Auto: Use detected autopilot (default, current behavior)
* - Pure: Pure standard MAVLink, no autopilot-specific quirks
* - Px4: Force PX4 quirks regardless of detection
* - ArduPilot: Force ArduPilot quirks regardless of detection
*
* Default: CompatibilityMode::Auto
*/
void set_compatibility_mode(CompatibilityMode mode);

private:
uint8_t _system_id;
uint8_t _component_id;
bool _always_send_heartbeats;
ComponentType _component_type;
MAV_TYPE _mav_type;
Autopilot _autopilot{Autopilot::Unknown};
CompatibilityMode _compatibility_mode{CompatibilityMode::Auto};

static ComponentType component_type_for_component_id(uint8_t component_id);
static MAV_TYPE mav_type_for_component_type(ComponentType component_type);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/mavsdk/core/include/mavsdk/server_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ServerComponent {
*
* This constructor is not (and should not be) directly called by application code.
*/
ServerComponent(MavsdkImpl& mavsdk_impl, uint8_t component_id);
ServerComponent(MavsdkImpl& mavsdk_impl, uint8_t component_id, uint8_t mav_type);

/**
* @brief Destructor.
Expand Down
2 changes: 1 addition & 1 deletion src/mavsdk/core/mavlink_command_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ float MavlinkCommandSender::maybe_reserved(const std::optional<float>& maybe_par
return maybe_param.value();

} else {
if (_system_impl.autopilot() == Autopilot::ArduPilot) {
if (_system_impl.effective_autopilot() == Autopilot::ArduPilot) {
return 0.0f;
} else {
return NAN;
Expand Down
2 changes: 1 addition & 1 deletion src/mavsdk/core/mavlink_mission_transfer_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MavlinkMissionTransferClientTest : public ::testing::Test {
ON_CALL(mock_sender, get_own_system_id()).WillByDefault(Return(own_address.system_id));
ON_CALL(mock_sender, get_own_component_id())
.WillByDefault(Return(own_address.component_id));
ON_CALL(mock_sender, autopilot()).WillByDefault(Return(Autopilot::Px4));
ON_CALL(mock_sender, compatibility_mode()).WillByDefault(Return(CompatibilityMode::Auto));
}

MockSender mock_sender;
Expand Down
2 changes: 1 addition & 1 deletion src/mavsdk/core/mavlink_mission_transfer_server_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MavlinkMissionTransferServerTest : public ::testing::Test {
ON_CALL(mock_sender, get_own_system_id()).WillByDefault(Return(own_address.system_id));
ON_CALL(mock_sender, get_own_component_id())
.WillByDefault(Return(own_address.component_id));
ON_CALL(mock_sender, autopilot()).WillByDefault(Return(Autopilot::Px4));
ON_CALL(mock_sender, compatibility_mode()).WillByDefault(Return(CompatibilityMode::Auto));
}

static ItemInt make_item(uint8_t type, uint16_t sequence)
Expand Down
2 changes: 1 addition & 1 deletion src/mavsdk/core/mavlink_parameter_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ void MavlinkParameterServer::do_work()
} else {
LogWarn() << "sending not extended message";
float param_value;
if (_sender.autopilot() == Autopilot::ArduPilot) {
if (_sender.compatibility_mode() == CompatibilityMode::ArduPilot) {
param_value = work->param_value.get_4_float_bytes_cast();
} else {
param_value = work->param_value.get_4_float_bytes_bytewise();
Expand Down
Loading
Loading