From 0dffc61048babfe0fb213f9feb0b09935f50aa4c Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Wed, 23 Sep 2015 17:02:17 +1000 Subject: [PATCH 1/4] DKPY2 fixes to getting started, running examples, and developer setup windows. Consequent fixups to links elsewhere --- docs/about/license.rst | 2 +- docs/about/overview.rst | 2 +- docs/contributing/developer_setup_windows.rst | 52 +---- docs/examples/running_examples.rst | 54 ++---- docs/guide/getting_started.rst | 181 ++++++++---------- docs/guide/migrating.rst | 20 +- docs/guide/sitl_setup.rst | 2 +- docs/guide/vehicle_state_and_parameters.rst | 2 +- examples/vehicle_state/vehicle_state.py | 3 - 9 files changed, 117 insertions(+), 201 deletions(-) diff --git a/docs/about/license.rst b/docs/about/license.rst index a7b95cc12..1fe406e2d 100644 --- a/docs/about/license.rst +++ b/docs/about/license.rst @@ -2,7 +2,7 @@ Open Source Licence ======================= -DroneKit-Python is licensed under the *Apache License Version 2.0, January 2004 (http://www.apache.org/licenses/). This is present in the `LICENSE `_ file in the source tree, and reproduced below: +DroneKit-Python is licensed under the *Apache License Version 2.0, January 2004* (http://www.apache.org/licenses/). This is present in the `LICENSE `_ file in the source tree, and reproduced below: .. include:: ../../LICENSE :literal: \ No newline at end of file diff --git a/docs/about/overview.rst b/docs/about/overview.rst index f0221b13f..f9372f8a2 100644 --- a/docs/about/overview.rst +++ b/docs/about/overview.rst @@ -13,7 +13,7 @@ Open source community DroneKit-Python is an open source and community-driven project. You can find all the source code on `Github here `_ and check out our permissive :doc:`Apache v2 Licence `. -If you want to join the community, then see our :doc:`contributing section ` for lots of ideas on how you can help. +If you want to join the community, then see our :doc:`contributing section <../contributing/index>` for lots of ideas on how you can help. Compatibility diff --git a/docs/contributing/developer_setup_windows.rst b/docs/contributing/developer_setup_windows.rst index 81d7e90b1..494775d0c 100644 --- a/docs/contributing/developer_setup_windows.rst +++ b/docs/contributing/developer_setup_windows.rst @@ -6,60 +6,12 @@ Building DroneKit-Python on Windows This article shows how to set up an environment for *developing* DroneKit-Python on Windows. -.. tip:: - - If you just want to *use* DroneKit-Python on Windows then easiest way to get started is to use the - :ref:`Windows Installer <_get_started_install_dk_windows>`. The installer is rebuilt with every patch - release, so you can always be up to date with the latest features and bug fixes. - Install DroneKit using WinPython command line ============================================= -First set up a command line DroneKit-Python installation using *WinPython*. This Python distribution already includes most of the needed dependencies (though you will need remove *python-dateutil* as the installation comes bundled with a version that does not work with *DroneKit*). - -The steps to install this package and the most important add-on modules are: - -#. Download and run the correct `WinPython installer `_ (**v2.7**) for your platform (win32 vs win64). - - * Run the installer as an administrator (**Right-click** on file, select **Run as Administrator**). - * When prompted for the destination location, specify **C:\Program Files (x86)** - (the default location is under the **Downloads** folder). - -#. Register the Python that came from *WinPython* as the preferred interpreter for your machine: - Open the folder where you installed WinPython, run *WinPython Control Panel* and choose **Advanced/Register Distribution**. - - .. image:: http://dev.ardupilot.com/wp-content/uploads/sites/6/2014/03/Screenshot-from-2014-09-03-083816.png - -#. Install DroneKit-Python and its remaining dependencies (including `MAVProxy `_) from the public PyPi repository: - - Open the *WinPython Command Prompt* and run the following two commands: - - .. code:: bash - - pip uninstall python-dateutil - pip install dronekit - -The dependencies above are all that are required to build DroneKit-Python and the *MAVProxy command line* (i.e. the minimum needed for testing). -If you also want the *MAVProxy console* and map install: - -#. OpenCV - - * `Download and install OpenCV version 2.4 for Windows `_ (this can be extracted anywhere) - * Copy/paste the file :file:`cv2.pyd` from :file:`OpenCV\\build\\python\\2.7\\x64\\` to :file:`site_packages` - on your Python installation (e.g. :file:`\\python-2.7.6.amd64\\Lib\\site-packages`). -#. WxPython - - * `Download and install WxPython `_. Make sure the target - path is your WinPython installation. -#. Console - - * Open the WinPython command prompt and enter: - - .. code:: bash - - pip install console +First set up a command line DroneKit-Python installation using *WinPython*. This process is the same as described in :ref:`Getting Started `. @@ -78,7 +30,7 @@ Fetch and build DroneKit source python setup.py install - + Updating DroneKit ================= diff --git a/docs/examples/running_examples.rst b/docs/examples/running_examples.rst index 7bfd2e898..2989bb3b4 100644 --- a/docs/examples/running_examples.rst +++ b/docs/examples/running_examples.rst @@ -4,8 +4,11 @@ Running the Examples ==================== -General instructions for running the example source code are given below (more explicit instructions may be -provided in the documentation for each example): +General instructions for running the `example source code `_ are given below. + +.. tip:: + + More explicit instructions may be provided within the documentation for each example, and on the command line using the ``-h`` (help) parameter. #. Get the DroneKit-Python example source code onto your local machine. The easiest way to do this is to clone the **dronekit-python** repository from Github. On the command prompt enter: @@ -14,49 +17,30 @@ provided in the documentation for each example): git clone http://github.com/dronekit/dronekit-python.git - .. tip:: - - The :ref:`Windows Installation ` copies the example code here: - :file:`C:\\Program Files (x86)\\MAVProxy\\examples\\`. - -#. Start MAVProxy and :ref:`connect to the vehicle `. For example: - - * To connect to a simulated vehicle when starting *MAVProxy* (from the command line): - - .. code-block:: bash - - mavproxy.py --master=127.0.0.1:14550 - * To connect to a simulated vehicle after starting MAVProxy (for example, on Windows): - - .. code-block:: bash - - link add 127.0.0.1:14550 - -#. You should already have set up *MAVProxy* to :ref:`load DroneKit automatically `. - If not, manually load the library using: + +#. Navigate to the example you wish to run (or specify the full path in the next step). The examples are all stored in + subdirectories of **dronekit-python\\examples\\**. + + To run the :ref:`vehicle_state ` example, you would navigate as shown: .. code-block:: bash - module load dronekit.module.api - -#. Once the *MAVProxy* console is running, start the example by entering: + cd dronekit-python\examples\vehicle_state\ - .. code-block:: bash - api start absolute_path_to_example/example_name.py - - .. tip:: +#. Start the example, passing the :ref:`connection string ` you wish to use in the ``--connect`` parameter: - If you start *MAVProxy* from the same directory as the target script you can omit - the full file path: + .. code-block:: bash - .. code-block:: bash + python vehicle_state.py --connect 127.0.0.1:14550 - api start example_name.py - + .. note:: + + The examples all use the ``--connect`` parameter to pass the :ref:`connection string ` into the script. + The command above would be used to connect to :ref:`SITL ` running on the local machine via UDP port 14550. + .. warning:: Propellers should be removed before testing examples indoors (on real vehicles). - diff --git a/docs/guide/getting_started.rst b/docs/guide/getting_started.rst index 349c748ec..1cd97adf9 100644 --- a/docs/guide/getting_started.rst +++ b/docs/guide/getting_started.rst @@ -9,9 +9,8 @@ on the vehicle and communicate with the autopilot via a serial port. However, du prototype apps on a standard Mac, Windows, or Linux computer using a *simulated* autopilot. -This topic explains how to set up and run DroneKit-Python (within MAVProxy) on the different host operating systems -and then run a basic DroneKit app. - +This topic explains how to set up and run DroneKit-Python on the different host operating systems +and then create and run a basic DroneKit app. @@ -21,7 +20,7 @@ Setting up the vehicle/autopilot For information on how to set up a vehicle (real and simulated) see: * :ref:`supported-companion-computers` for links to tested hardware/software configurations for a number of onboard Linux computers. -* :ref:`sitle_setup` for links explaining how to set up a simulated vehicle for Copter, Plane, or Rover. +* :ref:`sitl_setup` for links explaining how to set up a simulated vehicle for Copter, Plane, or Rover. @@ -40,11 +39,10 @@ If you are using Ubuntu or Debian Linux you can get most of the *DroneKit* depen .. code:: bash - sudo apt-get install python-pip python-dev python-opencv python-serial python-pyparsing python-wxgtk2.8 + sudo apt-get install python-pip python-dev -The remaining dependencies (including `MAVProxy `_), are -installed when you get DroneKit-Python from the public PyPi repository: +The remaining dependencies are installed when you get DroneKit-Python from the public PyPi repository: .. code:: bash @@ -61,151 +59,129 @@ installed when you get DroneKit-Python from the public PyPi repository: Installing DroneKit on Mac OSX ------------------------------ -If you're on Mac OSX, you can use `Homebrew `_ to install *WXMac*. +Install DroneKit-Python and its dependencies from the public PyPi repository: .. code:: bash - brew tap homebrew/science - brew install wxmac wxpython opencv - + sudo pip install droneapi numpy + -Uninstall *python-dateutil* (OSX and Windows come bundled with a version that is not supported for some dependencies): -.. code:: bash - - sudo pip uninstall python-dateutil +.. _get_started_install_dk_windows: -Install DroneKit-Python and its remaining dependencies (including `MAVProxy `_) from the public PyPi repository: +Installing DroneKit on Windows +------------------------------ -.. code:: bash +Set up a command line DroneKit-Python installation using *WinPython* (this Python distribution already includes most of the needed dependencies). +<<<<<<< HEAD sudo pip install pyparsing sudo pip install dronekit +======= +#. Download and run the correct `WinPython installer `_ (**v2.7**) for your platform (win32 vs win64). + + * Run the installer as an administrator (**Right-click** on file, select **Run as Administrator**). + * When prompted for the destination location, specify **C:\\Program Files (x86)** + (the default location is under the **Downloads** folder). +>>>>>>> DKPY2 fixes to getting started, running examples, and developer setup windows. Consequent fixups to links elsewhere +#. Register the Python that came from *WinPython* as the preferred interpreter for your machine: -.. _get_started_install_dk_windows: + Open the folder where you installed WinPython, run *WinPython Control Panel* and choose **Advanced/Register Distribution**. -Installing DroneKit on Windows ------------------------------- + .. image:: http://dev.ardupilot.com/wp-content/uploads/sites/6/2014/03/Screenshot-from-2014-09-03-083816.png -The easiest way to set up DroneKit-Python on Windows is to use the Windows Installer. -This is applied over the top of the *MAVProxy* Windows installation and includes all needed -dependencies and the DroneKit-Python examples. +#. Install DroneKit-Python and its remaining dependencies from the public PyPi repository: -.. tip:: + Open the *WinPython Command Prompt* and run the following command: - A new version of the Windows Installer is created with every patch revision (`get old versions - here `_). - Don't forget to update regularly for bug fixes and new features! - -To install DroneKit-Python using the installer: + .. code:: bash -#. Download and run the `latest MAVProxy installer `_ - — accept all prompts. -#. Download and run the `latest DroneKit installer `_ - — accept all prompts (install in the same location as MAVProxy). + pip install droneapi -The installer packages DroneKit-Python as an application, which is launched by double-clicking an icon -in the system GUI. After the *MAVProxy prompt* and *console* have started you can -:ref:`connect to the vehicle ` (instead of setting the -connection when starting *MAVProxy*). You will still need to :ref:`load DroneKit ` (not done by the installer -- see `#267 `_). The examples are copied to :file:`C:\\Program Files (x86)\\MAVProxy\\examples\\`. + + +.. _get_started_connect_string: -It is also possible to set up DroneKit-Python on the command line (see :ref:`dronekit_development_windows`). +.. _get_started_connecting: +Connecting to a Vehicle +======================= -.. _starting-mavproxy: +The connection to the vehicle is set up within the DroneKit script. Scripts import and call the :py:func:`connect()` method. +After connecting this returns a :py:class:`Vehicle ` object from which you can get/set parameters +and attributes, and control vehicle movement. -Starting MAVProxy -================= +.. code:: python -Before executing DroneKit scripts you must first start *MAVProxy* and connect to your autopilot (simulated or real). -The connection to the vehicle can be set up on the command line when starting *MAVProxy* or after MAVProxy is running. + from droneapi import connect + + # Connect to UDP endpoint. + vehicle = connect('127.0.0.1:14550', await_params=True) + +.. note:: -.. tip:: + Calling ``connect()`` with ``await_params=True`` (as shown above) ensures that the method will not return until + :py:attr:`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, + if the attribute is not supported by the vehicle). - If you're using DroneKit-Python from the Windows installer there is no way to pass command line options to MAVProxy; - you will have to start MAVProxy by double-clicking its icon and then :ref:`connect to the target vehicle after MAVProxy - has started `. +The example above connects to the udp address ``127.0.0.1:14550``. The table below shows addresses to use some of +the more common connection types: -Connecting at startup ---------------------- -The table below shows the command lines used to start *MAVProxy* for the respective connection types: -.. list-table:: MAVProxy connection options +.. list-table:: Connection string options :widths: 10 10 :header-rows: 1 * - Connection type - - MAVProxy command + - Connection string * - Linux computer connected to the vehicle via USB - - ``mavproxy.py --master=/dev/ttyUSB0`` + - ``/dev/ttyUSB0`` * - Linux computer connected to the vehicle via Serial port (RaspberryPi example) - - ``mavproxy.py --master=/dev/ttyAMA0 --baudrate 57600`` + - ``/dev/ttyAMA0 --baudrate 57600`` * - SITL connected to the vehicle via UDP - - ``mavproxy.py --master=127.0.0.1:14550`` + - ``127.0.0.1:14550`` * - OSX computer connected to the vehicle via USB - - ``mavproxy.py --master=/dev/cu.usbmodem1`` + - ``dev/cu.usbmodem1`` * - Windows computer connected to the vehicle via USB - - ``mavproxy.py --master=/dev/cu.usbmodem1`` - -For other connection options see the `MAVProxy documentation `_. + - ``/dev/cu.usbmodem1`` -.. _starting-mavproxy_set_link_when_mavproxy_running: - -Connecting after startup ------------------------- - -To connect to the autopilot once *MAVProxy* has already started use ``link add `` in the *MAVProxy command prompt*, where ```` -takes the same values as ``master`` in the table above. For example, to set up a connection to SITL running on the local computer at port 14550 do: - -.. code:: bash - - link add 127.0.0.1:14550 - -If you're connecting using a serial port you may need to first set up the baud rate first (the default is 57600). You can change the default baudrate used for -new connections as shown: - -.. code:: bash - - set baudrate 57600 #Set the default baud rate for new connections (do before calling "link add") - -See `Link Management `_ (MAVProxy documentation) for more information. - - - - -.. _loading-dronekit: - -Loading DroneKit -================ - -*DroneKit* is implemented as a *MAVProxy* module (MAVProxy is installed automatically with DroneKit). -The best way to load the *DroneKit* module into *MAVProxy* is to -`add it to the startup script `_ (**mavinit.scr**). - -Linux/MAC OSX: - -.. code:: bash +.. tip:: +<<<<<<< HEAD echo "module load dronekit.module.api" >> ~/.mavinit.scr +======= + The strings above are the same as you would use if connecting with MAVProxy. For other options see the + `MAVProxy documentation `_. +>>>>>>> DKPY2 fixes to getting started, running examples, and developer setup windows. Consequent fixups to links elsewhere -Windows: + +You can start this simple script in the same way you would start any other standalone Python script. -.. code:: bash +.. code-block:: bash +<<<<<<< HEAD echo module load dronekit.module.api >> %HOMEPATH%\AppData\Local\MAVProxy\mavinit.scr +======= + python your_dronekit_script.py +>>>>>>> DKPY2 fixes to getting started, running examples, and developer setup windows. Consequent fixups to links elsewhere -Alternatively you can choose to manually (re)load *DroneKit* into *MAVProxy* every time you need it: +<<<<<<< HEAD .. code-block:: bash :emphasize-lines: 1 MANUAL> module load dronekit.module.api DroneAPI loaded MANUAL> +======= +.. todo:: Connect method here needs to link to the function, but it isn't exported yet. Fix that once the API tidied. + +>>>>>>> DKPY2 fixes to getting started, running examples, and developer setup windows. Consequent fixups to links elsewhere @@ -214,6 +190,7 @@ Alternatively you can choose to manually (re)load *DroneKit* into *MAVProxy* eve Running an app/example ====================== +<<<<<<< HEAD This section shows how to run the :ref:`Vehicle State ` example, which reads and writes :ref:`vehicle state and parameter ` information. @@ -289,5 +266,9 @@ The steps are: Got MAVLink msg: COMMAND_ACK {command : 11, result : 0} ... +======= +This SDK has :ref:`numerous examples `. We recommend you start with :ref:`example-vehicle-state`, +which reads and writes :ref:`vehicle state and parameter ` information. +>>>>>>> DKPY2 fixes to getting started, running examples, and developer setup windows. Consequent fixups to links elsewhere -For more information on running the examples (and other apps) see :ref:`running_examples_top`. +For general information on running the examples (and other apps) see :ref:`running_examples_top`. diff --git a/docs/guide/migrating.rst b/docs/guide/migrating.rst index fca08b729..2af1ec245 100644 --- a/docs/guide/migrating.rst +++ b/docs/guide/migrating.rst @@ -52,20 +52,22 @@ You must specify the target vehicle address in your script (in DKPY 1.x this was The code fragment below shows how you import the :py:func:`connect() ` method and use it to return a connected :py:class:`Vehicle ` object. The address string passed to ``connect()`` takes the same -values as were passed to MAVProxy when setting up a connection in DKPY 1.x (in this case, a SITL instance running on the same computer). +values as were passed to *MAVProxy* when setting up a connection in DKPY 1.x (in this case, a SITL instance running on the same computer). .. code:: python from dronekit import connect - # Connect to the Vehicle - vehicle = connect('127.0.0.1:14550') - - # Wait for attributes to accumulate. - time.sleep(5) + # Connect to the Vehicle (in this case a UDP endpoint) + vehicle = connect('127.0.0.1:14550', await_params=True) + + +The ``await_params=True`` parameter ensures that ``connect()`` won't return until +:py:attr:`Vehicle.parameters ` has been populated. +This also allows *MAVLink* messages to arrive from the connected vehicle +and populate other ``Vehicle`` attributes. -The thread is normally suspended for a few seconds after connecting. This allows *MAVLink* messages to arrive from the connected vehicle -and populate the ``Vehicle`` attributes (before they are read). The vehicle can then be used in exactly the same way as in DKPY 1.x. +The vehicle can then be used in exactly the same way as in DKPY 1.x. .. note:: @@ -116,7 +118,7 @@ use whatever method you like. .. note:: In DKPY 1.x the script's ``sys.argv`` values were the values passed to MAVProxy when it was - started. To access arguments passed to the script from *MAVProxy you used the ``local_arguments`` array. + started. To access arguments passed to the script from *MAVProxy* you used the ``local_arguments`` array. For example if you started a script as shown below: .. code:: bash diff --git a/docs/guide/sitl_setup.rst b/docs/guide/sitl_setup.rst index 76cd5d839..a83e4bd5f 100644 --- a/docs/guide/sitl_setup.rst +++ b/docs/guide/sitl_setup.rst @@ -1,4 +1,4 @@ -.. _sitle_setup: +.. _sitl_setup: ===================================== Setting up a Simulated Vehicle (SITL) diff --git a/docs/guide/vehicle_state_and_parameters.rst b/docs/guide/vehicle_state_and_parameters.rst index b0b220d9d..0054ffbd3 100644 --- a/docs/guide/vehicle_state_and_parameters.rst +++ b/docs/guide/vehicle_state_and_parameters.rst @@ -74,7 +74,7 @@ Attributes will also return ``None`` if the associated hardware is not present .. tip:: - If you're using a :ref:`simulated vehicle ` you can add support for optional hardware including + If you're using a :ref:`simulated vehicle ` you can add support for optional hardware including `rangefinders `_ and `optical flow sensors `_. diff --git a/examples/vehicle_state/vehicle_state.py b/examples/vehicle_state/vehicle_state.py index f33eb5228..7f8a9cb41 100644 --- a/examples/vehicle_state/vehicle_state.py +++ b/examples/vehicle_state/vehicle_state.py @@ -23,9 +23,6 @@ print 'Connecting to vehicle on: %s' % args.connect vehicle = connect(args.connect, await_params=True) -# Wait for attribtues to accumulate. -time.sleep(5) - # Get all vehicle attributes (state) print "\nGet all vehicle attribute values:" print " Location: %s" % vehicle.location From 4c6f5d6b6c85453c887d1bd1cd273a99fe19105f Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Wed, 30 Sep 2015 16:35:46 +1000 Subject: [PATCH 2/4] Migrate simple_goto.py --- examples/simple_goto/simple_goto.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/examples/simple_goto/simple_goto.py b/examples/simple_goto/simple_goto.py index fb7caeb49..555935e7e 100644 --- a/examples/simple_goto/simple_goto.py +++ b/examples/simple_goto/simple_goto.py @@ -1,18 +1,30 @@ """ simple_goto.py: GUIDED mode "simple goto" example (Copter Only) -The example demonstrates how to arm and takeoff in Copter and how to navigate to -points using Vehicle.commands.goto. +Demonstrates how to arm and takeoff in Copter and how to navigate to points using Vehicle.commands.goto. Full documentation is provided at http://python.dronekit.io/examples/simple_goto.html """ import time +from dronekit import connect from dronekit.lib import VehicleMode, Location from pymavlink import mavutil +import time + + +#Set up option parsing to get connection string +import argparse +parser = argparse.ArgumentParser(description='Print out vehicle state information. Connects to SITL on local PC by default.') +parser.add_argument('--connect', default='127.0.0.1:14550', + help="vehicle connection target. Default '127.0.0.1:14550'") +args = parser.parse_args() + + +# Connect to the Vehicle +print 'Connecting to vehicle on: %s' % args.connect +vehicle = connect(args.connect, await_params=True) -api = local_connect() -vehicle = api.get_vehicles()[0] def arm_and_takeoff(aTargetAltitude): """ @@ -34,7 +46,7 @@ def arm_and_takeoff(aTargetAltitude): vehicle.armed = True vehicle.flush() - while not vehicle.armed and not api.exit: + while not vehicle.armed: print " Waiting for arming..." time.sleep(1) @@ -44,7 +56,7 @@ def arm_and_takeoff(aTargetAltitude): # Wait until the vehicle reaches a safe height before processing the goto (otherwise the command # after Vehicle.commands.takeoff will execute immediately). - while not api.exit: + while True: print " Altitude: ", vehicle.location.alt if vehicle.location.alt>=aTargetAltitude*0.95: #Just below target, in case of undershoot. print "Reached target altitude" @@ -72,4 +84,4 @@ def arm_and_takeoff(aTargetAltitude): print "Returning to Launch" vehicle.mode = VehicleMode("RTL") -vehicle.flush() \ No newline at end of file +vehicle.flush() From a88acc688a26dfe97db73758a87756012b17e6ea Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Wed, 30 Sep 2015 17:42:27 +1000 Subject: [PATCH 3/4] Migrate guided_set_speed_yaw.py to DKPY2 --- .../guided_set_speed_yaw.py | 25 ++++++++++++++----- examples/guided_set_speed_yaw/readme.md | 3 --- 2 files changed, 19 insertions(+), 9 deletions(-) delete mode 100644 examples/guided_set_speed_yaw/readme.md diff --git a/examples/guided_set_speed_yaw/guided_set_speed_yaw.py b/examples/guided_set_speed_yaw/guided_set_speed_yaw.py index 2729dfc19..ad0134e61 100644 --- a/examples/guided_set_speed_yaw/guided_set_speed_yaw.py +++ b/examples/guided_set_speed_yaw/guided_set_speed_yaw.py @@ -1,16 +1,29 @@ """ +guided_set_speed_yaw.py: (Copter Only) + This example shows how to move/direct Copter and send commands in GUIDED mode using DroneKit Python. Example documentation: http://python.dronekit.io/examples/guided-set-speed-yaw-demo.html """ +from dronekit import connect from dronekit.lib import VehicleMode, Location from pymavlink import mavutil import time import math -api = local_connect() -vehicle = api.get_vehicles()[0] + +#Set up option parsing to get connection string +import argparse +parser = argparse.ArgumentParser(description='Print out vehicle state information. Connects to SITL on local PC by default.') +parser.add_argument('--connect', default='127.0.0.1:14550', + help="vehicle connection target. Default '127.0.0.1:14550'") +args = parser.parse_args() + + +# Connect to the Vehicle +print 'Connecting to vehicle on: %s' % args.connect +vehicle = connect(args.connect, await_params=True) def arm_and_takeoff(aTargetAltitude): @@ -32,7 +45,7 @@ def arm_and_takeoff(aTargetAltitude): vehicle.armed = True vehicle.flush() - while not vehicle.armed and not api.exit: + while not vehicle.armed: print " Waiting for arming..." time.sleep(1) @@ -42,7 +55,7 @@ def arm_and_takeoff(aTargetAltitude): # Wait until the vehicle reaches a safe height before processing the goto (otherwise the command # after Vehicle.commands.takeoff will execute immediately). - while not api.exit: + while True: print " Altitude: ", vehicle.location.alt if vehicle.location.alt>=aTargetAltitude*0.95: #Just below target, in case of undershoot. print "Reached target altitude" @@ -341,7 +354,7 @@ def goto(dNorth, dEast, gotoFunction=vehicle.commands.goto): vehicle.flush() - while not api.exit and vehicle.mode.name=="GUIDED": #Stop action if we are no longer in guided mode. + while vehicle.mode.name=="GUIDED": #Stop action if we are no longer in guided mode. remainingDistance=get_distance_metres(vehicle.location, targetLocation) print "Distance to target: ", remainingDistance if remainingDistance<=targetDistance*0.01: #Just below target, in case of undershoot. @@ -460,7 +473,7 @@ def send_global_velocity(velocity_x, velocity_y, velocity_z): goto(0, 260, goto_position_target_global_int) print("Set speed to 10m/s (max).") -set_speed(10, goto_position_target_global_int) +set_speed(10) print("Position North 100 West 130") goto(100, -130, goto_position_target_global_int) diff --git a/examples/guided_set_speed_yaw/readme.md b/examples/guided_set_speed_yaw/readme.md deleted file mode 100644 index 0908d4fac..000000000 --- a/examples/guided_set_speed_yaw/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -# Guided Demo - -Please check the documentation folder for more info \ No newline at end of file From f832e8b5af28d446fa006d641e75604db5d47189 Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Mon, 12 Oct 2015 11:41:11 +1100 Subject: [PATCH 4/4] Remove git merge rubbish --- docs/guide/getting_started.rst | 113 ++------------------------------- 1 file changed, 7 insertions(+), 106 deletions(-) diff --git a/docs/guide/getting_started.rst b/docs/guide/getting_started.rst index 1cd97adf9..865ba1537 100644 --- a/docs/guide/getting_started.rst +++ b/docs/guide/getting_started.rst @@ -63,7 +63,7 @@ Install DroneKit-Python and its dependencies from the public PyPi repository: .. code:: bash - sudo pip install droneapi numpy + sudo pip install dronekit @@ -74,16 +74,12 @@ Installing DroneKit on Windows Set up a command line DroneKit-Python installation using *WinPython* (this Python distribution already includes most of the needed dependencies). -<<<<<<< HEAD - sudo pip install pyparsing - sudo pip install dronekit -======= + #. Download and run the correct `WinPython installer `_ (**v2.7**) for your platform (win32 vs win64). * Run the installer as an administrator (**Right-click** on file, select **Run as Administrator**). * When prompted for the destination location, specify **C:\\Program Files (x86)** (the default location is under the **Downloads** folder). ->>>>>>> DKPY2 fixes to getting started, running examples, and developer setup windows. Consequent fixups to links elsewhere #. Register the Python that came from *WinPython* as the preferred interpreter for your machine: @@ -97,7 +93,7 @@ Set up a command line DroneKit-Python installation using *WinPython* (this Pytho .. code:: bash - pip install droneapi + pip install dronekit @@ -109,12 +105,12 @@ Connecting to a Vehicle ======================= The connection to the vehicle is set up within the DroneKit script. Scripts import and call the :py:func:`connect()` method. -After connecting this returns a :py:class:`Vehicle ` object from which you can get/set parameters +After connecting this returns a :py:class:`Vehicle ` object from which you can get/set parameters and attributes, and control vehicle movement. .. code:: python - from droneapi import connect + from dronekit import connect # Connect to UDP endpoint. vehicle = connect('127.0.0.1:14550', await_params=True) @@ -122,7 +118,7 @@ and attributes, and control vehicle movement. .. note:: Calling ``connect()`` with ``await_params=True`` (as shown above) ensures that the method will not return until - :py:attr:`Vehicle.parameters ` is fully populated with values from the vehicle. + :py:attr:`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, if the attribute is not supported by the vehicle). @@ -151,37 +147,20 @@ the more common connection types: .. tip:: -<<<<<<< HEAD - echo "module load dronekit.module.api" >> ~/.mavinit.scr -======= The strings above are the same as you would use if connecting with MAVProxy. For other options see the `MAVProxy documentation `_. ->>>>>>> DKPY2 fixes to getting started, running examples, and developer setup windows. Consequent fixups to links elsewhere You can start this simple script in the same way you would start any other standalone Python script. .. code-block:: bash -<<<<<<< HEAD - echo module load dronekit.module.api >> %HOMEPATH%\AppData\Local\MAVProxy\mavinit.scr -======= python your_dronekit_script.py ->>>>>>> DKPY2 fixes to getting started, running examples, and developer setup windows. Consequent fixups to links elsewhere -<<<<<<< HEAD -.. code-block:: bash - :emphasize-lines: 1 - - MANUAL> module load dronekit.module.api - DroneAPI loaded - MANUAL> -======= .. todo:: Connect method here needs to link to the function, but it isn't exported yet. Fix that once the API tidied. - ->>>>>>> DKPY2 fixes to getting started, running examples, and developer setup windows. Consequent fixups to links elsewhere + @@ -190,85 +169,7 @@ You can start this simple script in the same way you would start any other stand Running an app/example ====================== -<<<<<<< HEAD -This section shows how to run the :ref:`Vehicle State ` example, -which reads and writes :ref:`vehicle state and parameter ` information. - -.. warning:: - - This example doesn't take off, but it does arm the motors. Don't run any example indoors on a real vehicle - unless you have first removed its propellers. - -The steps are: - -#. Get the DroneKit-Python example source code onto your local machine. - - The easiest way to do this is to clone the **dronekit-python** repository from Github. - On the command prompt enter: - - .. code-block:: bash - - git clone http://github.com/dronekit/dronekit-python.git - - .. tip:: - - The :ref:`Windows Installation ` copies the example code here: - :file:`C:\\Program Files (x86)\\MAVProxy\\examples\\`. - -#. Start MAVProxy and :ref:`connect to the vehicle `. For example: - - * To connect to a simulated vehicle when starting *MAVProxy* (from the command line): - - .. code-block:: bash - - mavproxy.py --master=127.0.0.1:14550 - - * To connect to a simulated vehicle after starting *MAVProxy* (for example, on Windows): - - .. code-block:: bash - - link add 127.0.0.1:14550 - -#. You should already have set up *MAVProxy* to :ref:`load DroneKit automatically `. - If not, manually load the library using: - - .. code-block:: bash - - module load dronekit.module.api - -#. Once the *MAVProxy* console is running, start ``vehicle_state.py`` by entering ``api start`` followed by the - full file path of the script. For example: - - .. code-block:: bash - - api start "C:\Program Files (x86)\MAVProxy\examples\vehicle_state\vehicle_state.py" - - - The output should look something like that shown below - - .. code-block:: bash - :emphasize-lines: 1 - - MANUAL> api start "C:\Program Files (x86)\MAVProxy\examples\vehicle_state\vehicle_state.py" - STABILIZE> - - Get all vehicle attribute values: - Location: Attitude: Attitude:pitch=-0.00405988190323,yaw=-0.0973932668567,roll=-0.00393210304901 - Velocity: [0.06, -0.07, 0.0] - GPS: GPSInfo:fix=3,num_sat=10 - groundspeed: 0.0 - airspeed: 0.0 - mount_status: [None, None, None] - Mode: STABILIZE - Armed: False - Set Vehicle.mode=GUIDED (currently: STABILIZE) - Waiting for mode change ... - Got MAVLink msg: COMMAND_ACK {command : 11, result : 0} - ... - -======= This SDK has :ref:`numerous examples `. We recommend you start with :ref:`example-vehicle-state`, which reads and writes :ref:`vehicle state and parameter ` information. ->>>>>>> DKPY2 fixes to getting started, running examples, and developer setup windows. Consequent fixups to links elsewhere For general information on running the examples (and other apps) see :ref:`running_examples_top`.