From f774bb0f5dd700bfafac97dc29efb8c5d961d496 Mon Sep 17 00:00:00 2001 From: Alessandro Simovic Date: Thu, 23 Feb 2023 11:17:27 +0100 Subject: [PATCH 1/5] Readme instructions for new plugins --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 372622fa..727013be 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,10 @@ Run the following helper script. It will generate the Python wrappers for each p ./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](./MAVSDK_SERVER_VERSION) contains exactly the tag name of the `mavsdk_server` release corresponding to the version of MAVSDK-Python. When the [proto](./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). From 8e6e693da42a57a677bb1f563569150ace45965e Mon Sep 17 00:00:00 2001 From: Alessandro Simovic Date: Thu, 23 Feb 2023 11:14:24 +0100 Subject: [PATCH 2/5] add winch and gripper plugins --- mavsdk/system.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mavsdk/system.py b/mavsdk/system.py index fb0fb101..e632bbde 100644 --- a/mavsdk/system.py +++ b/mavsdk/system.py @@ -18,6 +18,7 @@ from . import ftp from . import geofence from . import gimbal +from . import gripper from . import info from . import log_files from . import manual_control @@ -36,6 +37,7 @@ from . import tracking_server from . import transponder from . import tune +from . import winch from . import bin @@ -141,6 +143,7 @@ async def _init_plugins(self, host, port): self._plugins["ftp"] = ftp.Ftp(plugin_manager) self._plugins["geofence"] = geofence.Geofence(plugin_manager) self._plugins["gimbal"] = gimbal.Gimbal(plugin_manager) + self._plugins["gripper"] = gripper.Gripper(plugin_manager) self._plugins["info"] = info.Info(plugin_manager) self._plugins["log_files"] = log_files.LogFiles(plugin_manager) self._plugins["manual_control"] = manual_control.ManualControl(plugin_manager) @@ -159,6 +162,7 @@ async def _init_plugins(self, host, port): self._plugins["tracking_server"] = tracking_server.TrackingServer(plugin_manager) self._plugins["transponder"] = transponder.Transponder(plugin_manager) self._plugins["tune"] = tune.Tune(plugin_manager) + self._plugins["winch"] = winch.Winch(plugin_manager) @staticmethod def error_uninitialized(plugin_name: str) -> str: @@ -243,6 +247,12 @@ def gimbal(self) -> gimbal.Gimbal: raise RuntimeError(self.error_uninitialized("Gimbal")) return self._plugins["gimbal"] + @property + def gripper(self) -> gripper.Gripper: + if "gripper" not in self._plugins: + raise RuntimeError(self.error_uninitialized("Gripper")) + return self._plugins["gripper"] + @property def info(self) -> info.Info: if "info" not in self._plugins: @@ -351,6 +361,12 @@ def tune(self) -> tune.Tune: raise RuntimeError(self.error_uninitialized("Tune")) return self._plugins["tune"] + @property + def winch(self) -> winch.Winch: + if "tune" not in self._plugins: + raise RuntimeError(self.error_uninitialized("Winch")) + return self._plugins["winch"] + @staticmethod def _start_mavsdk_server(system_address, port, sysid, compid): """ From 5bfe7d452b227c21e42fbb4c167685b7b373bd82 Mon Sep 17 00:00:00 2001 From: Alessandro Simovic Date: Thu, 23 Feb 2023 11:16:42 +0100 Subject: [PATCH 3/5] winch and gripper examples --- examples/gripper.py | 32 ++++++++++++++++++++++++++++++++ examples/winch.py | 27 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 examples/gripper.py create mode 100644 examples/winch.py diff --git a/examples/gripper.py b/examples/gripper.py new file mode 100644 index 00000000..0121c8cc --- /dev/null +++ b/examples/gripper.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import asyncio +from mavsdk import System + +async def run(): + drone = System() + await drone.connect(system_address="udp://:14540") + + print("Waiting for drone to connect...") + async for state in drone.core.connection_state(): + if state.is_connected: + print(f"-- Connected to drone!") + break + + print(f"-- Gripper Grab") + await drone.gripper.grab(instance=1) + + await asyncio.sleep(1) + + print(f"-- Gripper Release") + await drone.gripper.release(instance=1) + + while True: + print("Staying connected, press Ctrl-C to exit") + await asyncio.sleep(1) + + +if __name__ == "__main__": + # Run the asyncio loop + asyncio.run(run()) + \ No newline at end of file diff --git a/examples/winch.py b/examples/winch.py new file mode 100644 index 00000000..edad70b5 --- /dev/null +++ b/examples/winch.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import asyncio +from mavsdk import System + +async def run(): + drone = System() + await drone.connect(system_address="udp://:14540") + + print("Waiting for drone to connect...") + async for state in drone.core.connection_state(): + if state.is_connected: + print(f"-- Connected to drone!") + break + + print(f"-- Winch action: load payload") + await drone.winch.load_payload(instance=1) + + while True: + print("Staying connected, press Ctrl-C to exit") + await asyncio.sleep(1) + + +if __name__ == "__main__": + # Run the asyncio loop + asyncio.run(run()) + \ No newline at end of file From 1a3d6ae6029ace6c90a9de4ddf566ba10fee979e Mon Sep 17 00:00:00 2001 From: alessandro <3762382+potaito@users.noreply.github.com> Date: Thu, 23 Feb 2023 11:19:58 +0100 Subject: [PATCH 4/5] Update gripper.py --- examples/gripper.py | 1 - examples/winch.py | 1 - 2 files changed, 2 deletions(-) diff --git a/examples/gripper.py b/examples/gripper.py index 0121c8cc..ce19e671 100644 --- a/examples/gripper.py +++ b/examples/gripper.py @@ -29,4 +29,3 @@ async def run(): if __name__ == "__main__": # Run the asyncio loop asyncio.run(run()) - \ No newline at end of file diff --git a/examples/winch.py b/examples/winch.py index edad70b5..fb16b088 100644 --- a/examples/winch.py +++ b/examples/winch.py @@ -24,4 +24,3 @@ async def run(): if __name__ == "__main__": # Run the asyncio loop asyncio.run(run()) - \ No newline at end of file From 6a9dc0769ed47bf8922df1c6141c5752a8805fc7 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Thu, 7 Mar 2024 16:33:09 +1300 Subject: [PATCH 5/5] examples: fix style Signed-off-by: Julian Oes --- examples/gripper.py | 1 + examples/winch.py | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/gripper.py b/examples/gripper.py index ce19e671..a6ecb172 100644 --- a/examples/gripper.py +++ b/examples/gripper.py @@ -3,6 +3,7 @@ import asyncio from mavsdk import System + async def run(): drone = System() await drone.connect(system_address="udp://:14540") diff --git a/examples/winch.py b/examples/winch.py index fb16b088..3b15b54e 100644 --- a/examples/winch.py +++ b/examples/winch.py @@ -3,6 +3,7 @@ import asyncio from mavsdk import System + async def run(): drone = System() await drone.connect(system_address="udp://:14540")