Configurate the drone

Before working with video, it is necessary to understand some basic configuration issues. Depending on configuration-settings the drone behaves differently, so is e.g. the command useDemoMode(), beside others, an alias for a reconfiguration of the drone.

The AR.Drone 2.0 has 104 information and configurable options. Some entries give a status and are only readable, like "general:flight_time", some are editable, e.g. "general:ardrone_name". These simple text strings, more or less, consist of two parts; the first part is the option's name, containing the category and the option, the second part is the set value.

The PS-Drone supports you by organizing the complex procedures of communication and its handling, so a reconfiguration is not so tricky. You cannot “brick” the drone, but it is always better to know what you are doing.
It is important to know that reconfigurations are set with a delay, depending on the quantity of configurations to set at once. Depending on the drone's firmware (e.g. version 2.3.3) that procedure is optimized by temporarily sending extra NavData in between.
Furthermore, it happens once in a while that the drone's reactions are inconsistent after an alteration: The drone claims that the value has been set, but it maintains its previous setting. It seems that this concerns mainly video: Sometimes a switch to ground-camera has been acknowledged, but the front-view is still visible.

Here is an example how to get and set the drones configurations:
##### Suggested clean drone startup sequence #####
import time, sys
import ps_drone                                    # Import PS-Drone-API

drone = ps_drone.Drone()                           # Start using drone
drone.startup()                                    # Connects to drone and starts subprocesses

drone.reset()                                      # Sets drone's status to good
while (drone.getBattery()[0]==-1): time.sleep(0.1) # Wait until drone has done its reset
print "Battery: "+str(drone.getBattery()[0])+"% "+str(drone.getBattery()[1]) # Battery-status
drone.useDemoMode(True)                            # Set 15 basic dataset/sec
time.sleep(0.5)                                    # Give it some time to awake fully

##### Mainprogram begin #####
# Just list the configuration, it is already synchronized
for i in drone.ConfigData:               print i

# Take a closer look at an option...
print "\nSample: ",
for i in drone.ConfigData:
    if i[0] == "control:altitude_max":   print str(i)+" Count: "+str(drone.ConfigDataCount)\
                                               +" Timestamp: "+str(drone.ConfigDataTimeStamp)
# ... and change it
print "-----"
print "Setting \"control:altitude_max\" to \"2999\"..."
CDC =     drone.ConfigDataCount
NDC =     drone.NavDataCount
refTime = time.time()
drone.setConfig("control:altitude_max","2999")      # request change of an option
while CDC==drone.ConfigDataCount: time.sleep(0.001) # Wait until it is done (resync is done)
print " Finished after "+str(time.time()-refTime)+" seconds, "+str(drone.NavDataCount-NDC)\
                                               +" NavData where received meanwhile."
for i in drone.ConfigData:
    if i[0] == "control:altitude_max":   print str(i)+" Count: "+str(drone.ConfigDataCount)\
                                               +" Timestamp: "+str(drone.ConfigDataTimeStamp)
# Change an option a couple of times
print "\n-----"
print "Setting \"control:altitude_max\" to \"2996\",\"2997\",\"2998\",\"2999\"&\"3000\"..."
CDC =     drone.ConfigDataCount
NDC =     drone.NavDataCount
refTime = time.time()
drone.setConfig("control:altitude_max","2996")      # Request change of an option...
drone.setConfig("control:altitude_max","2997")      # ...request change of the option again...
drone.setConfig("control:altitude_max","2998")      # ...and again
drone.setConfig("control:altitude_max","2999")      # PS-Drone detects and deletes double...
drone.setConfig("control:altitude_max","3000")      # ...requests and sets the last one only
while CDC==drone.ConfigDataCount: time.sleep(0.001) # Wait until it is done (resync is done)
print " Finished after "+str(time.time()-refTime)+" seconds, "+str(drone.NavDataCount-NDC)\
                                               +" NavData where received meanwhile."
for i in drone.ConfigData:
    if i[0] == "control:altitude_max":   print str(i)+" Count: "+str(drone.ConfigDataCount)\
                                               +" Timestamp: "+str(drone.ConfigDataTimeStamp)
print "\n-----"
print "Setting \"control:altitude_max\" to \"2980\", \"control:altitude_min\" to \"499\""\
                                               +" and \"video:video_on_usb\" to \"false\"..."
CDC =     drone.ConfigDataCount
NDC =     drone.NavDataCount
refTime = time.time()
drone.setConfig("control:altitude_max","2980")      # Request change of an option
drone.setConfig("control:altitude_min","499")       # Request change of an other option
drone.setConfig("video:video_on_usb","false")       # Request change of an other option
while CDC==drone.ConfigDataCount: time.sleep(0.001) # Wait until it is done (resync is done)
print " Finished after "+str(time.time()-refTime)+" seconds, "+str(drone.NavDataCount-NDC)\
                                               +" NavData where received meanwhile."
for i in drone.ConfigData:
  j = i[0]
  CDTS = drone.ConfigDataTimeStamp
  if j=="control:altitude_max" or j=="control:altitude_min" or j=="video:video_on_usb":
        print" "+str(i)+" Count: "+str(drone.ConfigDataCount)+" Timestamp: "+str(CDTS)

print "\n-----"
print "Just resyncing the drones configuration..."
CDC =     drone.ConfigDataCount
NDC =     drone.NavDataCount
refTime = time.time()
drone.getConfig()                                   # Request resyncing
while CDC==drone.ConfigDataCount: time.sleep(0.001) # Wait until it is done (resync is done)
print " Finished after "+str(time.time()-refTime)+" seconds, "+str(drone.NavDataCount-NDC)\
                                               +" NavData where received meanwhile."
Download sample firstConfig.py

For reconfiguration you mainly need two commands: getConfig() and setConfig()

getConfig() will synchronize the local copy of the drone’s configuration and stores the list in the variable ConfigData, along with the time when it was received in ConfigDataTimeStamp and the count of received configurations in ConfigDataCount. The fetch of the drone’s configuration works not in real-time and may take up to 0.15 seconds.

The command setConfig("option","value") sets the value for the given option. The name of the option has to be a text-string. As alterations are not in real-time, in order to optimize the configuration-speed and for convenience, the request is added to a queue and sent one after another without you having to care about. The PS-Drone-API tests the queue for double entries of the same option and initiates the latest change to prevent unnecessary delay.

If you try to set an unknown option, the drone will reject the request; however, if the value is unknown, the drone sets an unpredictable value itself. When the queue is done, the local copy of the drone's configuration is automatically updated analogue to command getConfig().

Not all of the options and their possible values are guessable, some are not even documented by Parrot. Take a look the PS-Drone-API-documentation to find the known descriptions of the entries.

A mode for multi-configuration is also existing. It is mainly interesting for using video and it contains the configurations for the set sessions. It is not really necessary to care about how it works; however, once you have started using it, you must continue to use it until your program has finished or until you have switched back to single-configuration.

After having enabled multi-configuration by sending pre-set IDs with the command setConfigAllID(), you change configurations by using the command setMConfig() which has the same usage and behaviour as setConfig().

##### Suggested clean drone startup sequence #####
import time, sys
import ps_drone                                    # Import PS-Drone-API

drone = ps_drone.Drone()                           # Start using drone
drone.startup()                                    # Connects to drone and starts subprocesses

drone.reset()                                      # Sets drone's status to good
while (drone.getBattery()[0]==-1): time.sleep(0.1) # Wait until drone has done its reset
print "Battery: "+str(drone.getBattery()[0])+"% "+str(drone.getBattery()[1]) # Battery-status
drone.useDemoMode(True)                            # Set 15 basic dataset/sec
time.sleep(0.5)                                    # Give it some time to awake fully

##### Mainprogram begin #####
# Take a closer look at an option...
print "default IDs:"
for i in drone.ConfigData:
    if i[0].count("custom:")==1 and i[0].count("_id")==1:   print str(i)

print "set default multiconfiguration:"
drone.setConfigAllID()
CDC = drone.ConfigDataCount
while CDC==drone.ConfigDataCount: time.sleep(0.001) # Wait until it is done (resync is done)
for i in drone.ConfigData:
    if i[0].count("custom:")==1 and i[0].count("_id")==1:   print str(i)

Download sample multiConfig.py
As you see, multi-configuration does not really differ from normal configuration.