Skip to content
Closed
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
16 changes: 16 additions & 0 deletions droneapi/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,22 @@ def mavrx_debug_handler(message):
"""
self.mavrx_callback = callback

def unset_mavlink_callback(self):
"""
Clears the asynchronous notification added by set_mavlink_callback.

The code snippet below shows how to set, then clear, a MAVLink callback function.

.. code:: python
# Set MAVLink callback handler (after getting Vehicle instance)
vehicle.set_mavlink_callback(mavrx_debug_handler)

# Remove the MAVLink callback handler. Callback will not be
# called after this point.
vehicle.unset_mavlink_callback()
"""
self.mavrx_callback = None

def flush(self):
"""
It is important to understand that setting attributes/changing vehicle state may occur over a slow link.
Expand Down
2 changes: 1 addition & 1 deletion droneapi/module/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def set(chnum, v):
self.__on_change('rangefinder')


if (self.vehicle is not None) and hasattr(self.vehicle, 'mavrx_callback'):
if (self.vehicle is not None) and getattr(self.vehicle, 'mavrx_callback', None):
self.vehicle.mavrx_callback(m)

self.send_to_server(m)
Expand Down
1 change: 1 addition & 0 deletions tests/sitl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def lets_run_a_test(name):
# NOTE these are *very inappropriate settings*
# to make on a real vehicle. They are leveraged
# exclusively for simulation. Take heed!!!
p.stdin.write('set moddebug 3\n')
p.stdin.write('param set ARMING_CHECK 0\n')
p.stdin.write('param set FS_THR_ENABLE 0\n')
p.stdin.write('param set FS_GCS_ENABLE 0\n')
Expand Down
37 changes: 37 additions & 0 deletions tests/sitl/test_115.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from droneapi.lib import VehicleMode
from pymavlink import mavutil
import time
import sys
import os

def test_115(local_connect):
api = local_connect()
v = api.get_vehicles()[0]

# Dummy callback
def noop(*args):
pass

# Set the callback.
v.set_mavlink_callback(noop)

# Change the vehicle into STABILIZE mode
v.mode = VehicleMode("STABILIZE")

# NOTE wait crudely for ACK on mode update
time.sleep(3)

# Unset the callback.
v.set_mavlink_callback(None)

# Disarm should not throw errors.
v.armed = False
v.flush()

time.sleep(3)

# Re-arm should not throw errors.
v.armed = True
v.flush()

time.sleep(3)