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
90 changes: 90 additions & 0 deletions docs/examples/channel_overrides.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
.. _example_channel_overrides:
.. _vehicle_state_channel_override:

==========================
Example: Channel Overrides
==========================

This example shows how to get channel information and to get/set channel-override information.

.. warning::

Channel overrides (a.k.a "RC overrides") are highly discommended (they are primarily implemented
for simulating user input and when implementing certain types of joystick control).

Instead use the appropriate MAVLink commands like DO_SET_SERVO/DO_SET_RELAY, or more generally set
the desired position or direction/speed.

If you have no choice but to use a channel-override please explain why in a
`github issue <https://github.com/dronekit/dronekit-python/issues>`_ and we will attempt to find a
better alternative.


Running the example
===================

The example can be run as described in :doc:`running_examples` (which in turn assumes that the vehicle
and DroneKit have been set up as described in :ref:`get-started`).

In summary, after cloning the repository:

#. Navigate to the example folder as shown:

.. code-block:: bash

cd dronekit-python/examples/channel_overrides/


#. Start the example, passing the :ref:`connection string <get_started_connect_string>` you wish to use in the ``--connect`` parameter:

.. code-block:: bash

python channel_overrides.py --connect 127.0.0.1:14550

.. note::

The examples uses the ``--connect`` parameter to pass the :ref:`connection string <get_started_connect_string>` into the script.
The command above would be used to connect to :ref:`SITL <sitl_setup>` running on the local machine via UDP port 14550.



On the command prompt you should see (something like):

.. code:: bash

Overriding RC channels for roll and yaw
Current overrides are: {'1': 900, '4': 1000}
Channel default values: {'1': 1500, '3': 1000, '2': 1500, '5': 1800, '4': 1500, '7': 1000, '6': 1000, '8': 1800}
Cancelling override



How does it work?
=================

Get the default values of the channels using the :py:attr:`channel_readback <dronekit.lib.Vehicle.channel_readback>` attribute.

You can over-ride these values using the :py:attr:`channel_override <dronekit.lib.Vehicle.channel_override>` attribute. This takes a dictionary argument defining the RC *output* channels to be overridden (specified by channel number), and their new values. Channels that are not specified in the dictionary are not overridden. All multi-channel updates are atomic. To cancel an override call ``channel_override`` again, setting zero for the overridden channels.

The values of the first four channels map to the main flight controls: 1=Roll, 2=Pitch, 3=Throttle, 4=Yaw (the mapping is defined in ``RCMAP_`` parameters in
`Plane <http://plane.ardupilot.com/wiki/arduplane-parameters/#rcmap__parameters>`_,
`Copter <http://copter.ardupilot.com/wiki/configuration/arducopter-parameters/#rcmap__parameters>`_ ,
`Rover <http://rover.ardupilot.com/wiki/apmrover2-parameters/#rcmap__parameters>`_).

The remaining channel values are configurable, and their purpose can be determined using the
`RCn_FUNCTION parameters <http://plane.ardupilot.com/wiki/flight-features/channel-output-functions/>`_.
In general a value of 0 set for a specific ``RCn_FUNCTION`` indicates that the channel can be
`mission controlled <http://plane.ardupilot.com/wiki/flight-features/channel-output-functions/#disabled>`_ (i.e. it will not directly be
controlled by normal autopilot code).




Source code
===========

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

.. literalinclude:: ../../examples/channel_overrides/channel_overrides.py
:language: python

2 changes: 2 additions & 0 deletions docs/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ during missions and outside missions using custom commands.
Follow Me (Linux only)<follow_me>
Drone Delivery <drone_delivery>
Flight Replay <flight_replay>
Channel Overrides <channel_overrides>




98 changes: 49 additions & 49 deletions docs/examples/vehicle_state.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Example: Vehicle State
======================

This example shows how to get/set vehicle attribute, parameter and channel-override information,
This example shows how to get/set vehicle attribute and parameter information,
how to observe vehicle attribute changes, and how to get the home position.

The guide topic :ref:`vehicle-information` provides a more detailed explanation of how the API
Expand All @@ -14,89 +14,89 @@ should be used.
Running the example
===================

The vehicle and DroneKit should be set up as described in :ref:`get-started`.
The example can be run as described in :doc:`running_examples` (which in turn assumes that the vehicle
and DroneKit have been set up as described in :ref:`get-started`).

If you're using a simulated vehicle remember to :ref:`disable arming checks <disable-arming-checks>` so
that the example can run. You can also `add a virtual rangefinder <http://dev.ardupilot.com/wiki/simulation-2/sitl-simulator-software-in-the-loop/using-sitl-for-ardupilot-testing/#adding_a_virtual_rangefinder>`_
that the example can run. You can also
`add a virtual rangefinder <http://dev.ardupilot.com/wiki/using-sitl-for-ardupilot-testing/#adding_a_virtual_rangefinder>`_
(otherwise the :py:attr:`Vehicle.rangefinder <dronekit.lib.Vehicle.rangefinder>` attribute may return values of ``None`` for the distance
and voltage).

Once MAVProxy is running and the API is loaded, you can start the example by typing: ``api start vehicle_state.py``.
In summary, after cloning the repository:

.. note::
#. Navigate to the example folder as shown:

The command above assumes you started the *MAVProxy* prompt in a directory containing the example script. If not,
you will have to specify the full path to the script (something like):
``api start /home/user/git/dronekit-python/examples/vehicle_state/vehicle_state.py``.
.. code-block:: bash

cd dronekit-python/examples/vehicle_state/

On the *MAVProxy* console you should see (something like):

#. Start the example, passing the :ref:`connection string <get_started_connect_string>` you wish to use in the ``--connect`` parameter:

.. code-block:: bash

python vehicle_state.py --connect 127.0.0.1:14550

.. note::

The examples uses the ``--connect`` parameter to pass the :ref:`connection string <get_started_connect_string>` into the script.
The command above would be used to connect to :ref:`SITL <sitl_setup>` running on the local machine via UDP port 14550.



On the command prompt you should see (something like):

.. code:: bash

MAV> api start vehicle_state.py
STABILIZE>
Connecting to vehicle on: 127.0.0.1:14550
>>> APM:Copter V3.3-rc1 (d66eec53)
>>> Frame: QUAD

Accumulating vehicle attribute messages (2s)

Get all vehicle attribute values:
Location: Attitude: Attitude:pitch=-0.00405988190323,yaw=-0.0973932668567,roll=-0.00393210304901
Velocity: [0.06, -0.07, 0.0]
Location: Location:lat=-35.3632601,lon=149.1652279,alt=-0.00999999977648,is_relative=False
Attitude: Attitude:pitch=0.00486609805375,yaw=0.489637970924,roll=0.00645932834595
Velocity: [-0.12, 0.06, 0.0]
GPS: GPSInfo:fix=3,num_sat=10
Groundspeed: 0.0
Airspeed: 0.0
Mount status: [None, None, None]
Battery: Battery voltage: 12590, current: 0, level: 99
Rangefinder: Rangefinder: distance=0.189999997616, voltage=0.0190000012517
Rangefinder distance: 0.189999997616
Rangefinder voltage: 0.0190000012517
Battery: Battery:voltage=0.0,current=None,level=None
Rangefinder: Rangefinder: distance=None, voltage=None
Rangefinder distance: None
Rangefinder voltage: None
Mode: STABILIZE
Armed: False

Set Vehicle.mode=GUIDED (currently: STABILIZE)
Waiting for mode change ...
Got MAVLink msg: COMMAND_ACK {command : 11, result : 0}
GUIDED> Mode GUIDED

Set Vehicle.armed=True (currently: False)
Waiting for arming...
APM: ARMING MOTORS
APM: Initialising APM...
Got MAVLink msg: COMMAND_ACK {command : 400, result : 0}
ARMED
>>> ☺ARMING MOTORS
>>> ☺Initialising APM...
Waiting for arming...

Add mode attribute observer for Vehicle.mode
Set mode=STABILIZE (currently: GUIDED)
Wait 2s so callback invoked before observer removed
Got MAVLink msg: COMMAND_ACK {command : 11, result : 0}
STABILIZE> Mode STABILIZE
CALLBACK: Mode changed to: STABILIZE
CALLBACK: Mode changed to: STABILIZE

Get home location
Requesting 0 waypoints t=Fri May 15 11:35:58 2015 now=Fri May 15 11:35:58 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 : 583.729980469}
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.3632583618, y : 149.165222168, z : 583.729980469}

Read vehicle param 'THR_MIN': 130.0
Write vehicle param 'THR_MIN' : 10
timeout setting THR_MIN to 10.000000
Read new value of param 'THR_MIN': 10.0

Set MAVLink callback handler (start receiving all MAVLink messages)
Wait 1s so mavrx_debug_handler has a chance to be called before it is removed
Raw MAVLink message: RAW_IMU {time_usec : 894620000, xacc : -3, yacc : 10, zacc : -999, xgyro : 1, ygyro : 0, zgyro : 1, xmag : 153, ymag : 52, zmag : -364}
...
Raw MAVLink message: SCALED_PRESSURE {time_boot_ms : 895340, press_abs : 945.038024902, press_diff : 0.0, temperature : 2600}
Remove the MAVLink callback handler (stop getting messages)


Overriding RC channels for roll and yaw
Current overrides are: {'1': 900, '4': 1000}
Channel default values: {'1': 1500, '3': 1000, '2': 1500, '5': 1800, '4': 1500, '7': 1000, '6': 1000, '8': 1800}
Cancelling override

Reset vehicle attributes/parameters and exit
Got MAVLink msg: COMMAND_ACK {command : 11, result : 0}
APM: DISARMING MOTORS
Got MAVLink msg: COMMAND_ACK {command : 400, result : 0}
DISARMED
timeout setting THR_MIN to 130.000000
APIThread-0 exiting...
>>> ☺DISARMING MOTORS

Close vehicle object




Expand Down Expand Up @@ -133,7 +133,7 @@ Source code
===========

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>`_):

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

Loading