dronekit / dronekit-python Goto Github PK
View Code? Open in Web Editor NEWDroneKit-Python library for communicating with Drones via MAVLink.
Home Page: https://readthedocs.org/projects/dronekit-python/
License: Apache License 2.0
DroneKit-Python library for communicating with Drones via MAVLink.
Home Page: https://readthedocs.org/projects/dronekit-python/
License: Apache License 2.0
http://python.dronekit.io/getting_started.html
http://python.dronekit.io/first_app.html
Tidy heading levels
http://python.dronekit.io/example_1.html
http://python.dronekit.io/example_2.html
http://python.dronekit.io/example_3.html
http://python.dronekit.io/example_4.html
The API contains a number of APIs that are not fully implemented, and may never be. We do not intend people to use them at the current time. They are however publically visible and currently documented.
IN addition there are APIs that are internal in that we don't expect people to call them (please confirm)
@mrpollo , is that a good set of items to hide/remove?
Obviously it is best that these are either fully implemented and so are usuable or are removed from the public API. In the meantime I propose:
:exclude-members: Mission, get_mission, ConnectionInfo, web_connect, AuthInfo, notify_observers
Note: This does not apply to "deprecated" APIs. APIs that might have been used by developers in the past need to be tagged as deprecated.
Thoughts?
@eliao asks if we can support MAV_CMD_DO_CHANGE_SPEED
This seems unexpected to me.
eg, If I call:
vehicle.add_attribute_observer('mode', mode_callback)
mode_callback is called with 'mode' as a parameter. I would expect to be passed the value of vehicle.mode. I'm not sure why I would want the name of the attribute, as I already know the name.
Perhaps the intention is for a single callback to handle multiple attributes? That seems odd to me, and the API does not enforce such a construct.
README.md indicates direct contact of Kevin. Suggest we modify it so that bugs and feedback go to issues list, and technical questions go to stack overflow. OK?
http://python.dronekit.io/getting_started.html
[Update: This fixed by https://github.com/diydrones/dronekit-python/commit/4054edf65abd2f2ae24d0e02f7890e07a54728ca]
Also we talk about installing dronekit on windows and MAC, and I find this confusing because we have SITL running on the VM. We need to make it clear where dronekit runs and how it fits with SITL simulation/MAVLINK.
Consider 2 options: a) putting the "dependencies" under a common heading. OR b) have an end to end topic "Setting up DroneKit on Linux" and then have separate sections covering setting up on Windows/Mac. These can just say "it's the same, but instead you need to do X, Y, Z"
Remove unnecessary code from examples to make them clean and clear (including the commented out code like "Test custom commands".
https://github.com/diydrones/dronekit-python/blob/master/example/small_demo/small_demo.py#L47
We should have a separate guide and reference on custom commands that uses this.
Note, no need to remove from perf_test.py as this is test rather than example code
localConnect and webConnect do not appear in the public API reference. I think they should - because they are what you use to get a hold of the APIConnection, and from this everything else.
@mrpollo Can you tell me what should / shouldn't be documented from this file - ie what is "private"?
Jaime Machuca: great, I think I missed that step on the tutorial. So now I have it running. But the example get stuck when trying to download the waypoints.
According to @tridge overriding channels is intended for simulating user input (ie in autotest) or for implementing joystick behaviour. It should not be used to directly drive a vehicle, except as a last resort. Instead the appropriate mavlink commands should be used.
The following examples set the channel_override in a way that we would not recommend:
https://github.com/diydrones/dronekit-python/blob/master/example/simple_goto/simple_goto.py#L26
I propose that we:
1 - the "check_home()" code that just confirms "home has been initialised", and
2 - the fact that in randy's code there is 4 different places where he has to "download the vehicle waypoints if we don't have them already" , presumably, "just to be sure"...?
3 - the send_nav_velocity() and condition_yaw() functions which would be convenient helper function/s in the drone.api directly. ... and probably the advance_current_cmd() function too... none of them are specific to the balloon thing in any way, and are clearly good-looking helper-apps to simplify the api or wrapper-up some common messages into something more human. :-)
4 - the move_to_balloon() , which should really be called move_to_position(), as that's what it does ( it contrains speed, and determines vector/s, and then calls send_nav_velocity() for the mavlink itself....
none of this is "balloon" code, it's really just convenience wrappers around the api....
Thoughts?
[5:49:46 PM] Kevin Hester: @buzz - I totally agree about 1, 3 & 4 (and will copy-paste this into a github so I don't forget)
[5:50:20 PM] Kevin Hester: 2 is probably just due to this being a 'rough'
Just toggle between the two sites and you can see the logo move to the left. The Android alignment looks better to me. I am assigning this as a python issue since both sites are built off the same theme.
The getting started section of the docs has a number of problems:
When I try to set a parameter (for example RC1_TRIM) in my python script I receive the following message after a 2 second delay:
timeout setting RC1_TRIM to 1500.000000
However, when I check the value in MAVProxy the value has been set correctly. I found that this message is generated by mavset() in mavparm.py in pymavlink, so perhaps it is a bug there. For now I have commented out these lines (24-35) in mavparm.py to avoid having to wait 2 seconds for each parameter set.
Follow me & Hello world example links appears broken. I cannot view the examples.
from drone-platform:
Lastly, I was just wondering if you were going to implement the "set_mavlink_callback" method? I am not sure exactly why but my boss says that is something that he is looking for. I wish I had more information for you but all I know is that he says it is necessary for the project.
Yes, oops - I hadn't noticed that we had missed that one. Yes - I'll add that tomorrow and push out a new release. Also it is worth noting that all of the attributes on vehicle, waypoints, parameters etc... support callbacks which might be a better way to go. (see documentation for add_attribute_observer). What mavlink packets were you needing to watch for? I just want to make sure we didn't miss anything that really should be in the common (web enabled) interface instead.
Thanks for you time and all of the amazing effort you have put in on this project!
Currently we don't have a central place for non-technical material that explains what the project is about and how it can be used, and how developers can engage with it more closely (contribute) - though some of this material is spread throughout the sidebar.
The requirement is to group all the introductory material about what the API offers, contributing, licencing, supported companion computers, FAQ etc into one section.
https://github.com/diydrones/droneapi-python/issues/new#fullscreen_issue_body
After following instructions here: http://dev.ardupilot.com/wiki/droneapi-tutorial/
I've tried a test with (1) APM <> Raspbian.
--I am able to run 'module load droneapi.module.api'
--When I run 'api start small_demo.py' it seems to work (get 'ARMED' commands and other) but I get the following error message. Any ideas what might be causing the error?
reported via email:
Is there a way to call DroneAPI without the interactive MavProxy ?
I have MavProxy running in the background and the droneapi.module loaded:
screen -d -m -s /bin/bash mavproxy.py --master=/dev/ttyAMA0 --baudrate 57600 --aircraft OCTO8 --out=127.0.0.1:12345 --cmd="module load droneapi.module.api;" > /tmp/rc.log 2>&1
If I execute small_demo.py outside of interactive MavProxy it fails on this line:
api = local_connect()
I assume that the function would find my local running copy but I guess that is a wrong assumption?
Of course it runs fine inside the interactive MavProxy but only after it completes loading ….. so I can’t use the “api start” as a parameter.
Thanks
http://python.dronekit.io/automodule.html
Lots of "FIXME" markup and comments like "This idea is from @rmackay9 - thanks"
These should be closed/removed. If there are some that can be hidden, this can be done using the appropriate sphinx markup (ie you can actually mark sections to build only in a debug build, and in that same build have a table showing the open issues).
This file is autogenerated, but not linked from anywhere http://python.dronekit.io/genindex.html
How useful is it? Should it be in the sidebar?
Is it possible to have command line arguments for calling a script using api start?
Example "api start SmartCamera.py land -c 0"
When run I get "usage: api load "
Also when I run my script(without arguments), my script has problems completing imports. However, my script is able to complete imports when I run it normally(not with droneapi). Note: even if the script did complete imports it would crash due to lack of arguments.
I don't think I'm fully understanding the usage.
If it is helpful my program can be seen at github.com/djnugent/SmartCamera
Thanks,
Daniel
Remove the comment on this line in small_demo.py to re-enable the mode.
So the code has
def mode_callback(attribute):
print "Mode changed: ", v.mode
v.add_attribute_observer('mode', mode_callback)
When executed, the code runs. After the thread exits the mavproxy command prompt prints out the mode forever as shown below. This is a bug of some sort right?
AUTO>
AUTO> module load droneapi.module.api
AUTO> api start small_demo.py
AUTO> Mode: VehicleMode:AUTO
Location: Location:lat=-35.3632603,lon=149.1652287,alt=0.0,is_relative=False
Attitude: Attitude:pitch=0.00512621784583,yaw=-0.0500796176493,roll=0.00491848401725
Velocity: [-0.08, 0.08, 0.0]
GPS: GPSInfo:fix=3,num_sat=10
Armed: False
groundspeed: 0.0
airspeed: 0.0
Requesting 95 waypoints t=Wed Apr 29 14:56:15 2015 now=Wed Apr 29 14:56:15 2015
Home WP: MISSION_ITEM {target_system : 255, target_component : 0, seq : 0, frame : 0, command : 16, current : 0, autocontinue : 1, param1 : 0.0, param2 : 0.0, param3 : 0.0, param4 : 0.0, x : -35.3632621765, y : 149.165237427, z : 584.090026855}
Current dest: 1
Disarming...
Arming...
Overriding a RC channel
Current overrides are: {'1': 900, '4': 1000}
RC readback: {'1': 1500, '3': 1000, '2': 1500, '5': 1800, '4': 1500, '7': 1000, '6': 1000, '8': Got MAVLink msg: COMMAND_ACK {command : 400, result : 0}
1800}
Cancelling override
APM: Arm: Mode not armable
APIThread-0 exiting...
Got MAVLink msg: COMMAND_ACK {command : 400, result : 4}
Got MAVLink msg: COMMAND_ACK {command : 11, result : 0}
Mode changed X: VehicleMode:AUTO
Mode changed X: VehicleMode:AUTO
Mode changed X: VehicleMode:AUTO
Mode changed X: VehicleMode:AUTO
Mode changed X: VehicleMode:AUTO
Mode changed X: VehicleMode:AUTO
Mode changed X: VehicleMode:AUTO
Mode changed X: VehicleMode:AUTO
Mode changed X: VehicleMode:AUTO
Mode changed X: VehicleMode:AUTO
Mode changed X: VehicleMode:AUTO
...
It'd be nice to have ROI helpers, rather than using mavlink commands to set them.
http://python.dronekit.io/ (index.rst)
The text in the first paragraph might be improved:
DroneKit-Python provides interfaces for creating applications that run on an onboard Linux computer communicating directly to the autopilot of 3DR-powered vehicles or applications that run on a personal computer communicating with vehicles over a wireless connection.
It does talk about the fact that the API can be used on Linux computer and on ground stations (good). The problems are that it:
Hi Kevin,
Our team was able to run the follow_me.py example without debugging errors in two different ways. The first way we ran it, was exactly as the follow_me.py was written, and the second way was hardcoding one GPS coordinate in the Location function. However, in both cases we received the proper debugging output but the motors did not move.
The first way we ran it, was exactly as the follow_me.py was written. Our GPS USB dongle was providing GPS coordinates every two seconds, those coordinates were displayed, and the output showed “Got MAVLink msg: MISSION_ACK... etc.
The second way we ran it was with all the gpsd functions commented out and by hard-coding one GPS coordinate in the Location function.
After educating ourselves on your API, we believe that we have narrowed down the problem to being the goto function does not end up forcing the drone to move the motors.
Do you have any thoughts on why this could be happening.
We speculate that the problem may be that the drone is going into Guided mode. We believe that this is your intent. However, from our understanding, the drone will only go to locations autonomously in AUTO mode and only after the waypoints are saved and an rc command starts the motors.
Again, we do not fully understand what is wrong and why the command itself seems to be received by the APM, but the motors are not moving.
Again, we are able to get small_demo.py to move the motors properly, so we know it is not a problem with our wiring or our connection between the APM and our Raspberry Pi.
Any help is appreciated,
Thanks!
Received the "AttributeError: 'MPStatus' object has no attribute 'target_system'" error when attempting to send a mavlink msg.
In api.py:392, neither self.mpstate.status or self.mpstate.settings had the target_system or target_component attributes set.
Details of setup, error, and .mavinit.scr follow below.
SITL
$ sim_vehicle.sh --console --map --aircraft test --out=$IP_ADDRESS:$PORT
MAVProxy
$ mavproxy.py --master=$IP_ADDRESS:$PORT
Exception in APIThread-0: 'MPStatus' object has no attribute 'target_system'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/droneapi/module/api.py", line 322, in run
self.fn()
File "/usr/local/lib/python2.7/dist-packages/droneapi/module/api.py", line 599, in
APIThread(self, lambda: execfile(args[1], g), args[1])
File "/home/igor/test_app/main.py", line 13, in
online system 1
AUTO> Mode AUTO
mgr.Start(api)
File "/home/igor/test_app/manager.py", line 94, in Start
self.enableFoo()
File "/home/igor/test_app/manager.py", line 392, in enableFoo
self.vehicle.send_mavlink(msg)
File "/usr/local/lib/python2.7/dist-packages/droneapi/module/api.py", line 244, in send_mavlink
self.__module.fix_targets(message)
File "/usr/local/lib/python2.7/dist-packages/droneapi/module/api.py", line 392, in fix_targets
message.target_system = status.target_system
AttributeError: 'MPStatus' object has no attribute 'target_system'
module load droneapi.module.api
module unload terrain
module unload log
module unload battery
module unload fence
module unload rally
module unload calibration
module unload relay
module unload misc
module unload rc
api start /home/igor/test_app/main.py
I can't seem to get a simple CherryPy Server working with DroneKit. The code below works fine when I execute it out of mavproxy using python drone.py
but when I enter mavproxy and execute it using api start drone.py
, none of the CherryPy debug messages appear and I just get "STABILIZE> APIThread-0 exiting..."
#drone.py
import cherrypy
class HelloWorld(object):
@cherrypy.expose
def index(self):
return "Hello world!"
if __name__ == '__main__':
cherrypy.quickstart(HelloWorld())
I'm trying this on a RaspberryPi2 and the 'drone delivery" demo which also uses CherryPy works on it.
USB camera and other cameras support for companion computers. Potentially allowing developer to access live stream over LTE from the drone. Roadmap to create "periscope" like app for drones.
The Flight Replay example sets waypoints using mavutil.mavlink.MAVLink_mission_item_message directly. As I understand the API the correct type for a command in this API is "Command" (which is not even imported)
cmd = mavutil.mavlink.MAVLink_mission_item_message(0,
0,
0,
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
0, 0, 0, 0, 0, 0,
lat, lon, altitude)
cmds.add(cmd)
To fix this I believe the change is trivial, because the Command is just a thin wrapper around MAVLink_mission_item_message
from droneapi.lib import VehicleMode, Command
...
cmd = Command(0,
0,
0,
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
0, 0, 0, 0, 0, 0,
lat, lon, altitude)
cmds.add(cmd)
we need to update it with the right link
Propose add http://planner.ardupilot.com/wiki/other-project-and-common-topics/common-autopilots/common-erle-brain-linux-autopilot/ to http://python.dronekit.io/getting_started.html#supported-companion-computers under "Beaglebone Black" section.
This is an all-in-one package autopilot and companion computer - and as you will note has instructions and back links to our docs. I think it is quite important in that it is an "out of the box" solution for experimentation. I think I want one :-)
Agreed?
This might be useful for filtering the docs requests. I don't know how to add these.
I've just started working with this api and so far it seems straight forward but I've been having some weird issues that might not be api problems specifically but not sure where else to ask about them. I'm running Yosemite on a macbook pro as fyi.
The issue is, I will run my script via the USB cable directly ( ex. mavproxy.py --master=/dev/cu.usbmodem1 --cmd="api start spray.py") it works like it should but if I connect via the usb radio adapter (ex. mavproxy.py --master=/dev/cu.usbserial-DN00B8MP --cmd="api start spray.py") then the api hangs anytime I change modes (ex. from GUIDED to ALT_HOLD) and I just see a MAV> console input
Is there a mechanism to support Rally Points?
These are not MAV_CMDs, and so it might be that there is no proper support for them through Command and CommandSequence.
They are created using MAVLINK_MSG_ID_RALLY_POINT
We should make it easier for people to get started with contributing to the documents. The good news is that sphinx_3dr_theme can now be updated from pip, so it is now possible to set up sphinx and build the source without having to modify any files (previously you needed to modify the conf file in order to replace the theme).
I've written a vagrant script that does this. The proposal is to put this in /docs/ alongside the .rst files. The (windows) workflow would be:
vagrant ssh -c "cd /vagrant && make html"
Is this approach desirable? Is the location of the vagrantfile in docs OK? (I think it is, but just checking).
In addition, I propose to update README.md to add information about how to contribute (specifically to the docs, but more generally it would be useful to cover how people can join the project?).
I would do this by adding a new heading "Contributing" near the end with a link "Contributing to the Documentation". That doc would explain how to use the vagrant file etc.
OK?
The current API Reference is built from droneapi.lib module by Sphinx, which pulls it from comments in /droneapi/module/api.py and droneapi/lib/init.py. I've done a bit of a comparison of what is in the files and what is documented and have some suggestions:
Documentation in init refers to objects as "base class" and has comments like "implemented in subclass". This is useful for a developer, but confusing for a user. If the base class is an interface, then it should just say what the interface does.
HW I have updated these cases in the source so they are marked as "Internal notes"
Attributes of Vehicle are documented in a table in the interface class. It would be better if these were part of the public "imported" API.
HW I have updated these cases in the source using py:attribute markup. However it would be better if these were "properly" in the public API.
The Linux Dependencies here for pip are incorrect:
sudo apt-get install pip python-numpy python-opencv python-serial python-pyparsing python-wxgtk2.8
this should be "python-pip"
This seems odd to me, particularly because they are labeled "__on_change".
eg: if I do a
vehicle.add_attribute_observer('mode', mode_callback)
mode_callback is called every heartbeat, regardless of mode change.
There is no implementation for battery_0_soc and battery_0_volt. Please provide implementation and information about what parameters these map to on ardupilot (basically I need to know their "meaning" and possible values and units - so for example "Remaining capacity of the first battery in X units"
It is possible for a UAV to have multiple batteries, and two are specified in the parameters. This implies that there should actually be multiple values for these, or a way to index them.
I verified the lack of these parameters by inspection and testing. To test, I added the following lines to small_demo.py:
print "battery_0_soc: %s" % v.battery_0_soc
print "battery_0_volt: %s" % v.battery_0_volt
And got the exception:
Exception in APIThread-2: 'MPVehicle' object has no attribute 'battery_0_soc'
Traceback (most recent call last):
File "C:\Users\hamis_000\Downloads\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\droneapi\module\api.py", line 321, in run
self.fn()
File "C:\Users\hamis_000\Downloads\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\droneapi\module\api.py", line 592, in <lambda>
APIThread(self, lambda: execfile(args[1], g), args[1])
File "small_demo.py", line 32, in <module>
print "battery_0_soc: %s" % v.battery_0_soc
AttributeError: 'MPVehicle' object has no attribute 'battery_0_soc'
The Command object is, I believe, a thin wrapper around a mavutil.mavlink.MAVLink_mission_item_message. It allows you to create a command object like this:
cmd = Command(0,
0,
0,
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
0, 0, 0, 0, 0, 0,
lat, lon, altitude)
cmds.add(cmd)
The values of the parameters are the same as the mavutil.mavlink.MAVLink_mission_item_message and I believe this to be a bug.
The problem is that I don't believe that most of these can or should be set by the user. It may be that they are already correctly set by the system, but IMO they should also be hidden. If we can't hide them we need to clearly state what values can be set, and this is not documented anywhere!
Specifically
So in summary, lets hide target_system, target_component, seq, current, autocontinue from the API.
It looks like updating the name from droneapi-python to dronekit-python may have messed up the gh-pages hosting. I am get a 404 not found message when I try to access the autodocs at either http://diydrones.github.io/droneapi-python/ or http://diydrones.github.io/dronekit-python/ even though the gh-pages branch seems to look ok.
This title is meaningless, and could apply to any of our docs in the kit :-)
This would be much better as "DroneKit Python API Reference". OK?
test-upload.py shows how to upload a file to a service with the Cloud (REST) API, using Python. IMO that makes it something that belongs in the cloud example code, NOT in the dronekit-python example code.
When you've created a place for the cloud docs and issues, I'll move this across (assuming you agree)
Hi,
Mavlink allows you to set a group of waypoints to be executed by AUTO mode by using the "set waypointfile.txt" command.
Have you created a function that emulates the "set" command so that waypoints can be saved to the drone? I looked extensively in your documentation and I have not found anything that resembles this command.
I did notice that in small_demo.py you have access to the waypoints that are already set using cmds[x] structure:
cmds = v.commands
cmds.download()
cmds.wait_valid()
print "Home WP: %s" % cmds[0]
print "Current dest: %s" % cmds.next
However, you cannot save to the cmds[x] structure, you have only given access to printing the contents (at least as far as my experimentation has shown me).
If there is not such a function in droneapi yet, would you please make one? I do not mind making the text file if you could make some sort of function that "sets" the text file as the waypoints. However, It would be even more nice if you had a way to just "set" waypoints into the AUTO mode list using some sort of structure.
Thanks,
Stephen
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.