Skip to content

Commit

Permalink
Add play_tune() method on vehicle, example for same
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Jun 1, 2017
1 parent 0cf17f8 commit 5f6a6e7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dronekit/__init__.py
Expand Up @@ -2146,6 +2146,11 @@ def send_capabilties_request(self, vehicle, name, m):
capability_msg = vehicle.message_factory.command_long_encode(0, 0, mavutil.mavlink.MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES, 0, 1, 0, 0, 0, 0, 0, 0)
vehicle.send_mavlink(capability_msg)

def play_tune(self, tune):
'''Request an AUTOPILOT_VERSION packet'''
msg = self.message_factory.play_tune_encode(0, 0, tune)
self.send_mavlink(msg)

def wait_ready(self, *types, **kwargs):
"""
Waits for specified attributes to be populated from the vehicle (values are initially ``None``).
Expand Down
42 changes: 42 additions & 0 deletions examples/play_tune/play_tune.py
@@ -0,0 +1,42 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
© Copyright 2017, Peter Barker
play_tune.py: GUIDED mode "simple goto" example (Copter Only)
Demonstrates how to play a custom tune on a vehicle using the vehicle's buzzer
Full documentation is provided at http://python.dronekit.io/examples/play_tune.html
"""

from __future__ import print_function
import time
from dronekit import connect


# Set up option parsing to get connection string
import argparse
parser = argparse.ArgumentParser(description='Play tune on vehicle buzzer.')
parser.add_argument('--connect',
help="Vehicle connection target string. If not specified, SITL automatically started and used.")
parser.add_argument('--tune', type=str, help="tune to play", default="AAAA")
args = parser.parse_args()

connection_string = args.connect
sitl = None


# Start SITL if no connection string specified
if not connection_string:
print("SITL doesn't do tunes?!")
import dronekit_sitl
sitl = dronekit_sitl.start_default()
connection_string = sitl.connection_string()


# Connect to the Vehicle
print('Connecting to vehicle on: %s' % connection_string)
vehicle = connect(connection_string, wait_ready=True)

vehicle.play_tune(args.tune)

0 comments on commit 5f6a6e7

Please sign in to comment.