ATCommands¶
The (in)complete description of ATCommands is documented in Parrot’s AR.Drone Developer Guide chapter 6.5, please refer to it for detailed description of each command.
Using ATCommands¶
Creating an ATCommand¶
To create an ATCommand
, you have to call the command class with the corresponding arguments.
For example, to create an "AT*PCMD"
command with the progressive flag and vertical speed = 0.8:
>>> from pyardrone import at
>>> cmd = at.PCMD(at.PCMD.flag.progressive, 0, 0.8, 0, 0)
>>> cmd
PCMD(flag=<flag.progressive: 1>, roll=0, pitch=0.8, gaz=0, yaw=0)
or using keyword arguments, just like a function:
>>> at.PCMD(at.PCMD.flag.progressive, gaz=0.8)
PCMD(flag=<flag.progressive: 1>, roll=0, pitch=0.8, gaz=0, yaw=0)
ATCommands are collections.namedtuple()
subclasses, so reading it is just as easy.
>>> cmd
PCMD(flag=<flag.progressive: 1>, roll=0, pitch=0.8, gaz=0, yaw=0)
>>> cmd.roll
0
>>> cmd.pitch
0.8
>>> cmd[0]
<flag.progressive: 1>
>>> cmd[2]
0.8
>>> list(cmd)
[<flag.progressive: 1>, 0, 0.8, 0, 0]
Additionally _pack()
packs the command into bytes
>>> cmd._pack(10) # pack with sequence number = 10
b'AT*PCMD=10,1,0,1061997773,0,0\r'
Sending an ATCommand¶
To send a AT*PCMD command with the progressive flag and vertical speed = 0.8, use pyardrone.ARDrone.send()
>>> # drone is an ARDrone instance here
>>> drone.send(at.PCMD(at.PCMD.flag.progressive, 0, 0.8, 0, 0))
send()
provides the sequence number for the _pack()
function automatically.
Defining ATCommand subclasses¶
If you want to use an ATCommand not defined in the library, you can define it yourself.
For example, to define a “AT*EXAMPLE” command with three arguments: options, speed, comment, which is a integer, a float, and a string respectively:
from pyardrone.at import base, parameters
class EXAMPLE(base.ATCommand):
options = parameters.Int32()
speed = parameters.Float()
comment = parameters.String(default='nothing')
options._set_flags(
eat=0b1,
sleep=0b10,
wander=0b100
)
The created EXAMPLE class can then be used just like other ATCommand classes:
>>> cmd = EXAMPLE(EXAMPLE.options.sleep, 3.5, 'hello')
>>> cmd
EXAMPLE(options=<options.sleep: 2>, speed=3.5, comment='hello')
>>> cmd._pack()
b'AT*EXAMPLE=SEQUNSET,2,1080033280,"hello"\r'
>>> EXAMPLE(options=EXAMPLE.options.wander, speed=6.7)
EXAMPLE(options=<options.wander: 4>, speed=6.7, comment='nothing')
The base ATCommand Class¶
Subclasses share the following methods:
List of ATCommands¶
- class pyardrone.at.REF(input=0, *, use_default_bits=True)[source]¶
Controls the basic behaviour of the drone (take-off/landing, emergency stop/reset)
- class pyardrone.at.PCMD(flag=None, roll=0, pitch=0, gaz=0, yaw=0)[source]¶
Send progressive commands - makes the drone move (translate/rotate).
- flag¶
flag enabling the use of progressive commands and/or the CombinedYaw mode (bitfield)
- Flags:
progressive
= 1combined_yaw
= 2absolute_control
= 4
- roll¶
drone left-right tilt, [-1…1]
- pitch¶
drone front-back tilt, [-1…1]
- gaz¶
drone vertical speed, [-1…1]
- yaw¶
drone angular speed, [-1…1]
- class pyardrone.at.PCMD_MAG(flag=None, roll=None, pitch=None, gaz=None, yaw=None, psi=None, psi_accuracy=None)[source]¶
Send progressive commands - makes the drone move (translate/rotate).
- flag¶
flag enabling the use of progressive commands and/or the CombinedYaw mode (bitfield)
- roll¶
drone left-right tilt, [-1…1]
- pitch¶
drone front-back tilt, [-1…1]
- gaz¶
drone vertical speed, [-1…1]
- yaw¶
drone angular speed, [-1…1]
- psi¶
magneto psi, [-1…1]
- psi_accuracy¶
magneto psi accuracy, [-1…1]
- class pyardrone.at.CONFIG(key=None, value=None)[source]¶
Sets an configurable option on the drone
- key¶
the name of the option to set
- value¶
the option value
- class pyardrone.at.CONFIG_IDS(session=None, user=None, application_ids=None)[source]¶
Identifiers for the next AT*CONFIG command
- class pyardrone.at.CALIB(device_number=None)[source]¶
Magnetometer calibration - Tells the drone to calibrate its magnetometer
- device_number¶
Identifier of the device to calibrate - Choose this identifier from ardrone_calibration_device_t.
- class pyardrone.at.CTRL(mode=None, zero=0)[source]¶
Not documented in developer guide, change control mode
- mode¶
- Flags:
NO_CONTROL_MODE
= 0ARDRONE_UPDATE_CONTROL_MODE
= 1PIC_UPDATE_CONTROL_MODE
= 2LOGS_GET_CONTROL_MODE
= 3CFG_GET_CONTROL_MODE
= 4ACK_CONTROL_MODE
= 5CUSTOM_CFG_GET_CONTROL_MODE
= 6
Parameters¶
- class pyardrone.at.parameters.Parameter(description='', default=None, name=None, index=None)[source]¶
Base class of all at command parameters.
- Parameters:
description – description of the parameter, stored in __doc__
default – default value of the parameter
- static _check(value)[source]¶
Checks the value on
ATCommand
‘s init. Subclasses can optionally define this method, the default implementation is a no-op.- Raises:
TypeError – If the value is of the wrong type.
ValueError – If the value is not valid.
Parameter types¶
- class pyardrone.at.parameters.Int32(...)[source]¶
Parameter class of a 32-bit integer.
- static _check(value)[source]¶
Checks the value on
ATCommand
‘s init. Subclasses can optionally define this method, the default implementation is a no-op.- Raises:
TypeError – If the value is of the wrong type.
ValueError – If the value is not valid.
- class pyardrone.at.parameters.String(...)[source]¶
Parameter class of a string
- static _check(value)[source]¶
Checks the value on
ATCommand
‘s init. Subclasses can optionally define this method, the default implementation is a no-op.- Raises:
TypeError – If the value is of the wrong type.
ValueError – If the value is not valid.