Basic AutoScript Functions

AutoScript has some basic functions for accessing drone navigation data and controlling flight. On this page, these built-in functions are documented.

Warning

In AutoFlight 1.0, the AutoScript API has changed and is not compatible with earlier versions of AutoFlight.

They are divided into two modules named basicctl and imgproc. The imgproc module contains functions for retrieving and processing images, while the basicctl module is used for most other simple commands.

For more advanced and high-level commands, please use the dronectl package.

Basic control and navigation data retrieval

basicctl.takeoff()

Sends a take off command to the drone. This will only send the command and continue immediately, so you’ll probably want to wait until the drone has fully taken off.

basicctl.land()

Sends a land command to the drone.

basicctl.move(pitch, roll, gaz, yaw)

Moves the drone by setting the pitch and roll angles as well as vertical and rotational speed.

Note

This function will cause the drone to move with the specified parameters for an infinite amount of time. You will need to call the hover() command to stop it.

Parameters:
  • pitch – Pitch angle in radians (positive is backward, negative is forward)
  • roll – Roll angle in radians (positive is right, negative is left)
  • gaz – Vertical speed in m/s (positive is up, negative is down)
  • yaw – Rotational speed in rad/s (positive is clockwise, negative is counterclockwise)
basicctl.move_rel(pitch, roll, gaz, yaw)

Moves the drone. The parameters are multipliers of the allowed maximum, and have to be in the range from -1.0 (corresponding to the maximum tilt in one direction) to 1.0 (corresponding to the maximum in the other direction).

Note

This function will cause the drone to move with the specified parameters for an infinite amount of time. You will need to call the hover() command to stop it.

Parameters:
  • pitch – Pitch angle (-1.0: full speed in forward direction; 1.0: full speed in backward direction)
  • roll – Roll angle (-1.0: full angle to left hand side; 1.0: full angle to right hand side)
  • gaz – Vertical speed (-1.0: full speed down; 1.0: full speed up)
  • yaw – Rotational speed (-1.0: full speed in counterclockwise direction; 1.0: full speed in clockwise direction)
basicctl.hover()

Hovers the drone, so it tries to stay at a fixed position. Equivalent to calling move(0, 0, 0, 0).

basicctl.flip(direction)

Sends the flip command to the drone.

Parameters:direction"FRONT", "BACK", "LEFT" or "RIGHT"
basicctl.navdata()

Retrieve the navigation data.

Returns:A dict containing all of the available navigation data. Can vary depending on the drone type (AR.Drone 2.0 or Bebop). Will be empty if not connected.
basicctl.status()

Retrieve the drone’s status.

Returns:A dict containing three keys: 'connected', 'armed' and 'flying'.
basicctl.flattrim()

Perform a “flat trim”.

basicctl.set_view(tilt, pan)

On the Bebop drone, this sets the direction of the digital gimbal.

Parameters:
  • tilt – Tilt between -100 and 100.
  • pan – Pan between -100 and 100.
basicctl.startrecording()

Start recording.

basicctl.stoprecording()

Stop recording.

basicctl.switchview(view)

Switch between front and bottom view. On the AR.Drone 2.0 this switches between the front and bottom camera. On the Bebop this changes the view of the digital gimbal.

Parameters:view – “TOGGLE” to toggle between front/bottom, “FRONT” to look front, “BOTTOM” to look down.
basicctl.takepicture()

Take a picture.

Image Processing

Warning

Using OpenCV’s built in GUI functionality is not (yet) possible in AutoFlight. To display an image, you should always use imgproc.showFrame(img) and never OpenCV’s imshow() or similar.

Note

I am still refining the image processing capabilities of AutoScript. Right now it is possible to retrieve images, to process them using OpenCV for Python, to display them in the AutoFlight main window and to use the April Tag detector built into AutoFlight.

imgproc.latest_frame()

Get the latest frame.

Returns:A numpy array containing the latest received video frame in 8-bit 3 channel BGR format.
imgproc.frame_age()

Get the age of the latest frame. Useful for ignoring outdated frames when the video feed is interrupted.

Returns:The age of the latest frame, in milliseconds.
imgproc.show_frame(frame)

Show an image in the AutoFlight main window.

Parameters:frame – A numpy array containing the frame to display. Must be 8-bit 3 channel BGR or binary.
imgproc.start_tag_detector()

Start the integrated April tag detector.

imgproc.stop_tag_detector()

Stop the integrated April tag detector.

imgproc.set_tag_family(family)

Tell the tag detector which April tag family you want to detect.

Parameters:family – The name of the tag family (e.g.: "Tag36h11")
imgproc.set_tag_roi(x, y, width, height)

Set the rectangular region of interest for the tag detector. Only this region will be analyzed when running the tag detector, potentially reducing CPU usage significantly.

Parameters:
  • x – X-coordinate of the upper left point of your ROI
  • y – Y-coordinate of the upper left point of your ROI
  • width – Width of the ROI
  • height – Height of the ROI
imgproc.tag_detections()

Get the detected tags.

Returns:A list of tuples, each tuple representing one detected tag. Each tuple contains the tag’s ID, a flag indicating whether the detection is valid or not and a list of X/Y coordinates of the tag’s edges.