Skip to content

Commit 42022f0

Browse files
committed
Merge pull request #445 from dronekit/tcr-frame
Implements LocationGlobalRelative.
2 parents 0f14b49 + cfc072b commit 42022f0

16 files changed

Lines changed: 364 additions & 137 deletions

File tree

docs/examples/drone_delivery.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ How it works
105105
Using attribute observers
106106
-------------------------
107107

108-
All attributes in DroneKit can have observers - this is the primary mechanism you should use to be notified of changes in vehicle state. For instance, `drone_delivery.py <https://github.com/dronekit/dronekit-python/blob/master/examples/drone_delivery/drone_delivery.py>`_ calls:
108+
All attributes in DroneKit can have observers - this is the primary mechanism you should use to be notified of changes in vehicle state.
109+
For instance, `drone_delivery.py <https://github.com/dronekit/dronekit-python/blob/master/examples/drone_delivery/drone_delivery.py>`_ calls:
109110

110111
.. code-block:: python
111112
@@ -114,7 +115,7 @@ All attributes in DroneKit can have observers - this is the primary mechanism yo
114115
...
115116
116117
def location_callback(self, location):
117-
location = self.vehicle.location.global_frame
118+
location = location.global_frame
118119
119120
if location.alt is not None:
120121
self.altitude = location.alt

docs/examples/vehicle_state.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ On the command prompt you should see (something like):
5858
>>> GROUND START
5959
6060
Get all vehicle attribute values:
61-
Global Location: LocationGlobal:lat=-35.363261,lon=149.1652299,alt=0.0,is_relative=False
61+
Global Location: LocationGlobal:lat=-35.363261,lon=149.1652299,alt=None
62+
Global Location (relative altitude): LocationGlobalRelative:lat=-35.363261,lon=149.1652299,alt=0.0
6263
Local Location: LocationLocal:north=None,east=None,down=None
6364
Attitude: Attitude:pitch=0.00294387154281,yaw=-0.11805768311,roll=0.00139428151306
6465
Velocity: [-0.03, 0.02, 0.0]
@@ -81,11 +82,11 @@ On the command prompt you should see (something like):
8182
Waiting for home location ...
8283
Waiting for home location ...
8384
84-
Home location: LocationGlobal:lat=-35.3632621765,lon=149.165237427,alt=583.989990234,is_relative=False
85+
Home location: LocationGlobal:lat=-35.3632621765,lon=149.165237427,alt=583.989990234
8586
8687
Set new home location
87-
New Home Location (from attribute - altitude should be 222): LocationGlobal:lat=-35.363261,lon=149.1652299,alt=222,is_relative=False
88-
New Home Location (from vehicle - altitude should be 222): LocationGlobal:lat=-35.3632621765,lon=149.165237427,alt=222.0,is_relative=False
88+
New Home Location (from attribute - altitude should be 222): LocationGlobal:lat=-35.363261,lon=149.1652299,alt=222
89+
New Home Location (from vehicle - altitude should be 222): LocationGlobal:lat=-35.3632621765,lon=149.165237427,alt=222.0
8990
9091
Set Vehicle.mode=GUIDED (currently: STABILIZE)
9192
Waiting for mode change ...
@@ -121,13 +122,13 @@ On the command prompt you should see (something like):
121122
Wait 1s so callback invoked before observer removed
122123
CALLBACK: (attitude): Attitude:pitch=0.00716688157991,yaw=-0.0950401723385,roll=0.00759896961972
123124
CALLBACK: (heading): 354
124-
CALLBACK: (location): LocationGlobal:lat=-35.3632621,lon=149.1652291,alt=362.0,is_relative=False
125+
CALLBACK: (location): <dronekit.lib.Locations object at 0x000000000767F2B0>
125126
CALLBACK: (airspeed): 0.0
126127
CALLBACK: (groundspeed): 0.0
127128
CALLBACK: (ekf_ok): True
128129
CALLBACK: (battery): Battery:voltage=12.538,current=3.48,level=99
129130
CALLBACK: (gps_0): GPSInfo:fix=3,num_sat=10
130-
CALLBACK: (location): LocationGlobal:lat=-35.3632622,lon=149.1652295,alt=362.0,is_relative=False
131+
CALLBACK: (location): <dronekit.lib.Locations object at 0x000000000767F2B0>
131132
CALLBACK: (velocity): [-0.14, 0.1, 0.0]
132133
CALLBACK: (local_position): LocationLocal:north=-0.136136248708,east=-0.0430941730738,down=-0.00938374921679
133134
CALLBACK: (channels): {'1': 1500, '3': 1000, '2': 1500, '5': 1800, '4': 1500, '7': 1000, '6': 1000, '8': 1800}
@@ -191,7 +192,8 @@ This example has no known issues.
191192
Source code
192193
===========
193194

194-
The full source code at documentation build-time is listed below (`current version on github <https://github.com/dronekit/dronekit-python/blob/master/examples/vehicle_state/vehicle_state.py>`_):
195+
The full source code at documentation build-time is listed below
196+
(`current version on github <https://github.com/dronekit/dronekit-python/blob/master/examples/vehicle_state/vehicle_state.py>`_):
195197

196198
.. literalinclude:: ../../examples/vehicle_state/vehicle_state.py
197199
:language: python

docs/guide/migrating.rst

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ Instead, use normal Python methods for getting file system information:
170170
full_directory_path_of_current_script = os.path.dirname(os.path.abspath(__file__))
171171
172172
173+
Vehicle.location
174+
----------------
175+
176+
DroneKit-Python v1.x had a ``Vehicle.location`` attribute which provided latitude and longitude information in the
177+
global frame, and altitude either relative to sea-level or the home location (depending on the value of its ``is_relative`` member).
178+
179+
DKPY2.0 uses and attribute with the same name to provide location in
180+
global, global-relative and local (NED) frames:
181+
182+
.. code-block:: python
183+
184+
print "Global Location: %s" % vehicle.location.global_frame
185+
print "Global Location (relative altitude): %s" % vehicle.location.global_relative_frame
186+
print "Local Location: %s" % vehicle.location.local_frame
187+
188+
For more information see: :py:attr:`Vehicle.location <dronekit.lib.Vehicle.location>`,
189+
:py:attr:`Vehicle.location.global_frame <dronekit.lib.Locations.global_frame>`,
190+
:py:attr:`Vehicle.location.global_relative_frame <dronekit.lib.Locations.global_relative_frame>`,
191+
:py:attr:`Vehicle.location.local_frame <dronekit.lib.Locations.local_frame>`, and :ref:`vehicle-information`.
192+
193+
173194
.. _migrating_dkpy2_0_home_location:
174195

175196
Home location
@@ -278,8 +299,8 @@ See :ref:`mavlink_messages` for more information.
278299
New attributes
279300
--------------
280301

281-
In addition to the :ref:`home_location <migrating_dkpy2_0_heading>`, a few more attributes have been added,
282-
including:
302+
In addition to the :ref:`home_location <migrating_dkpy2_0_home_location>`,
303+
a few more attributes have been added, including:
283304
:py:func:`Vehicle.system_status <dronekit.lib.Vehicle.system_status>`,
284305
:py:func:`Vehicle.heading <dronekit.lib.Vehicle.heading>`,
285306
:py:func:`Vehicle.mount_status <dronekit.lib.Vehicle.mount_status>`,

docs/guide/taking_off.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ The code below shows a function to arm a Copter, take off, and fly to a specifie
5555
# Wait until the vehicle reaches a safe height before processing the goto (otherwise the command
5656
# after Vehicle.commands.takeoff will execute immediately).
5757
while True:
58-
print " Altitude: ", vehicle.location.global_frame.alt
59-
if vehicle.location.global_frame.alt>=aTargetAltitude*0.95: #Just below target, in case of undershoot.
58+
print " Altitude: ", vehicle.location.global_relative_frame.alt
59+
if vehicle.location.global_relative_frame.alt>=aTargetAltitude*0.95: #Just below target, in case of undershoot.
6060
print "Reached target altitude"
6161
break
6262
time.sleep(1)
@@ -127,8 +127,8 @@ concerned about reaching a particular height, a simpler implementation might jus
127127
.. code-block:: python
128128
129129
while True:
130-
print " Altitude: ", vehicle.location.global_frame.alt
131-
if vehicle.location.global_frame.alt>=aTargetAltitude*0.95: #Just below target, in case of undershoot.
130+
print " Altitude: ", vehicle.location.global_relative_frame.alt
131+
if vehicle.location.global_relative_frame.alt>=aTargetAltitude*0.95: #Just below target, in case of undershoot.
132132
print "Reached target altitude"
133133
break
134134
time.sleep(1)

docs/guide/vehicle_state_and_parameters.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ Attributes
2121

2222
Vehicle state information is exposed through vehicle *attributes*. DroneKit-Python currently supports the following
2323
"standard" attributes:
24-
:py:attr:`Vehicle.location.global_frame <dronekit.lib.Vehicle.location.global_frame>`,
25-
:py:attr:`Vehicle.location.local_frame <dronekit.lib.Vehicle.location.local_frame>`,
24+
:py:attr:`Vehicle.location.global_frame <dronekit.lib.Locations.global_frame>`,
25+
:py:attr:`Vehicle.location.global_relative_frame <dronekit.lib.Locations.global_relative_frame>`,
26+
:py:attr:`Vehicle.location.local_frame <dronekit.lib.Locations.local_frame>`,
2627
:py:attr:`Vehicle.attitude <dronekit.lib.Vehicle.attitude>`,
2728
:py:attr:`Vehicle.velocity <dronekit.lib.Vehicle.velocity>`,
2829
:py:attr:`Vehicle.airspeed <dronekit.lib.Vehicle.airspeed>`,
@@ -65,6 +66,7 @@ regularly updated from MAVLink messages sent by the vehicle).
6566
6667
# vehicle is an instance of the Vehicle class
6768
print "Global Location: %s" % vehicle.location.global_frame
69+
print "Global Location (relative altitude): %s" % vehicle.location.global_relative_frame
6870
print "Local Location: %s" % vehicle.location.local_frame #NED
6971
print "Attitude: %s" % vehicle.attitude
7072
print "Velocity: %s" % vehicle.velocity
@@ -169,7 +171,7 @@ The ``observer`` callback function is invoked with the following arguments:
169171
* ``value`` - the attribute value (so you don't need to re-query the vehicle object).
170172

171173
The code snippet below shows how to add (and remove) a callback function to observe changes
172-
in :py:attr:`Vehicle.location.global_frame <dronekit.lib.Vehicle.location.global_frame>` using
174+
in :py:attr:`Vehicle.location.global_frame <dronekit.lib.Locations.global_frame>` using
173175
:py:func:`Vehicle.add_attribute_listener() <dronekit.lib.Vehicle.add_attribute_listener>`.
174176
The two second ``sleep()`` is required because otherwise the observer might be removed before the the
175177
callback is first run.
@@ -184,13 +186,24 @@ callback is first run.
184186
185187
186188
# Add a callback `location_callback` for the `global_frame` attribute.
187-
vehicle.add_attribute_listener('global_frame', location_callback)
189+
vehicle.add_attribute_listener('location.global_frame', location_callback)
188190
189191
# Wait 2s so callback can be notified before the observer is removed
190192
time.sleep(2)
191193
192194
# Remove observer - specifying the attribute and previously registered callback function
193-
vehicle.remove_message_listener('location', location_callback)
195+
vehicle.remove_message_listener('location.global_frame', location_callback)
196+
197+
.. note::
198+
199+
The example above adds a listener on ``Vehicle`` to for attribute name ``'location.global_frame'``
200+
You can alternatively add (and remove) a listener ``Vehicle.location`` for the attribute name ``'global_frame'``.
201+
Both alternatives are shown below:
202+
203+
.. code-block:: python
204+
205+
vehicle.add_attribute_listener('location.global_frame', location_callback)
206+
vehicle.location.add_attribute_listener('global_frame', location_callback)
194207
195208
196209
The example below shows how you can declare an attribute callback using the

dronekit/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
CommandSequence = dronekit.lib.CommandSequence
2121
VehicleMode = dronekit.lib.VehicleMode
2222
SystemStatus = dronekit.lib.SystemStatus
23+
LocationGlobalRelative = dronekit.lib.LocationGlobalRelative
2324
LocationGlobal = dronekit.lib.LocationGlobal
2425
LocationLocal = dronekit.lib.LocationLocal
2526
CloudClient = dronekit.lib.CloudClient

0 commit comments

Comments
 (0)