Please help me understand mavsdk_server

I am new to MAVSDK and trying to understand some basics.

  1. When I run any of the C++ examples (e.g. takeoff_and_land) – is it starting up an instance of mavsdk_server? Is this instance a separate process? Is the example code talking to this instance over gRPC? (Just trying to create a mental model of the system architecture.)
  2. Can the mavsdk_server be run standalone – preferably as a docker container running on a ARM-based Mac? (I tried to compile and run the server using instructions in the git repo, but was getting compile errors – must be doing something wrong!)
  3. Once I get mavsdk_server running standalone, can I make the examples work against this server? Basically I am trying to figure out if I can connect to the mavsdk_server from a custom client using gRPC.

1 Architecture

Check this: Autogeneration | MAVSDK Guide

MAVSDK (C++) is first and foremost a library, like any other C++ library. When you run any C++ example (e.g. takeoff_and_land) with it, it’ll just link to libmavsdk.so.3 (or similar).

mavsdk_server is a C++ application (like any of the examples) using libmavsdk (and libmavsdk_server) exposing a gRPC API. This gRPC API is then be used in language wrappers such as Python.

2 Building

You can absolutely build it run standalone. It just depends how you build it, whether it needs the libraries at runtime, or whether they are included (when statically built).

I think you got a bit misguided by the readme there. To see how it is built, have a look here:

Or if you just want to build within docker, you would just use the Linux instructions, I think:

The main option to add to the cmake configure line to build with the mavsdk_server is -DBUILD_MAVSDK_SERVER=ON

However, I usually recommend to just grab the latest pre-compiled release unless you have changes in a fork. You can get the build artifacts for the releases here: https://github.com/mavlink/MAVSDK/releases.

There are various options. For docker x64, you can just grab the musl one, which doesn’t even require libc, everything is built in. (It’s what we ship with pip.)

3 gRPC examples

No, the examples are just using the C++ library. My question would be: why aren’t you just using the C++ API? Do you really need gRPC in-between, and why?

Also note that the C++ API is richer and has more features than the gRPC API:

  • The C++ API supports server side (vehicle side) plugins (all plugins called something_server, e.g. param_server)
  • The C++ API supports more than one system (vehicle) per MAVSDK instance. The mavsdk_server is limited to one system (vehicle).

If you are looking for examples, check how the language wrappers do it, e.g. in Python:

Hi @JulianOes, thank you for a detailed answer. I think I have a better understanding now. I drew myself the following diagram to confirm my understanding. Does this look right to you?

  1. A C++ app like takeoff_and_land.cpp simply uses libmavsdk to connect to the drone over MAVLink. There is no gRPC involved.
  2. mavsdk_server is just another C++ app that uses libmavsdk to connect to the drone over MAVLink. The only difference is that it also exposes a gRPC API for other apps to control a drone through it.
  3. A Python app like takeoff_and_land.py uses mavsdk-python to connect to the mavsdk_server using its gRPC API. This allows Python apps to connect to a drone without implementing a full-fledged MAVLink implementation. My only question: how does the Python app create the mavsdk_server? In the Python QuickStart, there are no instructions to start mavsdk_server.
  4. This is my use case. I am trying to create an app in Go. My understanding is that mavsdk-go is not fully implemented. Hence I am trying to connect to the mavsdk_server using gRPC directly. Does that make sense?

Yes, it’s done in the background, see: MAVSDK-Python/mavsdk/system.py at fc56d9327bfaff06a4a672190c69f88a635048d4 · mavlink/MAVSDK-Python · GitHub

But you can run it explicitly yourself, see: MAVSDK-Python API reference — MAVSDK-Python 3.10.2 documentation

It does make sense but you’re probably making it harder that way. In the open source spriti, I would instead suggest to build on top of existing Mavsdk-Go and get it to where you need it to be.

Looking at GitHub - mavlink/MAVSDK-Go, it looks like it could be reasonably close to what you need (depending on what you need I suppose).

I assume the steps would be to:

  1. Update to latest mavsdk_server v3.x if it isn’t already.
  2. Check the existing functionality.
  3. Extend whatever is missing in the [templates](MAVSDK-Go/templates at main · mavlink/MAVSDK-Go · GitHub).

What sort of functionality do you need?

Hi @JulianOes, thanks for confirming my understanding and answering my questions.

I agree that the right way to connect to Go applications would be to fill in the gaps in MAVSDK-Go. However, at the moment I am simply trying to show the telemetry messages received from the drone. I am able to do that quite easily by consuming raw mavlink messages. If this project gets any more serious, I would be happy to contribute to MAVSDK-Go.

You’re welcome. No worries, whatever works for you.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.