Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Winch and Gripper plugins #545

Merged
merged 5 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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