Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ from dronekit import connect
from dronekit.lib import VehicleMode

# Connect to UDP endpoint.
vehicle = connect('127.0.0.1:14550', await_params=True)
vehicle = connect('127.0.0.1:14550', wait_ready=True)
# Use returned Vehicle object to query device state - e.g. to get the mode:
print " Mode: %s" % vehicle.mode.name
```
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/create_attribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ All values in the new attribute should be set to ``None`` so that it is obvious
.. code:: python

# Connect to the Vehicle passed in as args.connect
vehicle = connect(args.connect, await_params=True)
vehicle = connect(args.connect, wait_ready=True)

#Create an Vehicle.raw_imu object and set all values to None.
vehicle.raw_imu=RawIMU(None,None,None,None,None,None,None,None,None,None)
Expand Down
10 changes: 5 additions & 5 deletions docs/guide/auto_mode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use :py:func:`wait_ready() <dronekit.lib.CommandSequence.wait_ready>` to block y
.. code:: python

# Connect to the Vehicle (in this case a simulated vehicle at 127.0.0.1:14550)
vehicle = connect('127.0.0.1:14550', await_params=True)
vehicle = connect('127.0.0.1:14550', wait_ready=True)

# Download the vehicle waypoints (commands). Wait until download is complete.
cmds = vehicle.commands
Expand All @@ -96,7 +96,7 @@ To clear a mission you call :py:func:`clear() <dronekit.lib.CommandSequence.clea
.. code:: python

# Connect to the Vehicle (in this case a simulated vehicle at 127.0.0.1:14550)
vehicle = connect('127.0.0.1:14550', await_params=True)
vehicle = connect('127.0.0.1:14550', wait_ready=True)

# Get commands object from Vehicle.
cmds = vehicle.commands
Expand Down Expand Up @@ -128,7 +128,7 @@ The supported commands for each vehicle are :ref:`linked above <auto_mode_suppor
.. code:: python

# Connect to the Vehicle (in this case a simulated vehicle at 127.0.0.1:14550)
vehicle = connect('127.0.0.1:14550', await_params=True)
vehicle = connect('127.0.0.1:14550', wait_ready=True)

# Get the set of commands from the vehicle
cmds = vehicle.commands
Expand Down Expand Up @@ -161,7 +161,7 @@ modify them as needed, then clear ``Vehicle.commands`` and upload the list as a
.. code:: python

# Connect to the Vehicle (in this case a simulated vehicle at 127.0.0.1:14550)
vehicle = connect('127.0.0.1:14550', await_params=True)
vehicle = connect('127.0.0.1:14550', wait_ready=True)

# Get the set of commands from the vehicle
cmds = vehicle.commands
Expand Down Expand Up @@ -200,7 +200,7 @@ To start a mission, change the mode to AUTO:
.. code:: python

# Connect to the Vehicle (in this case a simulated vehicle at 127.0.0.1:14550)
vehicle = connect('127.0.0.1:14550', await_params=True)
vehicle = connect('127.0.0.1:14550', wait_ready=True)

# Set the vehicle into auto mode
vehicle.mode = VehicleMode("AUTO")
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ and attributes, and control vehicle movement.
from dronekit import connect

# Connect to UDP endpoint.
vehicle = connect('127.0.0.1:14550', await_params=True)
vehicle = connect('127.0.0.1:14550', wait_ready=True)

.. note::

Calling ``connect()`` with ``await_params=True`` (as shown above) ensures that the method will not return until
Calling ``connect()`` with ``wait_ready=True`` (as shown above) ensures that the method will not return until
:py:attr:`Vehicle.parameters <dronekit.lib.Vehicle.parameters>` is fully populated with values from the vehicle.
Vehicle *attributes* are populated in parallel but are not guaranteed to have values when ``connect()`` completes
(an attribute will have value ``None`` if a corresponding MAVLink message has not been received - for example,
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/migrating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ values as were passed to *MAVProxy* when setting up a connection in DKPY 1.x (in
from dronekit import connect

# Connect to the Vehicle (in this case a UDP endpoint)
vehicle = connect('127.0.0.1:14550', await_params=True)
vehicle = connect('127.0.0.1:14550', wait_ready=True)


The ``await_params=True`` parameter ensures that ``connect()`` won't return until
The ``wait_ready=True`` parameter ensures that ``connect()`` won't return until
:py:attr:`Vehicle.parameters <dronekit.lib.Vehicle.parameters>` has been populated.
This also allows *MAVLink* messages to arrive from the connected vehicle
and populate other ``Vehicle`` attributes.
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/taking_off.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The code below shows a function to arm a Copter, take off, and fly to a specifie
.. code-block:: python

# Connect to the Vehicle (in this case a simulator running the same computer)
vehicle = connect('127.0.0.1:14550', await_params=True)
vehicle = connect('127.0.0.1:14550', wait_ready=True)

def arm_and_takeoff(aTargetAltitude):
"""
Expand Down
11 changes: 8 additions & 3 deletions dronekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def close(self):
time.sleep(0.1)
self.master.close()

def connect(ip, await_params=False, status_printer=errprinter, vehicle_class=Vehicle, rate=4, baud=115200):
def connect(ip, wait_ready=None, status_printer=errprinter, vehicle_class=Vehicle, rate=4, baud=115200):
handler = MAVHandler(mavutil.mavlink_connection(ip, baud=baud))
vehicle = vehicle_class(handler)

Expand All @@ -181,6 +181,11 @@ def listener(self, name, m):
status_printer(re.sub(r'(^|\n)', '>>> ', m.text.rstrip()))

vehicle.initialize(rate=rate)
if await_params:
vehicle.wait_ready('parameters', 'gps_0')

if wait_ready:
if wait_ready == True:
vehicle.wait_ready(True)
else:
vehicle.wait_ready(*wait_ready)

return vehicle
19 changes: 13 additions & 6 deletions dronekit/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from dronekit import connect

# Connect to the Vehicle using "connection string" (in this case an address on network)
vehicle = connect('127.0.0.1:14550', await_params=True)
vehicle = connect('127.0.0.1:14550', wait_ready=True)

:py:class:`Vehicle <dronekit.lib.Vehicle>` provides access to vehicle *state* through python attributes
(e.g. :py:attr:`Vehicle.mode <dronekit.lib.Vehicle.mode>`)
Expand All @@ -39,13 +39,13 @@

.. todo:: Update this when have confirmed how to register for parameter notifications.

.. py:function:: connect(ip, await_params=False, status_printer=errprinter, vehicle_class=Vehicle, rate=4)
.. py:function:: connect(ip, wait_ready=False, status_printer=errprinter, vehicle_class=Vehicle, rate=4)

Returns a :py:class:`Vehicle` object connected to the address specified by string parameter ``ip``.
Connection string parameters for different targets are listed in the :ref:`getting started guide <get_started_connecting>`.

:param String ip: Connection string for target address - e.g. 127.0.0.1:14550.
:param Bool await_params: Wait until all :py:func:`Vehicle.parameters` have downloaded before the method returns (default is false)
:param Bool wait_ready: Wait until all :py:func:`Vehicle.parameters` have downloaded before the method returns (default is false)
:param status_printer: NA
:param Vehicle vehicle_class: NA
:param int rate: NA
Expand Down Expand Up @@ -540,6 +540,9 @@ def __init__(self, handler):
# By default, we presume all "commands" are loaded.
self._ready_attrs = set(['commands'])

# Default parameters when calling wait_ready() or wait_ready(True).
self._default_ready_attrs = ['parameters', 'gps_0', 'armed', 'mode', 'attitude']

@self.attribute_listener('*')
def listener(_, name):
self._ready_attrs.add(name)
Expand Down Expand Up @@ -1009,7 +1012,7 @@ def home_location(self):
.. code-block:: python

#Connect to a vehicle object (for example, on com14)
vehicle = connect('com14', await_params=True)
vehicle = connect('com14', wait_ready=True)

# Download the vehicle waypoints (commands). Wait until download is complete.
cmds = vehicle.commands
Expand Down Expand Up @@ -1113,7 +1116,7 @@ def message_factory(self):
"""
return self._master.mav

def initialize(self, await_params=False, rate=None):
def initialize(self, wait_ready=False, rate=None):
self._handler.start()

# Wait for first heartbeat.
Expand Down Expand Up @@ -1149,6 +1152,10 @@ def wait_ready(self, *types, **kwargs):
timeout = kwargs.get('timeout', 30)
raise_exception = kwargs.get('raise_exception', True)

# Vehicle defaults for wait_ready(True) or wait_ready()
if list(types) == [True] or list(types) == []:
types = self._default_ready_attrs

if not all(isinstance(item, basestring) for item in types):
raise APIException('wait_ready expects one or more string arguments.')

Expand Down Expand Up @@ -1298,7 +1305,7 @@ class CommandSequence(object):
:emphasize-lines: 5-10

#Connect to a vehicle object (for example, on com14)
vehicle = connect('com14', await_params=True)
vehicle = connect('com14', wait_ready=True)

# Download the vehicle waypoints (commands). Wait until download is complete.
cmds = vehicle.commands
Expand Down
2 changes: 1 addition & 1 deletion examples/channel_overrides/channel_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

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

#Override channels
print "\nOverriding RC channels for roll and yaw"
Expand Down
2 changes: 1 addition & 1 deletion examples/create_attribute/create_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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



Expand Down
2 changes: 1 addition & 1 deletion examples/drone_delivery/drone_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Drone(object):
def __init__(self, home_coords, server_enabled=True):
# Connect to the Vehicle
print 'Connecting to vehicle on: %s' % args.connect
self.vehicle = connect(args.connect, await_params=True)
self.vehicle = connect(args.connect, wait_ready=True)
print "connected ..."
self.gps_lock = False
self.altitude = 30.0
Expand Down
2 changes: 1 addition & 1 deletion examples/flight_replay/flight_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

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



Expand Down
2 changes: 1 addition & 1 deletion examples/follow_me/follow_me.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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



Expand Down
2 changes: 1 addition & 1 deletion examples/gcs/microgcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

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

def setMode(mode):
# Now change the vehicle into auto mode
Expand Down
2 changes: 1 addition & 1 deletion examples/guided_set_speed_yaw/guided_set_speed_yaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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


def arm_and_takeoff(aTargetAltitude):
Expand Down
2 changes: 1 addition & 1 deletion examples/mission_basic/mission_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

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


def get_location_metres(original_location, dNorth, dEast):
Expand Down
2 changes: 1 addition & 1 deletion examples/mission_import_export/mission_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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


def readmission(aFileName):
Expand Down
2 changes: 1 addition & 1 deletion examples/perf/perf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

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

#global vehicle

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_goto/simple_goto.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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


def arm_and_takeoff(aTargetAltitude):
Expand Down
2 changes: 1 addition & 1 deletion examples/vehicle_state/vehicle_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# Connect to the Vehicle
print "\nConnecting to vehicle on: %s" % args.connect
vehicle = connect(args.connect, await_params=True)
vehicle = connect(args.connect, wait_ready=True)

if vehicle.mode.name == "INITIALISING":
print "Waiting for vehicle to initialise"
Expand Down
2 changes: 1 addition & 1 deletion tests/sitl/test_110.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@with_sitl
def test_110(connpath):
v = connect(connpath, await_params=True)
v = connect(connpath, wait_ready=True)

# NOTE these are *very inappropriate settings*
# to make on a real vehicle. They are leveraged
Expand Down
2 changes: 1 addition & 1 deletion tests/sitl/test_115.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@with_sitl
def test_115(connpath):
v = connect(connpath, await_params=True)
v = connect(connpath, wait_ready=True)

# Dummy callback
def mavlink_callback(*args):
Expand Down
2 changes: 1 addition & 1 deletion tests/sitl/test_12.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def current_milli_time():

@with_sitl
def test_timeout(connpath):
v = connect(connpath, await_params=True)
v = connect(connpath, wait_ready=True)

value = v.parameters['THR_MIN']
assert_equals(type(value), float)
Expand Down
2 changes: 1 addition & 1 deletion tests/sitl/test_goto.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@with_sitl
def test_goto(connpath):
vehicle = connect(connpath, await_params=True)
vehicle = connect(connpath, wait_ready=True)

# NOTE these are *very inappropriate settings*
# to make on a real vehicle. They are leveraged
Expand Down
2 changes: 1 addition & 1 deletion tests/sitl/test_localposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@with_sitl
def test_timeout(connpath):
vehicle = connect(connpath, await_params=True)
vehicle = connect(connpath, wait_ready=True)

# NOTE these are *very inappropriate settings*
# to make on a real vehicle. They are leveraged
Expand Down
4 changes: 2 additions & 2 deletions tests/sitl/test_simpledemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
# This test runs first!
@with_sitl
def test_parameter(connpath):
v = connect(connpath, await_params=True)
v = connect(connpath, wait_ready=True)

# Perform a simple parameter check
assert_equals(type(v.parameters['THR_MIN']), float)

# This test runs second. Add as many tests as you like
@with_sitl
def test_mode(connpath):
v = connect(connpath, await_params=True)
v = connect(connpath, wait_ready=True)

# Ensure Mode is an instance of VehicleMode
assert isinstance(v.mode, VehicleMode)
4 changes: 2 additions & 2 deletions tests/sitl/test_waypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_empty_clear(connpath):

@with_sitl
def test_set_home(connpath):
vehicle = connect(connpath, await_params=True)
vehicle = connect(connpath, wait_ready=True)

# Wait for home position to be real and not 0, 0, 0
# once we request it via cmds.download()
Expand All @@ -38,7 +38,7 @@ def test_set_home(connpath):

@with_sitl
def test_parameter(connpath):
vehicle = connect(connpath, await_params=True)
vehicle = connect(connpath, wait_ready=True)

# Home should be None at first.
assert_equals(vehicle.home_location, None)
Expand Down