pyparrot package

Submodules

pyparrot.Bebop module

Bebop class holds all of the methods needed to pilot the drone from python and to ask for sensor data back from the drone

Author: Amy McGovern, dramymcgovern@gmail.com

class pyparrot.Bebop.Bebop(drone_type='Bebop2', ip_address=None)[source]

Bases: object

ask_for_state_update()[source]

Ask for a full state update (likely this should never be used but it can be called if you want to see everything the bebop is storing)

Returns:nothing but it will eventually fill the sensors with all of the state variables as they arrive
connect(num_retries)[source]

Connects to the drone and re-tries in case of failure the specified number of times. Seamlessly connects to either wifi or BLE depending on how you initialized it

Param:num_retries is the number of times to retry
Returns:True if it succeeds and False otherwise
disconnect()[source]

Disconnect the BLE connection. Always call this at the end of your programs to cleanly disconnect.

Returns:void
emergency_land()[source]

Sends the land command to the bebop on the high priority/emergency channel. Gets the codes for it from the xml files. Ensures the packet was received or sends it again up to a maximum number of times.

Returns:True if the command was sent and False otherwise
enable_geofence(value)[source]
If geofence is enabled, the drone won’t fly over the given max distance.

1 if the drone can’t fly further than max distance, 0 if no limitation on the drone should be done.

Parameters:value
Returns:
flat_trim(duration=0)[source]

Sends the flat_trim command to the bebop. Gets the codes for it from the xml files. :param duration: if duration is greater than 0, waits for the trim command to be finished or duration to be reached

flip(direction)[source]

Sends the flip command to the bebop. Gets the codes for it from the xml files. Ensures the packet was received or sends it again up to a maximum number of times. Valid directions to flip are: front, back, right, left

Returns:True if the command was sent and False otherwise
fly_direct(roll, pitch, yaw, vertical_movement, duration)[source]

Direct fly commands using PCMD. Each argument ranges from -100 to 100. Numbers outside that are clipped to that range.

Note that the xml refers to gaz, which is apparently french for vertical movements: http://forum.developer.parrot.com/t/terminology-of-gaz/3146

Parameters:
  • roll
  • pitch
  • yaw
  • vertical_movement
Returns:

is_landed()[source]

Returns true if it is landed or emergency and False otherwise :return:

land()[source]

Sends the land command to the bebop. Gets the codes for it from the xml files. Ensures the packet was received or sends it again up to a maximum number of times.

Returns:True if the command was sent and False otherwise
move_relative(dx, dy, dz, dradians)[source]

Move relative to our current position and pause until the command is done.

Parameters:
  • dx – change in front axis (meters)
  • dy – change in right/left (positive is right) (meters)
  • dz – change in height (positive is DOWN) (meters)
  • dradians – change in heading in radians
Returns:

nothing

pan_tilt_camera(tilt_degrees, pan_degrees)[source]

Send the command to pan/tilt the camera by the specified number of degrees in pan/tilt

Note, this only seems to work in small increments. Use pan_tilt_velocity to get the camera to look straight downward

Parameters:
  • tilt_degrees – tilt degrees
  • pan_degrees – pan degrees
Returns:

pan_tilt_camera_velocity(tilt_velocity, pan_velocity, duration=0)[source]

Send the command to tilt the camera by the specified number of degrees per second in pan/tilt. This function has two modes. First, if duration is 0, the initial velocity is sent and then the function returns (meaning the camera will keep moving). If duration is greater than 0, the command executes for that amount of time and then sends a stop command to the camera and then returns.

Parameters:
  • tilt_degrees – tile change in degrees per second
  • pan_degrees – pan change in degrees per second
  • duration – seconds to run the command for
Returns:

safe_land(timeout)[source]

Ensure the Bebop lands by sending the command until it shows landed on sensors

safe_takeoff(timeout)[source]

Sends commands to takeoff until the Bebop reports it is taking off

Parameters:timeout – quit trying to takeoff if it takes more than timeout seconds
set_exposition(value)[source]

Set image exposure

Parameters:value
Returns:
set_hull_protection(present)[source]

Set the presence of hull protection - this is only needed for bebop 1 1 if present, 0 if not present

Parameters:present
Returns:
set_indoor(is_outdoor)[source]

Set bebop 1 to indoor mode (not used in bebop 2!!) 1 if outdoor, 0 if indoor

Parameters:present
Returns:
set_max_altitude(altitude)[source]

Set max altitude in meters.

Parameters:altitude – altitude in meters
Returns:
set_max_distance(distance)[source]

Set max distance between the takeoff and the drone in meters.

Parameters:distance – distance in meters
Returns:
set_max_rotation_speed(speed)[source]

Set max yaw rotation speed in degree/s

Parameters:speed – max rotation speed for yaw in degree/s
Returns:
set_max_tilt(tilt)[source]

Set max pitch/roll in degrees

Parameters:tilt – max tilt for both pitch and roll in degrees
Returns:
set_max_tilt_rotation_speed(speed)[source]

Set max pitch/roll rotation speed in degree/s

Parameters:speed – max rotation speed for both pitch and roll in degree/s
Returns:
set_max_vertical_speed(speed)[source]

Set max vertical speed in m/s

Parameters:speed – max vertical speed in m/s
Returns:
set_picture_format(format)[source]

Set picture format

Parameters:format
Returns:
set_saturation(value)[source]

Set image saturation

Parameters:value
Returns:
set_timelapse(enable, interval=8)[source]

Set timelapse mode

Parameters:
  • enable
  • interval
Returns:

set_user_sensor_callback(function, args)[source]

Set the (optional) user callback function for sensors. Every time a sensor is updated, it calls this function.

Parameters:
  • function – name of the function
  • args – tuple of arguments to the function
Returns:

nothing

set_video_framerate(framerate)[source]

Set video framerate

Parameters:framerate
Returns:
set_video_recording(mode)[source]

Set video recording mode

Parameters:mode
Returns:
set_video_resolutions(type)[source]

Set video resolutions

Parameters:type
Returns:
set_video_stabilization(mode)[source]

Set video stabilization mode

Parameters:mode
Returns:
set_video_stream_mode(mode='low_latency')[source]

Set the video mode for the RTP stream. :param: mode: one of ‘low_latency’, ‘high_reliability’ or ‘high_reliability_low_framerate’

Returns:True if the command was sent and False otherwise
set_white_balance(type)[source]

Set white balance

Parameters:type
Returns:
smart_sleep(timeout)[source]

Don’t call time.sleep directly as it will mess up BLE and miss WIFI packets! Use this which handles packets received while sleeping

Parameters:timeout – number of seconds to sleep
start_video_stream()[source]

Sends the start stream command to the bebop. The bebop will start streaming RTP packets on the port defined in wifiConnection.py (55004 by default). The packets can be picked up by opening an approriate SDP file in a media player such as VLC, MPlayer, FFMPEG or OpenCV.

Returns:nothing
stop_video_stream()[source]

Sends the stop stream command to the bebop. The bebop will stop streaming RTP packets.

Returns:nothing
takeoff()[source]

Sends the takeoff command to the bebop. Gets the codes for it from the xml files. Ensures the packet was received or sends it again up to a maximum number of times.

Returns:True if the command was sent and False otherwise
update_sensors(data_type, buffer_id, sequence_number, raw_data, ack)[source]

Update the sensors (called via the wifi or ble connection)

Parameters:
  • data – raw data packet that needs to be parsed
  • ack – True if this packet needs to be ack’d and False otherwise
class pyparrot.Bebop.BebopSensors[source]

Bases: object

set_user_callback_function(function, args)[source]

Sets the user callback function (called everytime the sensors are updated)

Parameters:
  • function – name of the user callback function
  • args – arguments (tuple) to the function
Returns:

update(sensor_name, sensor_value, sensor_enum)[source]

pyparrot.DroneVision module

DroneVision is separated from the main Mambo/Bebop class to enable the use of the drone without the FPV camera. If you want to do vision processing, you will need to create a DroneVision object to capture the video stream.

Note that this module relies on the opencv module and the ffmpeg program

Ffmpeg write the images out to the images directory and then they are read in from the user thread. The DroneVisionGUI does not save copies of the images and instead shows you the images on the screen (they are saved to memory only). While you can see the images in real-time from this program using VisionServer, if you need copies of the images, you will want to use the ffmpeg approach. If you want a smaller delay on your image data for real-time control, you likely want to use libvlc and DroneVisionGUI.

Author: Amy McGovern, dramymcgovern@gmail.com

class pyparrot.DroneVision.DroneVision(drone_object, model, buffer_size=200, cleanup_old_images=True)[source]

Bases: object

close_video()[source]

Stop the vision processing and all its helper threads

get_latest_valid_picture()[source]

Return the latest valid image (from the buffer)

Returns:last valid image received from the Mambo
open_video()[source]

Open the video stream using ffmpeg for capturing and processing. The address for the stream is the same for all Mambos and is documented here:

http://forum.developer.parrot.com/t/streaming-address-of-mambo-fpv-for-videoprojection/6442/6

Remember that this will only work if you have connected to the wifi for your mambo!

Note that the old method tried to open the stream directly into opencv but there are known issues with rtsp streams in opencv. We bypassed opencv to use ffmpeg directly and then opencv is used to process the output of ffmpeg

:return True if the vision opened correctly and False otherwise

set_user_callback_function(user_callback_function=None, user_callback_args=None)[source]

Set the (optional) user callback function for handling the new vision frames. This is run in a separate thread that starts when you start the vision buffering

Parameters:
  • user_callback_function – function
  • user_callback_args – arguments to the function
Returns:

pyparrot.DroneVisionGUI module

DroneVisionGUI is a new class that parallels DroneVision but with several important changes.

  1. This module uses VLC instead of FFMPEG

2) This module opens a GUI window to show you the video in real-time (you could watch it in real-time previously through the VisionServer) 3) Because GUI windows are different on different OS’s (and in particular OS X behaves differently than linux and windows) and because they want to run in the main program thread, the way your program runs is different. You first open the GUI and then you have the GUI spawn a thread to run your program. 4) This module can use a virtual disk in memory to save the images, thus shortening the time delay for the camera for your programs.

Author: Amy McGovern, dramymcgovern@gmail.com Some of the LIBVLC code comes from Author: Valentin Benke, valentin.benke@aon.at

class pyparrot.DroneVisionGUI.DroneVisionGUI(drone_object, model, user_code_to_run, user_args, buffer_size=200, network_caching=200, fps=20, user_draw_window_fn=None)[source]

Bases: object

close_exit()[source]

Land, close the video, and exit the GUI :return:

close_video()[source]

Stop the vision processing and all its helper threads

get_latest_valid_picture()[source]

Return the latest valid image (from the buffer)

Returns:last valid image received from the Mambo
land()[source]

Send the land command over the emergency channel when the user pushes the button

Returns:
land_close_exit()[source]

Called if you Quit the GUI: lands the drone, stops vision, and exits the GUI :return:

open_video()[source]

Open the video stream using vlc. Note that this version is blocking meaning this function will NEVER return. If you want to run your own code and not just watch the video, be sure you set your user code in the constructor!

Remember that this will only work if you have connected to the wifi for your mambo!

:return never returns due to QT running in the main loop by requirement

run_user_code(button)[source]

Start the thread to run the user code :return:

set_user_callback_function(user_callback_function=None, user_callback_args=None)[source]

Set the (optional) user callback function for handling the new vision frames. This is run in a separate thread that starts when you start the vision buffering

Parameters:
  • user_callback_function – function
  • user_callback_args – arguments to the function
Returns:

pyparrot.Minidrone module

Mambo class holds all of the methods needed to pilot the drone from python and to ask for sensor data back from the drone

Author: Amy McGovern, dramymcgovern@gmail.com Author: Alexander Zach, https://github.com/alex-zach, groundcam support Author: Valentin Benke, https://github.com/Vabe7, groundcam support

class pyparrot.Minidrone.Mambo(address='', use_wifi=False)[source]

Bases: pyparrot.Minidrone.Minidrone

disconnect()[source]

Disconnect the BLE connection. Always call this at the end of your programs to cleanly disconnect.

Returns:void
fire_gun()[source]

Fire the gun (assumes it is attached) - note not supposed under wifi since the camera takes the place of the gun

Returns:True if the command was sent and False otherwise (can include errors or asking to do this using wifi)
class pyparrot.Minidrone.MamboGroundcam[source]

Bases: object

get_groundcam_picture(filename, cv2_flag)[source]

Downloads the specified picture from the Mambo and stores it into a tempfile.

Parameters:
  • filename – the name of the file which should be downloaded ON THE MAMBO.
  • cv2_flag – if true this function will return a cv2 image object, if false the name of the temporary file will be returned

:return False if there was an error during download, if cv2 is True a cv2 frame or it just returns the file name of the temporary file

get_groundcam_pictures_names()[source]

Retruns a list with the names of the pictures stored on the Mambo. :return The list as an array, if there isn’t any file, the array is empty.

class pyparrot.Minidrone.Minidrone(address='', use_wifi=False)[source]

Bases: object

ask_for_state_update()[source]

Ask for a full state update (likely this should never be used but it can be called if you want to see everything the mambo is storing)

Returns:nothing but it will eventually fill the MamboSensors with all of the state variables as they arrive
change_mode()[source]
change_preferred_mode(mode='easy')[source]
close_claw()[source]

Close the claw - note not supposed under wifi since the camera takes the place of the claw

Returns:True if the command was sent and False otherwise (can include errors or asking to do this using wifi)
connect(num_retries)[source]

Connects to the drone and re-tries in case of failure the specified number of times. Seamlessly connects to either wifi or BLE depending on how you initialized it

Param:num_retries is the number of times to retry
Returns:True if it succeeds and False otherwise
emergency()[source]

Sends the emergency command to the mambo. Gets the codes for it from the xml files. Ensures the packet was received or sends it again up to a maximum number of times.

Returns:True if the command was sent and False otherwise
flat_trim()[source]

Sends the flat_trim command to the mambo. Gets the codes for it from the xml files.

flip(direction)[source]

Sends the flip command to the mambo. Gets the codes for it from the xml files. Ensures the packet was received or sends it again up to a maximum number of times. Valid directions to flip are: front, back, right, left

Returns:True if the command was sent and False otherwise
fly_direct(roll, pitch, yaw, vertical_movement, duration=None)[source]

Direct fly commands using PCMD. Each argument ranges from -100 to 100. Numbers outside that are clipped to that range.

Note that the xml refers to gaz, which is apparently french for vertical movements: http://forum.developer.parrot.com/t/terminology-of-gaz/3146

duration is optional: if you want it to fly for a specified period of time, set this to the number of seconds (fractions are fine) or use None to send the command once. Note, if you do this, you will need an outside loop that sends lots of commands or your drone will not fly very far. The command is not repeated inside the drone. it executes once and goes back to hovering without new commands coming in. But the option of zero duration allows for smoother flying if you want to do the control loop yourself.

Parameters:
  • roll – roll speed in -100 to 100
  • pitch – pitch speed in -100 to 100
  • yaw – yaw speed in -100 to 100
  • vertical_movement – vertical speed in -100 to 100
  • duration – optional: seconds for a specified duration or None to send it once (see note above)
Returns:

hover()[source]

Sends the command execute a flat trim to the mambo. This is basically a hover command. Gets the codes for it from the xml files. Ensures the packet was received or sends it again up to a maximum number of times.

Returns:True if the command was sent and False otherwise
is_landed()[source]

Returns true if it is landed or emergency and False otherwise :return:

land()[source]

Sends the land command to the mambo. Gets the codes for it from the xml files. Ensures the packet was received or sends it again up to a maximum number of times.

Returns:True if the command was sent and False otherwise
open_claw()[source]

Open the claw - note not supposed under wifi since the camera takes the place of the claw

Returns:True if the command was sent and False otherwise (can include errors or asking to do this using wifi)
safe_emergency(timeout)[source]

Sends emergency stop command until the Mambo reports it is not flying anymore

Parameters:timeout – quit trying to emergency stop if it takes more than timeout seconds
safe_land(timeout)[source]

Ensure the mambo lands by sending the command until it shows landed on sensors

safe_takeoff(timeout)[source]

Sends commands to takeoff until the mambo reports it is taking off

Parameters:timeout – quit trying to takeoff if it takes more than timeout seconds
set_max_tilt(value)[source]

Sets the maximum tilt in degrees. Ensures you only set positive values.

Parameters:value – maximum tilt in degrees
Returns:True if the command was sent and False otherwise
set_max_vertical_speed(value)[source]

Sets the maximum vertical speed in m/s. Unknown what the true maximum is but we do ensure you only set positive values.

Parameters:value – maximum speed
Returns:True if the command was sent and False otherwise
set_user_sensor_callback(function, args)[source]

Set the (optional) user callback function for sensors. Every time a sensor is updated, it calls this function.

Parameters:
  • function – name of the function
  • args – tuple of arguments to the function
Returns:

nothing

smart_sleep(timeout)[source]

Don’t call time.sleep directly as it will mess up BLE and miss WIFI packets! Use this which handles packets received while sleeping

Parameters:timeout – number of seconds to sleep
take_picture()[source]

Ask the drone to take a picture also checks how many frames are on there, if there are ore than 35 it deletes one If connected via Wifi it If it is connected via WiFi it also deletes all frames on the Mambo once there are more than 35, since after there are 40 the next ones are ignored :return: True if the command was sent and False otherwise

takeoff()[source]

Sends the takeoff command to the mambo. Gets the codes for it from the xml files. Ensures the packet was received or sends it again up to a maximum number of times.

Returns:True if the command was sent and False otherwise
turn_degrees(degrees)[source]

Turn the mambo the specified number of degrees (-180, 180). Degrees must be an integere so it is cast to an integer here. If you send it a float, it will be rounded according to the rules of int()

This is called cap in the xml but it means degrees per http://forum.developer.parrot.com/t/what-does-cap-stand-for/6213/2

Parameters:degrees – degrees to turn (-180 to 180)
Returns:True if the command was sent and False otherwise
turn_on_auto_takeoff()[source]

Turn on the auto take off (throw mode) :return: True if the command was sent and False otherwise

update_sensors(data_type, buffer_id, sequence_number, raw_data, ack)[source]

Update the sensors (called via the wifi or ble connection)

Parameters:
  • data – raw data packet that needs to be parsed
  • ack – True if this packet needs to be ack’d and False otherwise
class pyparrot.Minidrone.MinidroneSensors[source]

Bases: object

Store the minidrone’s last known sensor values

get_estimated_z_orientation()[source]

Uses the quaternions to return an estimated orientation

Learn more about unit quaternions here:

https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

NOTE: This is not a real compass heading. 0 degrees is where you are facing when the mambo turns on!

Returns:
quaternion_to_euler_angle(w, x, y, z)[source]

This code is directly from:

https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles

Parameters:
  • x
  • y
  • z
Returns:

set_user_callback_function(function, args)[source]

Sets the user callback function (called everytime the sensors are updated)

Parameters:
  • function – name of the user callback function
  • args – arguments (tuple) to the function
Returns:

update(name, value, sensor_enum)[source]

Update the sensor

Parameters:
  • name – name of the sensor to update
  • value – new value for the sensor
  • sensor_enum – enum list for the sensors that use enums so that we can translate from numbers to strings
Returns:

class pyparrot.Minidrone.Swing(address='', use_wifi=False)[source]

Bases: pyparrot.Minidrone.Minidrone

disconnect()[source]

Disconnect the BLE connection. Always call this at the end of your programs to cleanly disconnect.

Returns:void
set_flying_mode(mode)[source]

Set drone flying mode

Parameters:state
Returns:
set_plane_gear_box(state)[source]

Set plane gear box

Parameters:state
Returns:

pyparrot.VisionServer module

This is a simple web server to let the user see the vision that is being processed by ffmpeg. It essentially replaces the role of VLC. Note that there are several user parameters that should be set to run this program.

This does not replace the vision process! This is a separate process just to run a web server that lets you see what the mambo is seeing.

orig author: Igor Maculan - n3wtron@gmail.com A Simple mjpg stream http server

Updated for python3 including png streaming and graceful error handling - Taner Davis

pyparrot.VisionServer.HOST_NAME = '127.0.0.1'

The port youd like to stream to locally. Unless you have a strong reason to change this, keep this as 9090.

pyparrot.VisionServer.IMAGE_PATH = '/Users/amy/repos/pyparrot/images/image_%03d.png'

The URL or website name you would like to stream to. Unless you have a strong reason to change this, keep this as “127.0.0.1”

pyparrot.VisionServer.PORT_NUMBER = 9090
Set this according to how we want to stream:
Stream in color -> >0 (1, 2, 873, etc.) Stream in black and white -> 0 Stream in color with transparency -> <0 (-1, -6, -747, etc.)
pyparrot.VisionServer.main()[source]

Builds an http page to see images in a stream as they are created in the IMAGE_PATH specified above.

Module contents