Skip to content

Commit

Permalink
Merge pull request #324 from mavlink/fix-tune
Browse files Browse the repository at this point in the history
Fix tune
  • Loading branch information
julianoes authored Mar 18, 2021
2 parents e16c5d8 + 743519c commit 163f47c
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 3 deletions.
68 changes: 68 additions & 0 deletions examples/tune.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3

import asyncio
from mavsdk import System
from mavsdk.tune import (SongElement, TuneDescription, TuneError)


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"Drone discovered with UUID: {state.uuid}")
break

song_elements = []
song_elements.append(SongElement.DURATION_4);
song_elements.append(SongElement.NOTE_G);
song_elements.append(SongElement.NOTE_A);
song_elements.append(SongElement.NOTE_B);
song_elements.append(SongElement.FLAT);
song_elements.append(SongElement.OCTAVE_UP);
song_elements.append(SongElement.DURATION_1);
song_elements.append(SongElement.NOTE_E);
song_elements.append(SongElement.FLAT);
song_elements.append(SongElement.OCTAVE_DOWN);
song_elements.append(SongElement.DURATION_4);
song_elements.append(SongElement.NOTE_PAUSE);
song_elements.append(SongElement.NOTE_F);
song_elements.append(SongElement.NOTE_G);
song_elements.append(SongElement.NOTE_A);
song_elements.append(SongElement.OCTAVE_UP);
song_elements.append(SongElement.DURATION_2);
song_elements.append(SongElement.NOTE_D);
song_elements.append(SongElement.NOTE_D);
song_elements.append(SongElement.OCTAVE_DOWN);
song_elements.append(SongElement.DURATION_4);
song_elements.append(SongElement.NOTE_PAUSE);
song_elements.append(SongElement.NOTE_E);
song_elements.append(SongElement.FLAT);
song_elements.append(SongElement.NOTE_F);
song_elements.append(SongElement.NOTE_G);
song_elements.append(SongElement.OCTAVE_UP);
song_elements.append(SongElement.DURATION_1);
song_elements.append(SongElement.NOTE_C);
song_elements.append(SongElement.OCTAVE_DOWN);
song_elements.append(SongElement.DURATION_4);
song_elements.append(SongElement.NOTE_PAUSE);
song_elements.append(SongElement.NOTE_A);
song_elements.append(SongElement.OCTAVE_UP);
song_elements.append(SongElement.NOTE_C);
song_elements.append(SongElement.OCTAVE_DOWN);
song_elements.append(SongElement.NOTE_B);
song_elements.append(SongElement.FLAT);
song_elements.append(SongElement.DURATION_2);
song_elements.append(SongElement.NOTE_G);

tune_description = TuneDescription(song_elements, 200)
await drone.tune.play_tune(tune_description)

print("Tune played")

if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
2 changes: 2 additions & 0 deletions mavsdk/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,9 +1450,11 @@ def translate_to_rpc(self, rpcSettingOptions):

rpc_elems_list = []
for elem in self.options:

rpc_elem = camera_pb2.Option()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)

rpcSettingOptions.options.extend(rpc_elems_list)


Expand Down
4 changes: 4 additions & 0 deletions mavsdk/geofence.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ def translate_to_rpc(self, rpcPolygon):

rpc_elems_list = []
for elem in self.points:

rpc_elem = geofence_pb2.Point()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)

rpcPolygon.points.extend(rpc_elems_list)


Expand Down Expand Up @@ -400,9 +402,11 @@ async def upload_geofence(self, polygons):

rpc_elems_list = []
for elem in polygons:

rpc_elem = geofence_pb2.Polygon()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)

request.polygons.extend(rpc_elems_list)


Expand Down
2 changes: 2 additions & 0 deletions mavsdk/mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,11 @@ def translate_to_rpc(self, rpcMissionPlan):

rpc_elems_list = []
for elem in self.mission_items:

rpc_elem = mission_pb2.MissionItem()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)

rpcMissionPlan.mission_items.extend(rpc_elems_list)


Expand Down
2 changes: 2 additions & 0 deletions mavsdk/mission_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,11 @@ async def upload_mission(self, mission_items):

rpc_elems_list = []
for elem in mission_items:

rpc_elem = mission_raw_pb2.MissionItem()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)

request.mission_items.extend(rpc_elems_list)


Expand Down
2 changes: 2 additions & 0 deletions mavsdk/offboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,11 @@ def translate_to_rpc(self, rpcActuatorControl):

rpc_elems_list = []
for elem in self.groups:

rpc_elem = offboard_pb2.ActuatorControlGroup()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)

rpcActuatorControl.groups.extend(rpc_elems_list)


Expand Down
4 changes: 4 additions & 0 deletions mavsdk/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,11 @@ def translate_to_rpc(self, rpcAllParams):

rpc_elems_list = []
for elem in self.int_params:

rpc_elem = param_pb2.IntParam()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)

rpcAllParams.int_params.extend(rpc_elems_list)


Expand All @@ -229,9 +231,11 @@ def translate_to_rpc(self, rpcAllParams):

rpc_elems_list = []
for elem in self.float_params:

rpc_elem = param_pb2.FloatParam()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)

rpcAllParams.float_params.extend(rpc_elems_list)


Expand Down
6 changes: 3 additions & 3 deletions mavsdk/tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ def translate_to_rpc(self, rpcTuneDescription):

rpc_elems_list = []
for elem in self.song_elements:
rpc_elem = tune_pb2.SongElement()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)
rpc_elems_list.append(elem.translate_to_rpc())
rpcTuneDescription.song_elements.extend(rpc_elems_list)


Expand Down
4 changes: 4 additions & 0 deletions other/templates/py/call.j2
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ async def {{ name.lower_snake_case }}(self{% for param in params %}, {{ param.na
{% if param.type_info.is_repeated %}
rpc_elems_list = []
for elem in {{ param.name.lower_snake_case }}:
{% if param.type_info.is_enum %}
rpc_elems_list.append(elem.translate_to_rpc())
{% else %}
rpc_elem = {{ plugin_name.lower_snake_case }}_pb2.{{ param.type_info.inner_name }}()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)
{% endif %}
request.{{ param.name.lower_snake_case }}.extend(rpc_elems_list)
{% elif param.type_info.is_enum %}
request.{{ param.name.lower_snake_case }} = {{ param.name.lower_snake_case }}.translate_to_rpc()
Expand Down
4 changes: 4 additions & 0 deletions other/templates/py/request.j2
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ async def {{ name.lower_snake_case }}(self{% for param in params %}, {{ param.na
{% if param.type_info.is_repeated %}
rpc_elems_list = []
for elem in {{ param.name.lower_snake_case }}:
{% if param.type_info.is_enum %}
rpc_elems_list.append(elem.translate_to_rpc())
{% else %}
rpc_elem = {{ plugin_name.lower_snake_case }}_pb2.{{ param.type_info.inner_name }}()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)
{% endif %}
request.{{ param.name.lower_snake_case }}.extend(rpc_elems_list)
{% elif param.type_info.is_enum %}
request.{{ param.name.lower_snake_case }} = {{ param.name.lower_snake_case }}.translate_to_rpc()
Expand Down
4 changes: 4 additions & 0 deletions other/templates/py/stream.j2
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ async def {{ name.lower_snake_case }}(self{% for param in params %}, {{ param.na
{% if param.type_info.is_repeated %}
rpc_elems_list = []
for elem in {{ param.name.lower_snake_case }}:
{% if param.type_info.is_enum %}
rpc_elems_list.append(elem.translate_to_rpc())
{% else %}
rpc_elem = {{ plugin_name.lower_snake_case }}_pb2.{{ param.type_info.inner_name }}()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)
{% endif %}
request.{{ param.name.lower_snake_case }}.extend(rpc_elems_list)
{% elif param.type_info.is_enum %}
request.{{ param.name.lower_snake_case }} = {{ param.name.lower_snake_case }}.translate_to_rpc()
Expand Down
4 changes: 4 additions & 0 deletions other/templates/py/struct.j2
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ class {{ name.upper_camel_case }}:
{% else %}
rpc_elems_list = []
for elem in self.{{ field.name.lower_snake_case }}:
{% if field.type_info.is_enum %}
rpc_elems_list.append(elem.translate_to_rpc())
{% else %}
rpc_elem = {{ plugin_name.lower_snake_case }}_pb2.{{ field.type_info.inner_name }}()
elem.translate_to_rpc(rpc_elem)
rpc_elems_list.append(rpc_elem)
{% endif %}
rpc{{ name.upper_camel_case }}.{{ field.name.lower_snake_case }}.extend(rpc_elems_list)
{% endif %}
{% else %}
Expand Down

0 comments on commit 163f47c

Please sign in to comment.