pyparrot.networking package¶
Submodules¶
pyparrot.networking.bleConnection module¶
-
class
pyparrot.networking.bleConnection.
BLEConnection
(address, minidrone)[source]¶ Bases:
object
-
ack_packet
(buffer_id, packet_id)[source]¶ Ack the packet id specified by the argument on the ACK_COMMAND channel
Parameters: packet_id – the packet id to ack Returns: nothing
-
connect
(num_retries)[source]¶ Connects to the drone and re-tries in case of failure the specified number of times
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
-
send_auto_takeoff_command
(command_tuple)[source]¶ Build the packet for auto takeoff and send it
Parameters: command_tuple – command tuple from the parser Returns: True if the command was sent and False otherwise
-
send_command_packet_ack
(packet)[source]¶ Sends the actual packet on the ack channel. Internal function only.
Parameters: packet – packet constructed according to the command rules (variable size, constructed elsewhere) Returns: True if the command was sent and False otherwise
-
send_enum_command_packet_ack
(command_tuple, enum_value, usb_id=None)[source]¶ Send a command on the ack channel with enum parameters as well (most likely a flip). All commandsandsensors except PCMD go on the ack channel per http://forum.developer.parrot.com/t/ble-characteristics-of-minidrones/5912/2
the id of the last command sent (for use in ack) is the send counter (which is incremented before sending)
Parameters: - command_tuple – 3 tuple of the command bytes. 0 padded for 4th byte
- enum_value – the enum index
Returns: nothing
-
send_noparam_command_packet_ack
(command_tuple)[source]¶ Send a command on the ack channel - where all commandsandsensors except PCMD go, per http://forum.developer.parrot.com/t/ble-characteristics-of-minidrones/5912/2
the id of the last command sent (for use in ack) is the send counter (which is incremented before sending)
Ensures the packet was received or sends it again up to a maximum number of times.
Parameters: command_tuple – 3 tuple of the command bytes. 0 padded for 4th byte Returns: True if the command was sent and False otherwise
-
send_param_command_packet
(command_tuple, param_tuple=None, param_type_tuple=0, ack=True)[source]¶ Send a command packet with parameters. Ack channel is optional for future flexibility, but currently commands are always send over the Ack channel so it defaults to True.
Contributed by awm102 on github. Edited by Amy McGovern to work for BLE commands also.
Param: command_tuple: the command tuple derived from command_parser.get_command_tuple() Param: param_tuple (optional): the parameter values to be sent (can be found in the XML files) Param: param_size_tuple (optional): a tuple of strings representing the data type of the parameters e.g. u8, float etc. (can be found in the XML files) :param: ack (optional): allows ack to be turned off if required :return:
-
send_pcmd_command
(command_tuple, roll, pitch, yaw, vertical_movement, duration)[source]¶ Send the PCMD command with the specified roll, pitch, and yaw
Parameters: - command_tuple – command tuple per the parser
- roll –
- pitch –
- yaw –
- vertical_movement –
- duration –
-
send_single_pcmd_command
(command_tuple, roll, pitch, yaw, vertical_movement)[source]¶ Send a single PCMD command with the specified roll, pitch, and yaw. Note this will not make that command run forever. Instead it sends ONCE. This can be used in a loop (in your agent) that makes more smooth control than using the duration option.
Parameters: - command_tuple – command tuple per the parser
- roll –
- pitch –
- yaw –
- vertical_movement –
-
send_turn_command
(command_tuple, degrees)[source]¶ Build the packet for turning and send it
Parameters: - command_tuple – command tuple from the parser
- degrees – how many degrees to turn
Returns: True if the command was sent and False otherwise
-
smart_sleep
(timeout)[source]¶ Sleeps the requested number of seconds but wakes up for notifications
Note: NEVER use regular time.sleep! It is a blocking sleep and it will likely cause the BLE to disconnect due to dropped notifications. Always use smart_sleep instead!
Parameters: timeout – number of seconds to sleep Returns:
-
pyparrot.networking.wifiConnection module¶
Holds all the data and commands needed to fly a Bebop or Anafi drone.
Author: Amy McGovern, dramymcgovern@gmail.com
-
class
pyparrot.networking.wifiConnection.
WifiConnection
(drone, drone_type='Bebop2', ip_address=None)[source]¶ Bases:
object
-
ack_packet
(buffer_id, packet_id)[source]¶ Ack the packet id specified by the argument on the ACK_COMMAND channel
Parameters: packet_id – the packet id to ack Returns: nothing
-
connect
(num_retries)[source]¶ Connects to the drone
Parameters: num_retries – maximum number of retries Returns: True if the connection succeeded and False otherwise
-
handle_data
(data)[source]¶ Handles the data as it comes in
Parameters: data – raw data packet Returns:
-
send_camera_move_command
(command_tuple, pan, tilt)[source]¶ Send the packet to move the camera (this is Bebop only).
Parameters: - command_tuple – command tuple per the parser
- pan –
- tilt –
-
send_command_packet_ack
(packet, seq_id)[source]¶ Sends the actual packet on the ack channel. Internal function only.
Parameters: packet – packet constructed according to the command rules (variable size, constructed elsewhere) Returns: True if the command was sent and False otherwise
-
send_command_packet_noack
(packet)[source]¶ Sends the actual packet on the No-ack channel. Internal function only.
Parameters: packet – packet constructed according to the command rules (variable size, constructed elsewhere) Returns: True if the command was sent and False otherwise
-
send_enum_command_packet_ack
(command_tuple, enum_value, usb_id=None)[source]¶ Send a command on the ack channel with enum parameters as well (most likely a flip). All commandsandsensors except PCMD go on the ack channel per http://forum.developer.parrot.com/t/ble-characteristics-of-minidrones/5912/2
the id of the last command sent (for use in ack) is the send counter (which is incremented before sending)
Parameters: - command_tuple – 3 tuple of the command bytes. 0 padded for 4th byte
- enum_value – the enum index
Returns: nothing
-
send_fly_relative_command
(command_tuple, change_x, change_y, change_z, change_angle)[source]¶ Send the packet to fly relative (this is Bebop only).
Parameters: - command_tuple – command tuple per the parser
- change_x – change in x
- change_y – change in y
- change_z – change in z
- change_angle – change in angle
-
send_noparam_command_packet_ack
(command_tuple)[source]¶ Send a no parameter command packet on the ack channel :param command_tuple: :return:
-
send_noparam_high_priority_command_packet
(command_tuple)[source]¶ Send a no parameter command packet on the high priority channel :param command_tuple: :return:
-
send_param_command_packet
(command_tuple, param_tuple=None, param_type_tuple=0, ack=True)[source]¶ Send a command packet with parameters. Ack channel is optional for future flexibility, but currently commands are always send over the Ack channel so it defaults to True.
Contributed by awm102 on github
Param: command_tuple: the command tuple derived from command_parser.get_command_tuple() Param: param_tuple (optional): the parameter values to be sent (can be found in the XML files) Param: param_size_tuple (optional): a tuple of strings representing the data type of the parameters e.g. u8, float etc. (can be found in the XML files) :param: ack (optional): allows ack to be turned off if required :return:
-
send_pcmd_command
(command_tuple, roll, pitch, yaw, vertical_movement, duration)[source]¶ Send the PCMD command with the specified roll, pitch, and yaw
Parameters: - command_tuple – command tuple per the parser
- roll –
- pitch –
- yaw –
- vertical_movement –
- duration –
-
send_single_pcmd_command
(command_tuple, roll, pitch, yaw, vertical_movement)[source]¶ Send a single PCMD command with the specified roll, pitch, and yaw. Note this will not make that command run forever. Instead it sends ONCE. This can be used in a loop (in your agent) that makes more smooth control than using the duration option.
Parameters: - command_tuple – command tuple per the parser
- roll –
- pitch –
- yaw –
- vertical_movement –
-
send_turn_command
(command_tuple, degrees)[source]¶ Build the packet for turning and send it
Parameters: - command_tuple – command tuple from the parser
- degrees – how many degrees to turn
Returns: True if the command was sent and False otherwise
-
smart_sleep
(timeout)[source]¶ Sleeps the requested number of seconds but wakes up for notifications
Note: time.sleep misbehaves for the BLE connections but seems ok for wifi. I encourage you to use smart_sleep since it handles the sleeping in a thread-safe way.
Parameters: timeout – number of seconds to sleep Returns:
-