### Build examples with static library dependencies Source: https://mavsdk.mavlink.io/main/en/cpp/guide/build_windows.html Configures and builds the examples, passing the install prefix and third-party install path as CMAKE_PREFIX_PATH to provide the static library and its transitive dependencies. ```bash cd examples cmake -G"Ninja" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH="../install;../build/third_party/install" -DCMAKE_INSTALL_PREFIX=install -B build -S . cmake --build build ``` -------------------------------- ### Build an example with cmake Source: https://mavsdk.mavlink.io/main/en/cpp/examples/index.html Builds the takeoff_and_land example. Requires the MAVSDK library to be installed. If MAVSDK is installed locally (e.g., on Windows), pass its location to cmake with -DCMAKE_PREFIX_PATH. ```sh cd cpp/examples/takeoff_and_land/ cmake -B build -S . cmake --build build -j4 ``` -------------------------------- ### Install Boost libraries on Linux Source: https://mavsdk.mavlink.io/main/en/cpp/examples/follow_me.html Install the Boost libraries on Linux before building the example. Required for the Follow Me example to compile and run. ```sh sudo apt-get install libboost-all-dev ``` -------------------------------- ### Build static library and install Source: https://mavsdk.mavlink.io/main/en/cpp/guide/build_windows.html Configures a static library build with RelWithDebInfo, install prefix, server enabled, and WERROR on, then builds the install target. ```bash cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DWERROR=ON -B build -S . cmake --build build --config RelWithDebInfo --target install ``` -------------------------------- ### Start, set target location, and stop following Source: https://mavsdk.mavlink.io/main/en/cpp/guide/follow_me.html Starts following, sets a target location, and stops following. The example shows error handling for start and stop. Note that set_target_location can be called anytime but messages are only sent once following is started. ```cpp // Start following FollowMe::Result follow_me_result = follow_me.start(); if (follow_me_result != FollowMe::Result::Success) { // handle start failure (in this case print error) std::cout << "Failed to start following:" << follow_me_result << '\n'; } // Get target position from underlying platform and supply to vehicle. // For this example we just show one point being set (instead of a stream). follow_me.set_target_location({ 47.39776569, 8.54553292, 0.f, 0.f, 0.f, 0.f }); // Stop following follow_me_result = follow_me.stop(); if (follow_me_result != FollowMe::Result::Success) { // handle stop failure (in this case print error) std::cout << "Failed to stop following:" << follow_me_result << '\n'; } ``` -------------------------------- ### start() Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_offboard.html Start offboard control synchronously. ```APIDOC ## start() ### Description Start offboard control. This function is blocking. See 'start_async' for the non-blocking counterpart. ### Parameters None ### Returns - **Result** - Result of request. ``` -------------------------------- ### Build and preview docs locally with npm Source: https://mavsdk.mavlink.io/main/en/cpp/contributing/documentation.html Use this command sequence to install dependencies and start the VitePress development server for local preview. The server runs at http://localhost:5173. ```bash cd docs npm install npm run dev ``` -------------------------------- ### start() method Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_follow_me.html Start FollowMe mode. This function is blocking. ```cpp Result mavsdk::FollowMe::start() const ``` -------------------------------- ### Run Follow Me example with UDP connection Source: https://mavsdk.mavlink.io/main/en/cpp/examples/follow_me.html Run the compiled Follow Me example, connecting to the drone via UDP on port 14540. The example then waits for a system to connect and starts the follow-me sequence. ```sh $ ./follow_me udpin://0.0.0.0:14540 ``` -------------------------------- ### Build takeoff_and_land example Source: https://mavsdk.mavlink.io/main/en/cpp/quickstart.html Configures and builds the takeoff_and_land example using CMake. ```bash cd takeoff_and_land/ cmake -B build -S . cmake --build build -j4 ``` -------------------------------- ### Run example on Windows Source: https://mavsdk.mavlink.io/main/en/cpp/examples/index.html Runs the example on Windows from the build\Debug directory, connecting to the simulator via the UDP port 14540. ```cmd build\Debug\takeoff_and_land.exe udpin://0.0.0.0:14540 ``` -------------------------------- ### Navigate to C++ examples directory Source: https://mavsdk.mavlink.io/main/en/cpp/quickstart.html Changes to the cpp/examples directory where the examples are located. ```bash cd cpp/examples ``` -------------------------------- ### start() Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_offboard.html Start offboard control. Blocking; see 'start_async' for the non-blocking counterpart. ```cpp Result mavsdk::Offboard::start() const ``` -------------------------------- ### Example plugin folder structure Source: https://mavsdk.mavlink.io/main/en/cpp/contributing/plugins.html Shows the required files and structure for a plugin, using the 'example' plugin as an example. Includes CMakeLists.txt, source files, and an optional test file. ```text └── plugins └── example ├── CMakeLists.txt ├── example.cpp ├── example.h ├── example_impl.cpp ├── example_impl.h └── example_foo_test.cpp ##optional ``` -------------------------------- ### Clone MAVSDK repository with examples Source: https://mavsdk.mavlink.io/main/en/cpp/quickstart.html Clones the MAVSDK repository recursively to get the examples source code. ```bash git clone https://github.com/mavlink/MAVSDK.git --recursive cd MAVSDK ``` -------------------------------- ### Local Installation Source: https://mavsdk.mavlink.io/main/en/cpp/guide/build_macos.html Configures a Release build with CMAKE_INSTALL_PREFIX set to 'install' and then runs the install target to put artifacts in that local directory. ```bash cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -B build -S . cmake --build build --target install ``` -------------------------------- ### Install Homebrew and CMake Source: https://mavsdk.mavlink.io/main/en/cpp/guide/build_macos.html Installs Homebrew via the official install script and then uses Homebrew to install CMake. Prepare for the script to prompt for confirmation and possibly require sudo. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew install cmake ``` -------------------------------- ### Run example on Linux/macOS Source: https://mavsdk.mavlink.io/main/en/cpp/examples/index.html Runs the example on Linux/macOS from the build directory, connecting to the simulator via the UDP port 14540. ```sh build/takeoff_and_land udpin://0.0.0.0:14540 ``` -------------------------------- ### System-wide Installation Source: https://mavsdk.mavlink.io/main/en/cpp/guide/build_macos.html Installs the built library system-wide into /usr/local using sudo. ```bash sudo cmake --build build --target install ``` -------------------------------- ### Download and install MAVSDK .deb on Ubuntu Source: https://mavsdk.mavlink.io/main/en/cpp/guide/installation.html Downloads the prebuilt C++ library .deb package from MAVSDK releases and installs it with dpkg. The example uses version v4.0.0 for Ubuntu 24.04 amd64. ```bash wget https://github.com/mavlink/MAVSDK/releases/download/v4.0.0/libmavsdk-dev_4.0.0_ubuntu24.04_amd64.deb sudo dpkg -i libmavsdk-dev_4.0.0_ubuntu24.04_amd64.deb ``` -------------------------------- ### Start offboard mode with set_velocity_body() and start() Source: https://mavsdk.mavlink.io/main/en/cpp/guide/offboard.html Create a setpoint using set_velocity_body() before starting offboard mode, then call start() synchronously. The returned Offboard::Result is checked and a human-readable error is printed on failure. ```cpp // Create a setpoint before starting offboard mode (in this case a null setpoint) offboard.set_velocity_body({0.0f, 0.0f, 0.0f, 0.0f}); // Start offboard mode. Offboard::Result offboard_result = offboard.start(); if (result != Offboard::Result::Success) { std::cerr << "Offboard::start() failed: " << offboard_result << '\n'; } ``` -------------------------------- ### Run takeoff_and_land example Source: https://mavsdk.mavlink.io/main/en/cpp/examples/takeoff_and_land.html Command to run the compiled example with a UDP connection address. The output shows the sequence of discovery, arming, takeoff, altitude telemetry, and landing. ```sh $ ./takeoff_and_land udpin://0.0.0.0:14540 ``` -------------------------------- ### Get System Object from MAVSDK Source: https://mavsdk.mavlink.io/main/en/cpp/guide/system_information.html Assumed preconditions for the examples on this page: include mavsdk.h and obtain the system from the MAVSDK instance. ```cpp System system = mavsdk.systems()[0]; ``` -------------------------------- ### Install XCode Command Line Tools Source: https://mavsdk.mavlink.io/main/en/cpp/guide/build_macos.html Runs xcode-select --install to install the XCode Command Line Tools, a required build dependency. ```bash xcode-select --install ``` -------------------------------- ### Install protoc_gen_mavsdk Source: https://mavsdk.mavlink.io/main/en/cpp/contributing/plugins.html Installs the protoc_gen_mavsdk tool required for auto-generation of plugin files. ```bash pip3 install --user protoc_gen_mavsdk # Or however you install pip packages ``` -------------------------------- ### Local installation of MAVSDK Source: https://mavsdk.mavlink.io/main/en/cpp/guide/build_windows.html Configures and builds the install target with a custom install prefix. ```bash cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -B build -S . cmake --build build --target install ``` -------------------------------- ### Run VTOL Transition Example Source: https://mavsdk.mavlink.io/main/en/cpp/examples/transition_vtol_fixed_wing.html Command to run the VTOL transition example, connecting to a simulated or real VTOL aircraft via UDP on port 14540. ```bash $ ./transition_vtol_fixed_wing udpin://0.0.0.0:14540 ``` -------------------------------- ### Run autopilot_server example Source: https://mavsdk.mavlink.io/main/en/cpp/examples/autopilot_server.html Command to run the autopilot_server example. The output shows MAVSDK version v0.44.0 and a series of debug/info messages, including mission item details and telemetry updates. ```bash $ ./autopilot_server ``` -------------------------------- ### System-wide installation of MAVSDK Source: https://mavsdk.mavlink.io/main/en/cpp/guide/build_windows.html Installs the built MAVSDK system-wide. Requires admin privileges. ```bash # Run in command prompt with admin privileges cmake --build build --target install ``` -------------------------------- ### start_async() Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_offboard.html Start offboard control asynchronously. Non-blocking; see 'start' for the blocking counterpart. ```cpp void mavsdk::Offboard::start_async(const ResultCallback callback) ``` -------------------------------- ### start_async() Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_offboard.html Start offboard control asynchronously. ```APIDOC ## start_async() ### Description Start offboard control. This function is non-blocking. See 'start' for the blocking counterpart. ### Parameters - **const ResultCallback callback** - Callback to receive the result. ### Returns None ``` -------------------------------- ### Run Fly Mission Example Source: https://mavsdk.mavlink.io/main/en/cpp/examples/fly_mission.html Command to run the compiled fly_mission example, connecting via UDP to the specified address. ```bash $ ./fly_mission udpin://0.0.0.0:14540 ``` -------------------------------- ### respond_start_video() Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_camera_server.html Responds to a start video request. ```APIDOC ## respond_start_video() ### Description Subscribe to stop video requests. Each request received should respond using StopVideoResponse. This function is blocking. ### Method respond_start_video ### Parameters - **start_video_feedback** (CameraFeedback) - Required - Feedback result for the start video request. ### Returns - **Result** - Result of request. ``` -------------------------------- ### Follow Me example terminal output Source: https://mavsdk.mavlink.io/main/en/cpp/examples/follow_me.html Example terminal output from a debug build of the SDK when running the Follow Me example. Shows the sequence from connection, arming, takeoff, and follow-me flight with position updates. Release builds omit the 'Debug' messages. ```text [01:55:59|Info ] DronecodeSDK version: 0.2.8 (dronecode_sdk_impl.cpp:25) Wait for system to connect via heartbeat [01:55:59|Info ] New device on: 127.0.0.1:14580 (udp_connection.cpp:200) [01:55:59|Debug] New: System ID: 1 Comp ID: 1 (dronecode_sdk_impl.cpp:286) [01:55:59|Debug] Component Autopilot added. (system_impl.cpp:335) [01:56:00|Debug] Found 1 component(s). (system_impl.cpp:462) [01:56:00|Debug] Discovered 4294967298 (system_impl.cpp:464) Waiting for system to be ready ... Waiting for system to be ready System is ready Armed [01:56:07|Debug] MAVLink: info: ARMED by arm/disarm component command (system_impl.cpp:273) In Air... [01:56:07|Debug] MAVLink: info: Using minimum takeoff altitude: 2.50 m (system_impl.cpp:273) [01:56:07|Debug] MAVLink: info: Takeoff detected (system_impl.cpp:273) [01:56:07|Debug] MAVLink: info: Using minimum takeoff altitude: 2.50 m (system_impl.cpp:273) [FlightMode: Takeoff] Vehicle is at: nan, nan degrees. [FlightMode: Takeoff] Vehicle is at: nan, nan degrees. [FlightMode: Hold] Vehicle is at: nan, nan degrees. [01:56:12|Debug] Waiting for the system confirmation of the new configuration.. (follow_me_impl.cpp:81) [FlightMode: FollowMe] Vehicle is at: nan, nan degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.54559 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.54559 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3976, 8.54559 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3976, 8.54559 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3976, 8.54559 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3975, 8.54559 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3975, 8.54559 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3974, 8.54559 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3974, 8.54559 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3974, 8.54563 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3974, 8.54567 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3974, 8.5457 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3974, 8.54574 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3974, 8.54577 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3974, 8.54581 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3974, 8.54588 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3974, 8.54592 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3974, 8.54595 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3974, 8.54595 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3975, 8.54595 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3975, 8.54595 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3975, 8.54595 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3976, 8.54595 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3976, 8.54595 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.54595 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.54595 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.54595 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.54592 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.54588 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.54581 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.54577 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.54574 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.5457 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.54567 degrees. [FlightMode: FollowMe] Vehicle is at: 47.3977, 8.54563 degrees. ``` -------------------------------- ### Install prerequisites for building without superbuild Source: https://mavsdk.mavlink.io/main/en/cpp/guide/build_linux.html Installs the required system packages needed before running the build script. ```bash sudo apt install build-essential cmake git python3 python3-pip \ liblzma-dev libtinyxml2-dev nlohmann-json3-dev \ libcurl4-openssl-dev libssl-dev ``` -------------------------------- ### System-wide installation of MAVSDK Source: https://mavsdk.mavlink.io/main/en/cpp/guide/build_linux.html Installs MAVSDK system-wide to /usr/local and updates the linker cache. ```bash sudo cmake --build build --target install sudo ldconfig # Update linker cache ``` -------------------------------- ### start_mission Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_mission_raw.html Start the mission synchronously. ```APIDOC ## start_mission ### Description Start the mission synchronously. ### Method Result ### Signature ```cpp Result start_mission() const ``` ### Parameters None. ### Returns - **Result** - The result of the start mission operation. ``` -------------------------------- ### Using MAVSDK plugins in C++ (Action example) Source: https://mavsdk.mavlink.io/main/en/cpp/guide/using_plugins.html Steps to use a MAVSDK plugin in C++: include the plugin header, create a plugin instance bound to a System object, then call its methods. The Action plugin is used as the example. ```cpp #include ``` ```cpp auto action = Action{system}; ``` ```cpp action.takeoff(); ``` -------------------------------- ### respond_zoom_in_start Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_camera_server.html Responds to a zoom in start command. ```APIDOC ## respond_zoom_in_start ### Description Responds to a zoom in start command. ### Method respond_zoom_in_start ### Parameters - **zoom_in_start_feedback** (CameraFeedback) - Required - The feedback for the zoom in start command. ### Returns - **Result** - The result of the operation. ``` -------------------------------- ### respond_focus_in_start Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_camera_server.html Responds to a focus in start command. ```APIDOC ## respond_focus_in_start ### Description Responds to a focus in start command. ### Method respond_focus_in_start ### Parameters - **focus_in_start_feedback** (CameraFeedback) - Required - The feedback for the focus in start command. ### Returns - **Result** - The result of the operation. ``` -------------------------------- ### Start interactive asyncio Python shell Source: https://mavsdk.mavlink.io/main/en/python/quickstart.html Start an interactive Python shell that supports await, which is needed for the asyncio API used in this guide. ```sh python3 -m asyncio ``` -------------------------------- ### subscribe_start_video() Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_camera_server.html Subscribes to start video requests. ```APIDOC ## subscribe_start_video() ### Description Subscribe to start video requests. Each request received should respond to using RespondStartVideo. ### Method subscribe_start_video ### Parameters - **callback** (const StartVideoCallback&) - Required - Callback to be called on start video requests. ### Returns - **StartVideoHandle** - Handle for the subscription. ``` -------------------------------- ### start_video_async() Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_camera.html Asynchronous method to start a video recording. ```APIDOC ## start_video_async() ### Description Start a video recording. This function is non-blocking. See 'start_video' for the blocking counterpart. ### Method void mavsdk::Camera::start_video_async(int32_t component_id, const ResultCallback callback) ### Parameters - **component_id** (int32_t) - Required - Component ID. - **callback** (const ResultCallback) - Required - Callback to receive the result. ### Returns void ``` -------------------------------- ### CameraServer constructor usage example Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_camera_server.html Shows how to create a CameraServer instance with a ServerComponent. ```cpp auto camera_server = CameraServer(server_component); ``` -------------------------------- ### Typical plugin creation with System reference Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_mavlink_direct.html Shows the typical way to create the plugin using a System reference. ```cpp auto mavlink_direct = MavlinkDirect(system); ``` -------------------------------- ### Send a custom MAVLink message with MavlinkDirect::send_message Source: https://mavsdk.mavlink.io/main/en/cpp/guide/mavlink_direct.html Quickstart example showing how to send a custom MAVLink message using the MavlinkDirect plugin. The receiving side must know the message definition; if it uses MAVSDK, it must load the same XML. Forwarding MAVSDK instances do not need to know about it. ```cpp auto result = mavlink_direct.send_message(gas_sensor_message); ``` -------------------------------- ### Info constructor usage example Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_info.html Shows the typical way to create an Info plugin instance using a System reference. ```cpp auto info = Info(system); ``` -------------------------------- ### Create FollowMe plugin instance Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_follow_me.html Example of creating a FollowMe plugin instance using a System object. ```cpp auto follow_me = FollowMe(system); ``` -------------------------------- ### Install MAVSDK on macOS via Homebrew Source: https://mavsdk.mavlink.io/main/en/cpp/guide/installation.html Installs the MAVSDK library using Homebrew. Requires Homebrew to be installed first. ```bash brew install mavsdk ``` -------------------------------- ### Create FtpServer Instance Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_ftp_server.html Example of how to typically create an FtpServer plugin instance. ```cpp auto ftp_server = FtpServer(server_component); ``` -------------------------------- ### Record Video Source: https://mavsdk.mavlink.io/main/en/cpp/guide/camera.html Starts and stops video recording. The camera must be in Video mode before starting; the comment indicates flight operations can occur between start and stop. ```cpp camera.set_mode(component_id, Camera::Mode::Video); camera.start_video(component_id); // ... fly around ... camera.stop_video(component_id); ``` -------------------------------- ### init Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_system.html Initializes the system with the given system ID and component ID. ```APIDOC ## init ### Description Initializes the system with the given system ID and component ID. ### Method void init(uint32_t system_id, uint8_t component_id) const ### Parameters - **system_id** (uint32_t) - The MAVLink system ID. - **component_id** (uint8_t) - The MAVLink component ID. ### Returns void ``` -------------------------------- ### Install MAVSDK with pip Source: https://mavsdk.mavlink.io/main/en/python/quickstart.html Install the MAVSDK Python package from PyPI, ideally in a virtual environment. The package bundles the MAVSDK C++ library, so no additional installation is required. ```sh pip install mavsdk ``` -------------------------------- ### Build with locally installed MAVSDK Source: https://mavsdk.mavlink.io/main/en/cpp/guide/toolchain.html Build commands for when MAVSDK is installed locally (e.g., extracted from mavsdk-windows-x64-release.zip or built from source). Use CMAKE_PREFIX_PATH to point to the local installation directory. ```bash cmake -B build -DCMAKE_PREFIX_PATH=../mavsdk -S . cmake --build build -j8 ``` -------------------------------- ### Create Action plugin: connect to system and instantiate Action Source: https://mavsdk.mavlink.io/main/en/cpp/guide/taking_off_landing.html Create a connection to a system and then create an Action instance. The first block sets up a UDP connection and waits for the system to be discovered. The second block creates the Action object using the discovered system. ```cpp #include Mavsdk mavsdk{Mavsdk::Configuration{Mavsdk::ComponentType::GroundStation}}; ConnectionResult conn_result = mavsdk.add_udp_connection(); // Wait for the system to connect via heartbeat while (mavsdk.system().size() == 0) { sleep_for(seconds(1)); } // System got discovered. System system = mavsdk.systems()[0]; ``` ```cpp #include auto action = Action{system}; ``` -------------------------------- ### Creating the plugin Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_component_metadata_server.html Shows how to create a ComponentMetadataServer instance with a ServerComponent. ```cpp auto component_metadata_server = ComponentMetadataServer(server_component); ``` -------------------------------- ### VTOL Transition Example Output Source: https://mavsdk.mavlink.io/main/en/cpp/examples/transition_vtol_fixed_wing.html Example terminal output from a debug build of the SDK when running the VTOL transition example. A release build omits the "Debug" messages. ```text Waiting to discover system... [10:24:42|Info ] New system on: 127.0.0.1:14557 (udp_connection.cpp:210) [10:24:42|Debug] MAVLink: info: [logger] file: rootfs/fs/microsd/log/2017-11-21/0 (mavlink_system.cpp:286) [10:24:43|Debug] Discovered 4294967298 (mavlink_system.cpp:483) Discovered system with UUID: 4294967298 Arming... Taking off... [10:24:44|Debug] MAVLink: info: ARMED by arm/disarm component command (mavlink_system.cpp:286) [10:24:44|Debug] MAVLink: info: Using minimum takeoff altitude: 10.00 m (mavlink_system.cpp:286) [10:24:44|Debug] MAVLink: info: Takeoff detected (mavlink_system.cpp:286) [10:24:44|Debug] MAVLink: critical: Using minimum takeoff altitude: 10.00 m (mavlink_system.cpp:286) Altitude: 0.079 m Altitude: 0.507 m ... Altitude: 10.254 m Transition to fixedwing... Altitude: 10.263 m ... Altitude: 20.72 m Altitude: 24.616 m Altitude: 22.262 m Transition back to multicopter... Altitude: 17.083 m ... Return to launch... Altitude: 11.884 m [10:25:09|Debug] MAVLink: info: RTL: climb to 518 m (29 m above home) (mavlink_system.cpp:286) Altitude: 13.61 m ... Altitude: 27.489 m Altitude: 28.892 m [10:25:18|Debug] MAVLink: info: RTL: return at 517 m (29 m above home) (mavlink_system.cpp:286) Altitude: 29.326 m Altitude: 29.33 m ... Altitude: 29.323 m Altitude: 29.357 m Landing... [10:25:29|Debug] MAVLink: info: Landing at current position (mavlink_system.cpp:286) Altitude: 29.199 m Altitude: 28.722 m Altitude: 28.189 m Altitude: 27.62 m Finished... ``` -------------------------------- ### Before: MAVSDK-Python arming and takeoff Source: https://mavsdk.mavlink.io/main/en/python/migration.html MAVSDK-Python example for arming and taking off before migrating. Uses System(), connect(), and plugin attributes like drone.action. ```python import asyncio from mavsdk import System async def run(): drone = System() await drone.connect(system_address="udpin://0.0.0.0:14540") async for state in drone.core.connection_state(): if state.is_connected: break await drone.action.arm() await drone.action.takeoff() await asyncio.sleep(5) await drone.action.land() asyncio.run(run()) ``` -------------------------------- ### init() Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_system.html Initializes the system. This method is not intended for direct application use. ```APIDOC ## init() ### Description Initialize the system. This is not (and should not be) directly called by application code. ### Method void mavsdk::System::init(uint32_t system_id, uint8_t component_id) const ### Parameters - **system_id** (uint32_t) - System id. - **component_id** (uint8_t) - Component id. ``` -------------------------------- ### Create Winch plugin with System reference Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_winch.html Example of creating a Winch plugin instance using the constructor that takes a System reference. ```cpp auto winch = Winch(system); ``` -------------------------------- ### Typical LogFiles plugin creation Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_log_files.html Shows the typical way to create a LogFiles plugin instance for a specific system. ```cpp auto log_files = LogFiles(system); ``` -------------------------------- ### Create a connection to a system Source: https://mavsdk.mavlink.io/main/en/cpp/guide/follow_me.html Basic code to create a MAVSDK connection and wait for a system to be discovered. This is the first step in creating a FollowMe plugin. ```cpp #include Mavsdk mavsdk{Mavsdk::Configuration{Mavsdk::ComponentType::GroundStation}}; ConnectionResult conn_result = mavsdk.add_udp_connection(); // Wait for the system to connect via heartbeat while (mavsdk.system().size() == 0) { sleep_for(seconds(1)); } // System got discovered. System system = mavsdk.systems()[0]; ``` -------------------------------- ### Install build dependencies on Ubuntu Source: https://mavsdk.mavlink.io/main/en/cpp/guide/build_linux.html Installs the required build tools for Ubuntu: build-essential, cmake, git, and Python 3. ```bash sudo apt-get update sudo apt-get install build-essential cmake git python3 python3-pip ``` -------------------------------- ### Create a connection to a system Source: https://mavsdk.mavlink.io/main/en/cpp/guide/missions.html Sets up a MAVSDK instance and waits for a system to connect via heartbeat. This is the first step before creating a Mission plugin. ```cpp #include Mavsdk mavsdk{Mavsdk::Configuration{Mavsdk::ComponentType::GroundStation}}; ConnectionResult conn_result = mavsdk.add_udp_connection(); // Wait for the system to connect via heartbeat while (mavsdk.systems().size() == 0) { sleep_for(seconds(1)); } // System got discovered. System system = mavsdk.systems()[0]; ``` -------------------------------- ### Arm and take off with Action plugin Source: https://mavsdk.mavlink.io/main/en/python/quickstart.html Create an Action plugin for the drone and arm and take off. The drone should take off if everything is working. ```python action = ActionAsync(drone) await action.arm() await action.takeoff() ``` -------------------------------- ### subscribe_start_video() Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_camera_server.html Subscribes to start video requests. Each request received should be responded to using RespondStartVideo. ```cpp StartVideoHandle mavsdk::CameraServer::subscribe_start_video(const StartVideoCallback &callback) ``` -------------------------------- ### Create Shell plugin instance Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_shell.html Example of creating a Shell plugin instance for a specific system. This is the typical usage pattern for the constructor. ```cpp auto shell = Shell(system); ``` -------------------------------- ### Install build dependencies on Fedora Source: https://mavsdk.mavlink.io/main/en/cpp/guide/build_linux.html Installs the required build tools for Fedora: Development Tools, Development Libraries, cmake, and git. ```bash sudo dnf update sudo dnf groupinstall "Development Tools" "Development Libraries" sudo dnf install cmake git ``` -------------------------------- ### Param constructor with System reference Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_param.html Creates a Param plugin instance for a specific System, typically used as shown in the example. ```cpp mavsdk::Param::Param(System &system) ``` -------------------------------- ### ActionError example for rejected command Source: https://mavsdk.mavlink.io/main/en/python/quickstart.html Example of an exception raised when a command is rejected, such as arming before GPS fix. The vehicle refused the command. ```python mavsdk.plugins.action.action.ActionError: COMMAND_DENIED; origin: arm(); params: () ``` -------------------------------- ### Constructor with System reference Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_mavlink_direct.html Creates the plugin for a specific system using a System reference. ```cpp mavsdk::MavlinkDirect::MavlinkDirect(System &system) ``` -------------------------------- ### Run offboard velocity example Source: https://mavsdk.mavlink.io/main/en/cpp/examples/offboard_velocity.html Command to run the offboard velocity example, connecting to a vehicle via UDP on port 14540. ```bash $ ./offboard udpin://0.0.0.0:14540 ``` -------------------------------- ### init() pure virtual method Source: https://mavsdk.mavlink.io/main/en/cpp/contributing/plugins.html Called when a plugin is instantiated, which happens when a System is constructed (even if it is an empty dummy system). Use it for initialization steps that depend on the System, such as setting up callbacks with _parent (DeviceImpl). ```cpp virtual void init() = 0 ``` -------------------------------- ### Configure cmake with local MAVSDK path Source: https://mavsdk.mavlink.io/main/en/cpp/examples/index.html Configures the build when MAVSDK is installed locally (e.g., on Windows). Replace the placeholder with the actual installation path. ```sh cmake -B build -DCMAKE_PREFIX_PATH=wherever_mavsdk_is_locally_installed ``` -------------------------------- ### Typical ServerUtility creation Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_server_utility.html Typical way to create a ServerUtility plugin instance. Used in the constructor documentation for both constructor overloads. ```cpp auto server_utility = ServerUtility(system); ``` -------------------------------- ### Start mavsdk_server with heartbeat watchdog timeout Source: https://mavsdk.mavlink.io/main/en/cpp/guide/heartbeat_watchdog.html Command-line option to enable the watchdog when starting mavsdk_server for gRPC-based wrappers. The timeout value is in seconds; 0 disables it (default). ```bash mavsdk_server --heartbeat-watchdog-timeout 2 udpin://0.0.0.0:14540 ``` -------------------------------- ### Mavsdk(Configuration configuration) Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_mavsdk.html Constructor with configuration. Initializes a MAVSDK instance with the provided configuration. ```APIDOC ## Mavsdk(Configuration configuration) ### Description Constructor with configuration. Initializes a MAVSDK instance with the provided configuration. ### Method Constructor ### Signature ```cpp mavsdk::Mavsdk::Mavsdk(Configuration configuration) ``` ### Parameters - **configuration** (Configuration) - Required - Configuration to use in MAVSDK instance. ### Return Value None ``` -------------------------------- ### Fly Mission Example Terminal Output Source: https://mavsdk.mavlink.io/main/en/cpp/examples/fly_mission.html Expected output from running the example, showing discovery, mission upload, arming, mission execution, pause/resume, RTL, and disarming. ```text Waiting to discover system... [09:36:08|Info ] New device on: 127.0.0.1:14557 (udp_connection.cpp:208) [09:36:08|Debug] New: System ID: 1 Comp ID: 1 (dronecode_sdk_impl.cpp:292) [09:36:08|Debug] Component Autopilot added. (system_impl.cpp:339) [09:36:08|Debug] MAVLink: info: [logger] file: rootfs/fs/microsd/log/2018-07-09/1 (system_impl.cpp:277) [09:36:09|Debug] Found 1 component(s). (system_impl.cpp:466) [09:36:09|Debug] Discovered 4294967298 (system_impl.cpp:468) Discovered system with UUID: 4294967298 Waiting for system to be ready System ready Creating and uploading mission Uploading mission... [09:36:10|Debug] Send mission item 0 (mission_impl.cpp:898) [09:36:10|Debug] Send mission item 1 (mission_impl.cpp:898) ... [09:36:10|Debug] Send mission item 19 (mission_impl.cpp:898) [09:36:10|Debug] Send mission item 20 (mission_impl.cpp:898) [09:36:10|Debug] Send mission item 21 (mission_impl.cpp:898) [09:36:10|Debug] Send mission item 22 (mission_impl.cpp:898) [09:36:10|Info ] Mission accepted (mission_impl.cpp:163) Mission uploaded. Arming... [09:36:10|Debug] MAVLink: info: ARMED by arm/disarm component command (system_impl.cpp:277) Armed. Starting mission. Started mission. Mission status update: 0 / 6 [09:36:10|Debug] MAVLink: info: Executing Mission (system_impl.cpp:277) [09:36:10|Debug] MAVLink: info: Takeoff to 10.0 meters above home. (system_impl.cpp:277) [09:36:10|Debug] MAVLink: info: Takeoff detected (system_impl.cpp:277) Mission status update: 0 / 6 Mission status update: 0 / 6 Mission status update: 1 / 6 ... Mission status update: 1 / 6 Mission status update: 2 / 6 Mission status update: 2 / 6 Pausing mission... Mission paused. [09:36:28|Debug] MAVLink: critical: MANUAL CONTROL LOST (at t=41381ms) (system_impl.cpp:277) [09:36:28|Debug] MAVLink: info: MANUAL CONTROL REGAINED after 541ms (system_impl.cpp:277) Resuming mission... Resumed mission. Mission status update: 2 / 6 ... Mission status update: 2 / 6 Mission status update: 3 / 6 ... Mission status update: 3 / 6 Mission status update: Mission status update: 44 / 6 / 6 Mission status update: 4 / 6 ... Mission status update: 4 / 6 Mission status update: 5 / 6 ... Mission status update: 5 / 6 [09:37:00|Debug] MAVLink: info: Mission finished, loitering. (system_impl.cpp:277) Mission status update: 6 / 6 Commanding RTL... Commanded RTL. [09:37:01|Debug] MAVLink: info: RTL HOME activated (system_impl.cpp:277) [09:37:01|Debug] MAVLink: info: RTL: climb to 518 m (31 m above home) (system_impl.cpp:277) [09:37:09|Debug] MAVLink: info: RTL: return at 518 m (31 m above home) (system_impl.cpp:277) [09:37:16|Debug] MAVLink: info: RTL: descend to 493 m (5 m above home) (system_impl.cpp:277) [09:37:41|Debug] MAVLink: info: RTL: loiter 5.0s (system_impl.cpp:277) [09:37:46|Debug] MAVLink: info: RTL: land at home (system_impl.cpp:277) [09:37:56|Debug] MAVLink: info: Landing detected (system_impl.cpp:277) [09:37:59|Debug] MAVLink: info: DISARMED by auto disarm on land (system_impl.cpp:277) Mission status update: 6 / 6 Disarmed, exiting. ``` -------------------------------- ### Set and Get Heartbeat Timeout Source: https://mavsdk.mavlink.io/main/en/cpp/guide/general_usage.html Set the heartbeat timeout on the Mavsdk object. The default is 3 seconds. Also demonstrates getting the current heartbeat timeout value. ```cpp mavsdk.set_heartbeat_timeout_s(5.0); // allow up to 5 seconds between heartbeats double current = mavsdk.get_heartbeat_timeout_s(); ``` -------------------------------- ### set_config() method Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_follow_me.html Apply configuration by sending it to the system. This function is blocking. ```cpp Result mavsdk::FollowMe::set_config(Config config) const ``` -------------------------------- ### Example terminal output for offboard velocity Source: https://mavsdk.mavlink.io/main/en/cpp/examples/offboard_velocity.html Example terminal output from a debug build of the SDK, showing the sequence of NED and body frame velocity commands and the final landing. ```text Wait for system to connect via heartbeat [12:53:03|Info ] New device on: 127.0.0.1:14557 (udp_connection.cpp:208) [12:53:03|Debug] New: System ID: 1 Comp ID: 1 (dronecode_sdk_impl.cpp:286) [12:53:03|Debug] Component Autopilot added. (mavlink_system.cpp:349) [12:53:03|Debug] MAVLink: info: [logger] file: rootfs/fs/microsd/log/2018-05-23/0 (mavlink_system.cpp:286) [12:53:04|Debug] Found 1 component(s). (mavlink_system.cpp:481) [12:53:04|Debug] Discovered 4294967298 (mavlink_system.cpp:483) Waiting for system to be ready System is ready Armed [12:53:05|Debug] MAVLink: info: ARMED by arm/disarm component command (mavlink_system.cpp:286) In Air... [12:53:05|Debug] MAVLink: info: Using minimum takeoff altitude: 2.50 m (mavlink_system.cpp:286) [12:53:05|Debug] MAVLink: info: Takeoff detected (mavlink_system.cpp:286) [12:53:05|Debug] MAVLink: critical: Using minimum takeoff altitude: 2.50 m (mavlink_system.cpp:286) [NED] Offboard started [NED] Turn to face East [NED] Go North and back South [NED] Turn to face West [NED] Go up 2 m/s, turn to face South [NED] Go down 1 m/s, turn to face North [NED] Offboard stopped [BODY] Offboard started [BODY] Turn clock-wise and climb [BODY] Turn back anti-clockwise [BODY] Wait for a bit [BODY] Fly a circle [BODY] Wait for a bit [BODY] Fly a circle sideways [BODY] Wait for a bit [BODY] Offboard stopped [12:54:29|Debug] MAVLink: info: Landing at current position (mavlink_system.cpp:286) Landed ``` -------------------------------- ### Configure build with BUILD_MAVSDK_SERVER=ON Source: https://mavsdk.mavlink.io/main/en/cpp/contributing/plugins.html Configures the build with the MAVSDK server enabled, preparing the tools required for generating plugin files. ```bash cmake -DBUILD_MAVSDK_SERVER=ON -B build/default -S . ``` -------------------------------- ### get_all_params Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_param.html Get all parameters. ```APIDOC ## get_all_params ### Description Get all parameters. ### Method SDK Method ### Signature `Param::AllParams get_all_params() const` ### Return Value - **Param::AllParams** - All parameters. ``` -------------------------------- ### start_video() Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_camera.html Start a video recording. Blocking; see 'start_video_async' for the non-blocking counterpart. Returns Result of request. ```cpp Result mavsdk::Camera::start_video(int32_t component_id) const ``` -------------------------------- ### start_mission_async Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_mission_raw.html Start the mission asynchronously. ```APIDOC ## start_mission_async ### Description Start the mission asynchronously. ### Method void ### Signature ```cpp void start_mission_async(const ResultCallback callback) ``` ### Parameters - **callback** (const ResultCallback) - Required - Callback to receive the result. ``` -------------------------------- ### Create Mocap plugin instance Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_mocap.html Example of creating a Mocap plugin instance. The system parameter is the specific system associated with this plugin. ```cpp auto mocap = Mocap(system); ``` -------------------------------- ### vehicle_type() Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_system.html Get vehicle type. ```APIDOC ## vehicle_type() ### Description Get vehicle type. ### Method Vehicle mavsdk::System::vehicle_type() const ### Returns - **Vehicle** - vehicle type discovered. ``` -------------------------------- ### autopilot_type() Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_system.html Get autopilot type. ```APIDOC ## autopilot_type() ### Description Get autopilot type. ### Method Autopilot mavsdk::System::autopilot_type() const ### Returns - **Autopilot** - autopilot type discovered. ``` -------------------------------- ### vehicle_type Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_system.html Gets the vehicle type. ```APIDOC ## vehicle_type ### Description Gets the vehicle type. ### Method Vehicle vehicle_type() const ### Parameters None ### Returns Vehicle - The vehicle type. ``` -------------------------------- ### typedef StartVideoHandle Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_camera_server.html Handle type for subscribe_start_video. ```APIDOC ## typedef StartVideoHandle ### Description Handle type for subscribe_start_video. ### Definition ```cpp using mavsdk::CameraServer::StartVideoHandle = Handle; ``` ``` -------------------------------- ### autopilot_type Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_system.html Gets the autopilot type. ```APIDOC ## autopilot_type ### Description Gets the autopilot type. ### Method Autopilot autopilot_type() const ### Parameters None ### Returns Autopilot - The autopilot type. ``` -------------------------------- ### get_param_custom Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_param.html Get a custom parameter. ```APIDOC ## get_param_custom ### Description Get a custom parameter. ### Method SDK Method ### Signature `std::pair get_param_custom(std::string name) const` ### Parameters - **name** (std::string) - Required - The name of the parameter. ### Return Value - **Result** - The result of the request. - **std::string** - The value of the parameter. ``` -------------------------------- ### Info constructor with System reference Source: https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_info.html Creates an Info plugin instance for a specific System, passed by reference. Typically used as shown in the example. ```cpp mavsdk::Info::Info(System &system) ```