Skip to content

Commit

Permalink
Merge pull request #545 from akkawimo/winch_plugin
Browse files Browse the repository at this point in the history
Winch and Gripper plugins
  • Loading branch information
julianoes authored Mar 7, 2024
2 parents a0562ac + 6a9dc07 commit 0d137ca
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
32 changes: 32 additions & 0 deletions examples/gripper.py
Original file line number Diff line number Diff line change
@@ -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())
27 changes: 27 additions & 0 deletions examples/winch.py
Original file line number Diff line number Diff line change
@@ -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())
16 changes: 16 additions & 0 deletions mavsdk/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +37,7 @@
from . import tracking_server
from . import transponder
from . import tune
from . import winch

from . import bin

Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 0d137ca

Please sign in to comment.