1 Star 0 Fork 0

wangqx/MAVSDK-Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

MAVSDK-Python

GitHub Actions Status

This is the Python wrapper for MAVSDK.

The Python wrapper is based on a gRPC client communicating with the gRPC server written in C++. To use the Python wrapper the gRPC server called "backend" needs to be running on the same system. The wrapper is essentially auto-generated from the message definitions (proto files).

Important Notes

  • Python 3.7+ is required (because the wrapper is based on asyncio).
  • You may need to run pip3 instead of pip and python3 instead of python, depending of your system defaults.
  • Auterion has a Getting started with MAVSDK-Python guide if you're a beginner and not sure where to start.

API Reference docs

-> API Reference documentation.

Install using pip from PyPi

To install mavsdk-python, simply run:

pip3 install mavsdk

The package contains mavsdk_server already (previously called "backend"), which is started automatically when connecting (e.g. await drone.connect()). Have a look at the examples to see it used in practice. It will be something like:

from mavsdk import System

...

drone = System()
await drone.connect(system_address="udp://:14540")

Note: System() takes two named parameters: mavsdk_server_address and port. When left empty, they default to None and 50051, respectively, and mavsdk_server -p 50051 is run by await drone.connect(). If mavsdk_server_address is set (e.g. to "localhost"), then await drone.connect() will not start the embedded mavsdk_server and will try to connect to a server running at this address. This is useful for platforms where mavsdk_server does not come embedded, for debugging purposes, and for running mavsdk_server in a place different than where the MAVSDK-Python script is run.

Run the examples

Once the package has been installed, the examples can be run:

examples/takeoff_and_land.py

The examples assume that the embedded mavsdk_server binary can be run. In some cases (e.g. on Raspberry Pi), it may be necessary to run mavsdk_server manually, and therefore to set mavsdk_server_address='localhost' as described above.

Contribute

Note: this is more involved and targeted at contributors.

Most of the code is auto-generated from the proto definitions, using our templates. The generated files can be found in the generated folder. As a result, contributions are generally made in the templates or on the build system. Regularly, there is a need to update MAVSDK-Python to include the latest features defined in the proto definitions. This is described below.

Clone the repo

Clone this repo and recursively update submodules:

git clone https://github.com/mavlink/MAVSDK-Python --recursive
cd MAVSDK-Python

Install prerequisites

First install the protoc plugin (protoc-gen-mavsdk):

cd proto/pb_plugins
pip3 install -r requirements.txt

You can check that the plugin was installed with $ which protoc-gen-mavsdk, as it should now be in the PATH.

Then go back to the root of the repo and install the dependencies of the SDK:

cd ../..
pip3 install -r requirements.txt -r requirements-dev.txt

Generate the code

Run the following helper script. It will generate the Python wrappers for each plugin.

./other/tools/run_protoc.sh

Adding support for new plugins

In case you updated the ./proto submodule to include a new plugin, you will also have to manually edit the file mavsdk/system.py to register the plugin.

Update mavsdk_server version

MAVSDK_SERVER_VERSION contains exactly the tag name of the mavsdk_server release corresponding to the version of MAVSDK-Python. When the proto submodule is updated here, chances are that mavsdk_server should be updated, too. Just edit this file, and the corresponding binary will be downloaded by the setup.py script (see below).

Build and install the package locally

After generating the wrapper and only in ARM architectures with linux, defines a variable MAVSDK_SERVER_ARCH:

export MAVSDK_SERVER_ARCH=<ARM embedded architecture>

Supported architectures: armv6l, armv7l and aarch64. For example for Raspberry Pi it is armv7l, or aarch64 (if a 64 bit distribution is used).

Then you can install a development version of the package, which links the package to the generated code in this local directory. To do so, use:

python3 setup.py build
pip3 install -e .

Note: MAVDSK-Python runs mavsdk/bin/mavsdk_server when await drone.connect() is called. This binary comes from MAVSDK and is downloaded during the setup.py step above.

Generate the API documentation

Make sure the version tag is set correctly before generating new documentation.

pip3 install -r requirements-docs.txt
make -C mavsdk html

Release steps

  1. Check the proto submodule is up-to-date and the generated code has been updated.
  2. Check all required pull requests are merged to main
  3. Check MAVSDK_SERVER_VERSION is set to the correct version of mavsdk_server.
  4. Create git tag on laster main, e.g.:
    git switch main
    git pull
    git tag X.Y.Z
    git push --tags
    
  5. Go to releases page and create new release. The CI will now:
    • Create and push a wheel for Windows, Linux and macOS to PyPi.
    • Generate the latest docs and push them to s3.
Copyright (c) 2020, MAVSDK Development Team All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

暂无描述 展开 收起
README
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangqiongxia/MAVSDK-Python.git
git@gitee.com:wangqiongxia/MAVSDK-Python.git
wangqiongxia
MAVSDK-Python
MAVSDK-Python
main

搜索帮助