Skip to content

Commit bf8e8da

Browse files
committed
Merge pull request #427 from dronekit/tcr-rc
Implements Channels functionality as its own object.
2 parents 4567686 + 054e9ef commit bf8e8da

File tree

5 files changed

+490
-115
lines changed

5 files changed

+490
-115
lines changed

docs/examples/channel_overrides.rst

Lines changed: 96 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
.. _example_channel_overrides:
22
.. _vehicle_state_channel_override:
33

4-
==========================
5-
Example: Channel Overrides
6-
==========================
4+
=======================================
5+
Example: Channels and Channel Overrides
6+
=======================================
77

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

@@ -52,19 +52,52 @@ On the command prompt you should see (something like):
5252

5353
.. code:: bash
5454
55-
Overriding RC channels for roll and yaw
56-
Current overrides are: {'1': 900, '4': 1000}
57-
Channel default values: {'1': 1500, '3': 1000, '2': 1500, '5': 1800, '4': 1500, '7': 1000, '6': 1000, '8': 1800}
58-
Cancelling override
55+
Connecting to vehicle on: 170.0.0.1:14550
56+
>>> APM:Copter V3.3 (d6053245)
57+
>>> Frame: QUAD
58+
>>> Calibrating barometer
59+
>>> Initialising APM...
60+
>>> barometer calibration complete
61+
>>> GROUND START
62+
Channel values from RC Tx: {'1': 1500, '3': 1000, '2': 1500, '5': 1800, '4': 1500, '7': 1000, '6': 1000, '8': 1800}
63+
Read channels individually:
64+
Ch1: 1500
65+
Ch2: 1500
66+
Ch3: 1000
67+
Ch4: 1500
68+
Ch5: 1800
69+
Ch6: 1000
70+
Ch7: 1000
71+
Ch8: 1800
72+
Number of channels: 8
73+
74+
Channel overrides: {}
75+
Set Ch2 override to 200 (indexing syntax)
76+
Channel overrides: {'2': 200}
77+
Ch2 override: 200
78+
Set Ch3 override to 300 (dictionary syntax)
79+
Channel overrides: {'3': 300}
80+
Set Ch1-Ch8 overrides to 110-810 respectively
81+
Channel overrides: {'1': 110, '3': 310, '2': 210, '5': 510, '4': 4100, '7': 710, '6': 610, '8': 810}
82+
83+
Cancel Ch2 override (indexing syntax)
84+
Channel overrides: {'1': 110, '3': 310, '5': 510, '4': 4100, '7': 710, '6': 610, '8': 810}
85+
Clear Ch3 override (del syntax)
86+
Channel overrides: {'1': 110, '5': 510, '4': 4100, '7': 710, '6': 610, '8': 810}
87+
Clear Ch5, Ch6 override and set channel 3 to 500 (dictionary syntax)
88+
Channel overrides: {'3': 500}
89+
Clear all overrides
90+
Channel overrides: {}
91+
92+
Close vehicle object
93+
Completed
5994
6095
6196
6297
How does it work?
6398
=================
6499

65-
Get the default values of the channels using the :py:attr:`channel_readback <dronekit.lib.Vehicle.channel_readback>` attribute.
66-
67-
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.
100+
The RC transmitter channels are connected to the autopilot and control the vehicle.
68101

69102
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
70103
`Plane <http://plane.ardupilot.com/wiki/arduplane-parameters/#rcmap__parameters>`_,
@@ -77,7 +110,60 @@ In general a value of 0 set for a specific ``RCn_FUNCTION`` indicates that the c
77110
`mission controlled <http://plane.ardupilot.com/wiki/flight-features/channel-output-functions/#disabled>`_ (i.e. it will not directly be
78111
controlled by normal autopilot code).
79112

113+
You can read the values of the channels using the :py:attr:`Vehicle.channels <dronekit.lib.Vehicle.channels>` attribute. The values are regularly updated,
114+
from the UAV, based on the RC inputs from the transmitter. These can be read either as a set or individually:
115+
116+
.. code:: python
117+
118+
# Get all channel values from RC transmitter
119+
print "Channel values from RC Tx:", vehicle.channels
120+
121+
# Access channels individually
122+
print "Read channels individually:"
123+
print " Ch1: %s" % vehicle.channels['1']
124+
print " Ch2: %s" % vehicle.channels['2']
125+
126+
You can override the values sent to the vehicle by the autopilot using :py:attr:`Vehicle.channels.overrides <dronekit.lib.Channels.overrides>`
127+
(although this is not recommended)! The overrides can be written individually using an indexing syntax or as a set using a dictionary syntax.
128+
129+
.. code:: python
130+
131+
# Set Ch2 override to 200 using indexing syntax
132+
vehicle.channels.overrides['2'] = 200
133+
# Set Ch3, Ch4 override to 300,400 using dictionary syntax"
134+
vehicle.channels.overrides = {'3':300, '4':400}
135+
136+
To clear all overrides, set the attribute to an empty dictionary.
137+
To clear an individual override you can set its value to ``None`` (or call ``del`` on it):
138+
139+
.. code:: python
140+
141+
# Clear override by setting channels to None
142+
# Clear using index syntax
143+
vehicle.channels.overrides['2'] = None
144+
145+
# Clear using 'del' syntax
146+
del vehicle.channels.overrides['3']
147+
148+
# Clear using dictionary syntax (and set override at same time!)
149+
vehicle.channels.overrides = {'5':None, '6':None,'3':500}
150+
151+
# Clear all overrides by setting an empty dictionary
152+
vehicle.channels.overrides = {}
153+
154+
Read the channel overrides either as a dictionary or by index.
155+
156+
.. code:: python
157+
158+
# Get all channel overrides
159+
print " Channel overrides: %s" % vehicle.channels.overrides
160+
# Print just one channel override
161+
print " Ch2 override: %s" % vehicle.channels.overrides['2']
162+
163+
.. note::
80164

165+
You'll get a ``KeyError`` exception if you read a channel override that has
166+
not been set.
81167

82168

83169
Source code

docs/guide/migrating.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,25 @@ including:
237237
:py:func:`Vehicle.is_armable <dronekit.lib.Vehicle.is_armable>`.
238238

239239

240+
Channel Overrides
241+
-----------------
242+
243+
.. warning::
244+
245+
Channel overrides (a.k.a “RC overrides”) are highly discommended (they are primarily implemented for
246+
simulating user input and when implementing certain types of joystick control).
247+
248+
DKPY v2 replaces the ``vehicle.channel_readback`` attribute with
249+
:py:attr:`Vehicle.channels <dronekit.lib.Vehicle.channels>` (and the :py:class:`Channels <dronekit.lib.Channels>`
250+
class) and the ``vehicle.channel_override`` attribute with
251+
:py:attr:`Vehicle.channels.overrides <dronekit.lib.Channels.overrides>`
252+
(and the :py:class:`ChannelsOverrides <dronekit.lib.ChannelsOverrides>` class).
253+
254+
Documentation and example code for how to use the new API are provided in :ref:`example_channel_overrides`.
255+
256+
257+
258+
240259
Debugging
241260
=========
242261

0 commit comments

Comments
 (0)