Detecting markers

The AR.Drone 2.0 supports detecting certain machine-parsable images using its cameras. These particular images are called “tags” or “markers”. It is an integrated feature of the drone able to detect up to four markers; their position, distance to the drone and, depending on the marker, their orientation at the same time.
The cameras of the drone (tested with a standard AR.Drone 2.0) are not really good, so there is a limited range of luminance in which it is possible to get acceptable results. Also spotlights and reflections of marker-printouts are a serious problem.

The marker that comes with the drone is the “black and white oriented roundel”. It is recommended for the following tests, not least because the drone detects it most certainly. The tag “Roundel” has also been tested, but, because it contains specific colors, it is harder for the drone to detect it.

##### 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
drone.getNDpackage(["demo","vision_detect"])       # Packets, which shall be decoded
time.sleep(0.5)                                    # Give it some time to awake fully

##### Mainprogram begin #####
# Setting up detection...
# Shell=1|Roundel=2|BlackRoundel=4|Stripe=8|Cap=16|ShellV2=32|TowerSide=64|OrientedRoundel=128
drone.setConfig("detect:detect_type","3"            # Enable detection in universal mode
drone.setConfig("detect:detections_select_h","128") # Detect "Oriented Roundel" in front
drone.setConfig("detect:detections_select_v","0")   # No detection on ground cam
CDC = drone.ConfigDataCount
while CDC==drone.ConfigDataCount: time.sleep(0.001) # Wait until it is done (resync is done)

# Get detections
stop = False
while not stop:
    NDC = drone.NavDataCount
    while NDC == drone.NavDataCount:  time.sleep(0.01)
    if drone.getKey():              stop = True
    tagNum = drone.NavData["vision_detect"][0]      # Number of found tags
    tagX = drone.NavData["vision_detect"][2]        # Horizontal position(s)
    tagY = drone.NavData["vision_detect"][3]        # Vertical position(s)
    tagZ = drone.NavData["vision_detect"][6]        # Distance(s)
    tagRot = drone.NavData["vision_detect"][7]      # Orientation(s)

# Show detections
    if tagNum:
        for i in range (0,tagNum):
            print "Tag no "+str(i)+" : X= "+str(tagX[i])+" Y= "+str(tagY[i])\
                                  +" Dist= "+str(tagZ[i])+" Orientation= "+str(tagRot[i])
    else:   print "No tag detected"
Download sample

At first, the detection has to be enabled by reconfiguring option "detect:detect_type" from "0" to "10".
Options "detect:detections_select_h" and "detect:detections_select_v" limit the detection to a specific set of available tags for the front or respectively the ground camera. Each available tag has a certain number, e.g. “Black and white oriented roundel” has "128" and “Roundel” has "2". To detect both, set the option's value to "130"; however, the more tags are selected, the longer the drone might need to detect and analyze the positions of the markers.

The detected coordinates for X (horizontal) and Y (vertical) are given in a range from 0 to 1000, which means a low value on the left respectively on top and a high value on the right respectively bottom. Also the distance has a value range from 0 to 1000, where 0 means very close and 1000 fare away.