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). diff --git a/examples/gripper.py b/examples/gripper.py new file mode 100644 index 00000000..a6ecb172 --- /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()) diff --git a/examples/winch.py b/examples/winch.py new file mode 100644 index 00000000..3b15b54e --- /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()) 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): """