Skip to content

Commit 0d137ca

Browse files
authored
Merge pull request #545 from akkawimo/winch_plugin
Winch and Gripper plugins
2 parents a0562ac + 6a9dc07 commit 0d137ca

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Run the following helper script. It will generate the Python wrappers for each p
8989
./other/tools/run_protoc.sh
9090
```
9191

92+
### Adding support for new plugins
93+
94+
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.
95+
9296
### Update `mavsdk_server` version
9397

9498
[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).

examples/gripper.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
3+
import asyncio
4+
from mavsdk import System
5+
6+
7+
async def run():
8+
drone = System()
9+
await drone.connect(system_address="udp://:14540")
10+
11+
print("Waiting for drone to connect...")
12+
async for state in drone.core.connection_state():
13+
if state.is_connected:
14+
print(f"-- Connected to drone!")
15+
break
16+
17+
print(f"-- Gripper Grab")
18+
await drone.gripper.grab(instance=1)
19+
20+
await asyncio.sleep(1)
21+
22+
print(f"-- Gripper Release")
23+
await drone.gripper.release(instance=1)
24+
25+
while True:
26+
print("Staying connected, press Ctrl-C to exit")
27+
await asyncio.sleep(1)
28+
29+
30+
if __name__ == "__main__":
31+
# Run the asyncio loop
32+
asyncio.run(run())

examples/winch.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
3+
import asyncio
4+
from mavsdk import System
5+
6+
7+
async def run():
8+
drone = System()
9+
await drone.connect(system_address="udp://:14540")
10+
11+
print("Waiting for drone to connect...")
12+
async for state in drone.core.connection_state():
13+
if state.is_connected:
14+
print(f"-- Connected to drone!")
15+
break
16+
17+
print(f"-- Winch action: load payload")
18+
await drone.winch.load_payload(instance=1)
19+
20+
while True:
21+
print("Staying connected, press Ctrl-C to exit")
22+
await asyncio.sleep(1)
23+
24+
25+
if __name__ == "__main__":
26+
# Run the asyncio loop
27+
asyncio.run(run())

mavsdk/system.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from . import ftp
1919
from . import geofence
2020
from . import gimbal
21+
from . import gripper
2122
from . import info
2223
from . import log_files
2324
from . import manual_control
@@ -36,6 +37,7 @@
3637
from . import tracking_server
3738
from . import transponder
3839
from . import tune
40+
from . import winch
3941

4042
from . import bin
4143

@@ -141,6 +143,7 @@ async def _init_plugins(self, host, port):
141143
self._plugins["ftp"] = ftp.Ftp(plugin_manager)
142144
self._plugins["geofence"] = geofence.Geofence(plugin_manager)
143145
self._plugins["gimbal"] = gimbal.Gimbal(plugin_manager)
146+
self._plugins["gripper"] = gripper.Gripper(plugin_manager)
144147
self._plugins["info"] = info.Info(plugin_manager)
145148
self._plugins["log_files"] = log_files.LogFiles(plugin_manager)
146149
self._plugins["manual_control"] = manual_control.ManualControl(plugin_manager)
@@ -159,6 +162,7 @@ async def _init_plugins(self, host, port):
159162
self._plugins["tracking_server"] = tracking_server.TrackingServer(plugin_manager)
160163
self._plugins["transponder"] = transponder.Transponder(plugin_manager)
161164
self._plugins["tune"] = tune.Tune(plugin_manager)
165+
self._plugins["winch"] = winch.Winch(plugin_manager)
162166

163167
@staticmethod
164168
def error_uninitialized(plugin_name: str) -> str:
@@ -243,6 +247,12 @@ def gimbal(self) -> gimbal.Gimbal:
243247
raise RuntimeError(self.error_uninitialized("Gimbal"))
244248
return self._plugins["gimbal"]
245249

250+
@property
251+
def gripper(self) -> gripper.Gripper:
252+
if "gripper" not in self._plugins:
253+
raise RuntimeError(self.error_uninitialized("Gripper"))
254+
return self._plugins["gripper"]
255+
246256
@property
247257
def info(self) -> info.Info:
248258
if "info" not in self._plugins:
@@ -351,6 +361,12 @@ def tune(self) -> tune.Tune:
351361
raise RuntimeError(self.error_uninitialized("Tune"))
352362
return self._plugins["tune"]
353363

364+
@property
365+
def winch(self) -> winch.Winch:
366+
if "tune" not in self._plugins:
367+
raise RuntimeError(self.error_uninitialized("Winch"))
368+
return self._plugins["winch"]
369+
354370
@staticmethod
355371
def _start_mavsdk_server(system_address, port, sysid, compid):
356372
"""

0 commit comments

Comments
 (0)