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 docs/examples/vehicle_state.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ On the command prompt you should see (something like):
Rangefinder distance: None
Rangefinder voltage: None
Is Armable?: True
System status: 3
System status: STANDBY
Heading: 341
Mode: STABILIZE
Armed: False
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/vehicle_state_and_parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ regularly updated from MAVLink messages sent by the vehicle).
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 "System status: %s" % vehicle.system_status.state
print "Mode: %s" % vehicle.mode.name # settable
print "Armed: %s" % vehicle.armed # settable

Expand Down
1 change: 1 addition & 0 deletions dronekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Command = dronekit.lib.Command
CommandSequence = dronekit.lib.CommandSequence
VehicleMode = dronekit.lib.VehicleMode
SystemStatus = dronekit.lib.SystemStatus
LocationGlobal = dronekit.lib.LocationGlobal
LocationLocal = dronekit.lib.LocationLocal
CloudClient = dronekit.lib.CloudClient
Expand Down
55 changes: 41 additions & 14 deletions dronekit/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,26 @@ def __eq__(self, other):
def __ne__(self, other):
return self.name != other

class SystemStatus(object):
"""
This object is used to get and set the current "system status".

.. py:attribute:: state

The system state, as a ``string``.
"""
def __init__(self, state):
self.state = state

def __str__(self):
return "SystemStatus:%s" % self.state

def __eq__(self, other):
return self.state == other

def __ne__(self, other):
return self.state != other

class HasObservers(object):
def __init__(self):
# A mapping from attr_name to a list of observers
Expand Down Expand Up @@ -744,8 +764,9 @@ def listener(self, name, m):
self._armed = (m.base_mode & mavutil.mavlink.MAV_MODE_FLAG_SAFETY_ARMED) != 0
self.notify_attribute_listeners('armed', self.armed)
self._flightmode = {v: k for k, v in self._master.mode_mapping().items()}[m.custom_mode]
self._system_status = m.system_status
self.notify_attribute_listeners('mode', self.mode)
self._system_status = m.system_status
self.notify_attribute_listeners('system_status', self.system_status)

# Waypoints.

Expand Down Expand Up @@ -1071,22 +1092,28 @@ def is_armable(self):
@property
def system_status(self):
"""
System status flag according to the MAVLink
`MAV_STATE <http://mavlink.org/messages/common#MAV_STATE_UNINIT>`_ enum.

States include:
System status. Is a ``SystemStatus`` object with a ``state`` property of:

* ``MAV_STATE_UNINIT`` (0): Uninitialized system, state is unknown.
* ``MAV_STATE_BOOT`` (1): System is booting up.
* ``MAV_STATE_CALIBRATING`` (2): System is calibrating and not flight-ready.
* ``MAV_STATE_STANDBY`` (3): System is grounded and on standby. It can be launched any time.
* ``MAV_STATE_ACTIVE`` (4): System is active and might be already airborne. Motors are engaged.
* ``MAV_STATE_CRITICAL`` (5): System is in a non-normal flight mode. It can however still navigate.
* ``MAV_STATE_EMERGENCY`` (6): System is in a non-normal flight mode. It lost control over parts
* ``UNINIT``: Uninitialized system, state is unknown.
* ``BOOT``: System is booting up.
* ``CALIBRATING``: System is calibrating and not flight-ready.
* ``STANDBY``: System is grounded and on standby. It can be launched any time.
* ``ACTIVE``: System is active and might be already airborne. Motors are engaged.
* ``CRITICAL``: System is in a non-normal flight mode. It can however still navigate.
* ``EMERGENCY``: System is in a non-normal flight mode. It lost control over parts
or over the whole airframe. It is in mayday and going down.
* ``MAV_STATE_POWEROFF`` (7): System just initialized its power-down sequence, will shut down now.
* ``POWEROFF``: System just initialized its power-down sequence, will shut down now.
"""
return self._system_status
return {
0: SystemStatus('UNINIT'),
1: SystemStatus('BOOT'),
2: SystemStatus('CALIBRATING'),
3: SystemStatus('STANDBY'),
4: SystemStatus('ACTIVE'),
5: SystemStatus('CRITICAL'),
6: SystemStatus('EMERGENCY'),
7: SystemStatus('POWEROFF'),
}.get(self._system_status, None)

@property
def heading(self):
Expand Down
14 changes: 14 additions & 0 deletions dronekit/test/sitl/test_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import time
import sys
import os
import socket
from dronekit import connect, VehicleMode, SystemStatus
from dronekit.test import with_sitl
from nose.tools import assert_equals

@with_sitl
def test_state(connpath):
vehicle = connect(connpath, wait_ready=['system_status'])

assert_equals(type(vehicle.system_status), SystemStatus)
assert_equals(type(vehicle.system_status.state), str)
2 changes: 1 addition & 1 deletion examples/vehicle_state/vehicle_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
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 " System status: %s" % vehicle.system_status.state
print " Mode: %s" % vehicle.mode.name # settable
print " Armed: %s" % vehicle.armed # settable

Expand Down