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
30 changes: 20 additions & 10 deletions docs/examples/simple_goto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,19 @@ On the command prompt you should see (something like):
>>> APM:Copter V3.4-dev (e0810c2e)
>>> Frame: QUAD
Basic pre-arm checks
Waiting for GPS...: None
...
Waiting for GPS...: None
Waiting for vehicle to initialise...
Waiting for vehicle to initialise...
Waiting for vehicle to initialise...
Waiting for vehicle to initialise...
Waiting for vehicle to initialise...
Arming motors
Waiting for arming...
Waiting for arming...
Waiting for arming...
>>> ARMING MOTORS
>>> GROUND START
Waiting for arming...
Waiting for arming...
>>> Initialising APM...
Taking off!
Altitude: 0.0
Expand All @@ -93,14 +100,16 @@ On the command prompt you should see (something like):

.. tip::

If you get stuck in ``Waiting for arming...`` it is very likely that the vehicle did not pass all pre-arm checks.
On a real device you can view the controller LEDs to determine possible causes. On the Simulator console you
can disable the checks if needed:
The code waits on :py:func:`Vehicle.is_armable <dronekit.lib.Vehicle.is_armable>`, so you shouldn't get stuck in ``Waiting for arming...``.
If you do, then:

* On a real device you can view the controller LEDs to determine possible causes.
* On the Simulator console you can disable the checks if needed:

.. code-block:: bash
.. code-block:: bash

STABILIZE>param load ../Tools/autotest/copter_params.parm
STABILIZE>param set ARMING_CHECK 0
STABILIZE>param load ../Tools/autotest/copter_params.parm
STABILIZE>param set ARMING_CHECK 0


How does it work?
Expand All @@ -111,7 +120,8 @@ The code has three distinct sections: arming and takeoff, flight to two location
Takeoff
-------

To launch *Copter* you need to set the mode to ``GUIDED``, arm the vehicle, and then call
To launch *Copter* you need to first check that the vehicle :py:func:`Vehicle.is_armable <dronekit.lib.Vehicle.is_armable>`.
Then set the mode to ``GUIDED``, arm the vehicle, and call
:py:func:`Vehicle.commands.takeoff() <dronekit.lib.CommandSequence.takeoff>`. The takeoff code in this example
is explained in the guide topic :ref:`taking-off`.

Expand Down
1 change: 1 addition & 0 deletions docs/examples/vehicle_state.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ On the command prompt you should see (something like):
Rangefinder: Rangefinder: distance=None, voltage=None
Rangefinder distance: None
Rangefinder voltage: None
Is Armable?: True
System status: 3
Heading: 341
Mode: STABILIZE
Expand Down
7 changes: 5 additions & 2 deletions docs/guide/migrating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,11 @@ New attributes

In addition to the :ref:`home_location <migrating_dkpy2_0_heading>`, a few more attributes have been added,
including:
:py:func:`Vehicle.system_status <dronekit.lib.Vehicle.system_status>` and
:py:func:`Vehicle.heading <dronekit.lib.Vehicle.heading>`.
:py:func:`Vehicle.system_status <dronekit.lib.Vehicle.system_status>`,
:py:func:`Vehicle.heading <dronekit.lib.Vehicle.heading>`,
:py:func:`Vehicle.mount_status <dronekit.lib.Vehicle.mount_status>`,
:py:func:`Vehicle.ekf_ok <dronekit.lib.Vehicle.ekf_ok>`,
:py:func:`Vehicle.is_armable <dronekit.lib.Vehicle.is_armable>`.


Debugging
Expand Down
42 changes: 29 additions & 13 deletions docs/guide/taking_off.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ and then call :py:func:`Vehicle.commands.takeoff() <dronekit.lib.CommandSequence
Copter is always started in ``GUIDED`` mode. Copter will not take off ``AUTO`` mode even if you have a
`MAV_CMD_NAV_TAKEOFF <http://copter.ardupilot.com/common-mavlink-mission-command-messages-mav_cmd/#copter-2>`_ waypoint
in your mission (you can run a mission by switching to ``AUTO`` mode after you're in the air).

By contrast, Plane apps take off using the ``MAV_CMD_NAV_TAKEOFF`` command in a mission. Plane should first arm and then change to
``AUTO`` mode to start the mission.

The code below shows a function to arm a Copter, take off, and fly to a specified altitude. This is taken from :ref:`example_simple_goto`.

Expand All @@ -33,12 +36,9 @@ The code below shows a function to arm a Copter, take off, and fly to a specifie
"""

print "Basic pre-arm checks"
# Don't let the user try to fly autopilot is booting
if vehicle.mode.name == "INITIALISING":
print "Waiting for vehicle to initialise"
time.sleep(1)
while vehicle.gps_0.fix_type < 2:
print "Waiting for GPS...:", vehicle.gps_0.fix_type
# Don't let the user try to arm until autopilot is ready
while not vehicle.is_armable:
print " Waiting for vehicle to initialise..."
time.sleep(1)

print "Arming motors"
Expand Down Expand Up @@ -72,16 +72,32 @@ The function first performs some pre-arm checks.
until the vehicle has passed a series of pre-arm checks to ensure that it is safe to fly.

DroneKit-Python can't check every possible symptom that might prevent arming, but we can confirm that the
vehicle has booted and has a GPS lock:
vehicle has booted, EKF is ready, and it has a GPS lock. These checks are encapsulated in the
:py:func:`Vehicle.is_armable <dronekit.lib.Vehicle.is_armable>` attribute:

.. code-block:: python

if v.mode.name == "INITIALISING":
print "Waiting for vehicle to initialise"
time.sleep(1)
while vehicle.gps_0.fix_type < 2:
print "Waiting for GPS...:", vehicle.gps_0.fix_type
time.sleep(1)
print "Basic pre-arm checks"
# Don't let the user try to arm until autopilot is ready
while not vehicle.is_armable:
print " Waiting for vehicle to initialise..."
time.sleep(1)

.. note::

If you need more status information you can perform the following sorts of checks:

.. code-block:: python

if v.mode.name == "INITIALISING":
print "Waiting for vehicle to initialise"
time.sleep(1)
while vehicle.gps_0.fix_type < 2:
print "Waiting for GPS...:", vehicle.gps_0.fix_type
time.sleep(1)

You should always do a final check on :py:func:`Vehicle.is_armable <dronekit.lib.Vehicle.is_armable>`!


Once the vehicle is ready we set the mode to ``GUIDED`` and arm it. We then wait until arming is confirmed
before sending the :py:func:`takeoff <dronekit.lib.CommandSequence.takeoff>` command.
Expand Down
2 changes: 2 additions & 0 deletions docs/guide/vehicle_state_and_parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Vehicle state information is exposed through vehicle *attributes*. DroneKit-Pyth
:py:attr:`Vehicle.home_location <dronekit.lib.Vehicle.home_location>`,
:py:func:`Vehicle.system_status <dronekit.lib.Vehicle.system_status>`,
:py:func:`Vehicle.heading <dronekit.lib.Vehicle.heading>`,
:py:func:`Vehicle.is_armable <dronekit.lib.Vehicle.is_armable>`,
:py:attr:`Vehicle.armed <dronekit.lib.Vehicle.armed>`,
:py:attr:`Vehicle.mode <dronekit.lib.Vehicle.mode>`.

Expand Down Expand Up @@ -72,6 +73,7 @@ regularly updated from MAVLink messages sent by the vehicle).
print "Rangefinder distance: %s" % vehicle.rangefinder.distance
print "Rangefinder voltage: %s" % vehicle.rangefinder.voltage
print "Heading: %s" % vehicle.heading
print "Is Armable?: %s" % vehicle.is_armable
print "System status: %s" % vehicle.system_status
print "Mode: %s" % vehicle.mode.name # settable
print "Armed: %s" % vehicle.armed # settable
Expand Down
13 changes: 13 additions & 0 deletions dronekit/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,19 @@ def armed(self, value):
else:
self._master.arducopter_disarm()

@property
def is_armable(self):
"""
Returns ``True`` if the vehicle is ready to arm, false otherwise.

This attribute wraps a number of pre-arm checks, ensuring that the vehicle has booted,
has a good GPS fix, and that the EKF pre-arm is complete.
"""
# check that mode is not INITIALSING
# check that we have a GPS fix
# check that EKF pre-arm is complete
return self.mode != 'INITIALISING' and self.gps_0.fix_type > 1 and self._ekf_predposhorizabs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think arming requires a 3D Fix (on Copter at least) based on various comments around the place. Should be checked. And yes, I know my tests look at <2 ... I do wonder though if perhaps the 3D fix happens very quickly after 2d fix and I've just got lucky.


@property
def system_status(self):
"""
Expand Down
32 changes: 11 additions & 21 deletions dronekit/test/sitl/test_goto.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,33 @@ def arm_and_takeoff(aTargetAltitude):
Arms vehicle and fly to aTargetAltitude.
"""

# print "Basic pre-arm checks"
# Don't let the user try to fly autopilot is booting
if vehicle.mode.name == "INITIALISING":
# print "Waiting for vehicle to initialise"
time.sleep(1)
while vehicle.gps_0.fix_type < 2:
# print "Waiting for GPS...:", vehicle.gps_0.fix_type
i = 60
while not vehicle.is_armable and i > 0:
time.sleep(1)

# print "Arming motors"
# Copter should arm in GUIDED mode
vehicle.mode = VehicleMode("GUIDED")
i = i - 1
assert_equals(vehicle.is_armable, True)

# Copter should arm in GUIDED mode
vehicle.mode = VehicleMode("GUIDED")
i = 60
while vehicle.mode.name != 'GUIDED' and i > 0:
# print " Waiting for guided %s seconds..." % (i,)
time.sleep(1)
i = i - 1
assert_equals(vehicle.mode.name, 'GUIDED')

# EKF warmup. Await that EKF's predicted horizontal position (absolute) estimate is good
while not vehicle._ekf_predposhorizabs:
time.sleep(1)

# Arm copter.
vehicle.armed = True

i = 60
while not vehicle.armed and vehicle.mode.name == 'GUIDED' and i > 0:
# print " Waiting for arming %s seconds..." % (i,)
time.sleep(1)
i = i - 1
assert_equals(vehicle.armed, True)

# Failure will result in arming but immediately landing
assert vehicle.armed
assert_equals(vehicle.mode.name, 'GUIDED')

# print "Taking off!"
vehicle.commands.takeoff(aTargetAltitude) # Take off to target altitude
# Take off to target altitude
vehicle.commands.takeoff(aTargetAltitude)

# Wait until the vehicle reaches a safe height before
# processing the goto (otherwise the command after
Expand Down
32 changes: 11 additions & 21 deletions dronekit/test/sitl/test_localposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,33 @@ def arm_and_takeoff(aTargetAltitude):
Arms vehicle and fly to aTargetAltitude.
"""

# print "Basic pre-arm checks"
# Don't let the user try to fly autopilot is booting
if vehicle.mode.name == "INITIALISING":
# print "Waiting for vehicle to initialise"
time.sleep(1)
while vehicle.gps_0.fix_type < 2:
# print "Waiting for GPS...:", vehicle.gps_0.fix_type
i = 60
while not vehicle.is_armable and i > 0:
time.sleep(1)

# print "Arming motors"
# Copter should arm in GUIDED mode
vehicle.mode = VehicleMode("GUIDED")
i = i - 1
assert_equals(vehicle.is_armable, True)

# Copter should arm in GUIDED mode
vehicle.mode = VehicleMode("GUIDED")
i = 60
while vehicle.mode.name != 'GUIDED' and i > 0:
# print " Waiting for guided %s seconds..." % (i,)
time.sleep(1)
i = i - 1
assert_equals(vehicle.mode.name, 'GUIDED')

# EKF warmup. Await that EKF's predicted horizontal position (absolute) estimate is good
while not vehicle._ekf_predposhorizabs:
time.sleep(1)

# Arm copter.
vehicle.armed = True

i = 60
while not vehicle.armed and vehicle.mode.name == 'GUIDED' and i > 0:
# print " Waiting for arming %s seconds..." % (i,)
time.sleep(1)
i = i - 1
assert_equals(vehicle.armed, True)

# Failure will result in arming but immediately landing
assert vehicle.armed
assert_equals(vehicle.mode.name, 'GUIDED')

# print "Taking off!"
vehicle.commands.takeoff(aTargetAltitude) # Take off to target altitude
# Take off to target altitude
vehicle.commands.takeoff(aTargetAltitude)

# Wait until the vehicle reaches a safe height before
# processing the goto (otherwise the command after
Expand Down
9 changes: 3 additions & 6 deletions examples/simple_goto/simple_goto.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ def arm_and_takeoff(aTargetAltitude):
"""

print "Basic pre-arm checks"
# Don't let the user try to fly autopilot is booting
if vehicle.mode.name == "INITIALISING":
print "Waiting for vehicle to initialise"
time.sleep(1)
while vehicle.gps_0.fix_type < 2:
print "Waiting for GPS...:", vehicle.gps_0.fix_type
# Don't let the user try to arm until autopilot is ready
while not vehicle.is_armable:
print " Waiting for vehicle to initialise..."
time.sleep(1)


Expand Down
1 change: 1 addition & 0 deletions examples/vehicle_state/vehicle_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
print " Rangefinder distance: %s" % vehicle.rangefinder.distance
print " Rangefinder voltage: %s" % vehicle.rangefinder.voltage
print " Heading: %s" % vehicle.heading
print " Is Armable?: %s" % vehicle.is_armable
print " System status: %s" % vehicle.system_status
print " Mode: %s" % vehicle.mode.name # settable
print " Armed: %s" % vehicle.armed # settable
Expand Down