Introduction to Python SDK

Python SDK Overview

The Python SDK provided with the XFly Drone is designed for advanced users who want to automate various drone functionalities. 


Central to this SDK is the main.py file, which acts as the entry point for operational scripts. Other critical files, such as commander.py, communicator.py, handGesture.py, keyboard.py, packetGenerator.py, and validation.py, contain essential functions that are tightly integrated with the drone’s firmware.

 

Key Recommendations for Using the Python SDK

Users are advised to focus on the main.py for customization and refrain from altering the other files. These files are specifically created to ensure seamless communication with the drone’s firmware, enabling the precise execution of commands as defined within the SDK. Any modifications to these files could disrupt the drone’s operation and are therefore not recommended without a thorough understanding of the underlying code and the drone’s architecture.

Please handle the SDK with caution and ensure any changes made to the main.py are tested in a controlled environment to prevent any unintended behavior during the drone’s flight.

Connecting to the Drone’s Wi-Fi

To connect to your drone’s Wi-Fi network, please follow these steps:

  1. On your device, open the Wi-Fi settings.
  2. Look for the network named “QubeBots Xfly” in the list of available networks.
  3. Select “QubeBots Xfly” from the list.
  4. When prompted for a password, enter “12345678” (without quotes).
  5. Wait for the connection to be established. You should see a confirmation that you are connected, although it may indicate ‘No internet, secured’ which is typical for direct connections to devices like drones that do not offer internet access.

After connecting to the drone’s Wi-Fi network, you can proceed with any further instructions or use the SDK to control the drone as intended.

Key Functionalities in main.py for Drone Operation

The main.py module serves as the entry point for controlling the drone through various high-level functions. It utilizes the validation.py functions to ensure that the inputs for each command are within acceptable ranges and formats before execution. Below are descriptions of key functions that can be integrated into main.py for drone operation:

  • manualModeFlying(thrust, roll, pitch, yaw_rate): Engages manual flight mode, allowing direct control over the drone’s movement through thrust, roll, pitch, and yaw rate inputs. Each parameter is first validated to be within safe operational limits.
    • Inputs:
      • thrust (int): The power of the drone’s ascent or descent, within a range of 0 to 100.
      • roll (int): The drone’s left or right tilt angle, ranging from -80 to 80 degrees.
      • pitch (int): The drone’s forward or backward tilt angle, ranging from -80 to 80 degrees.
      • yaw_rate (int): The rate of rotation around the drone’s vertical axis, between -100 to 100.
 
  • altitudeHoldFlying(set_height, roll, pitch, yaw_rate): Activates altitude hold mode, allowing the drone to maintain a specified altitude while responding to roll, pitch, and yaw rate commands.
    • Inputs:
      • set_height (float): The desired altitude for the drone to hold, between 0.0 to 2.0 meters.
      • roll (int): The roll angle input as described above.
      • pitch (int): The pitch angle input as described above.
      • yaw_rate (int): The yaw rate input as described above.
 
  • takeoff(set_height): Initiates the drone’s takeoff sequence, automatically ascending to a specified height.
    • Input:
      • set_height (float, optional): The target altitude for takeoff, defaulting to 0.5 meters if not specified.
 
  • land(): Commands the drone to initiate the landing sequence and safely descend to the ground.
 
  • setHeight(set_height): Sets the drone’s flight height to a specified value. It uses the same altitude hold principles.
    • Input:
      • set_height (float): The desired altitude for the drone to reach, which must be between 0.0 to 2.0 meters.
 
  • goForward(set_vel, set_time)goBackward(set_vel, set_time)goLeft(set_vel, set_time)goRight(set_vel, set_time): Directs the drone to move linearly in the specified direction using the given velocity and for the specified time.
    • Inputs:
      • set_vel (float|int): The velocity at which the drone should move.
      • set_time (float): The duration for which the movement should be maintained.
 
  • rotateLeft(angle)rotateRight(angle): Commands the drone to rotate left or right by a specific angle.
    • Input:
      • angle (int): The angle through which the drone should rotate.
 
  • setPID(type, KP, KI, KD): Configures the drone’s PID controller values for precise control over its flight dynamics.
    • Inputs:
      • type (string): The aspect of flight to be controlled, such as ‘Roll’, ‘Pitch’, or ‘Yaw’.
      • KP (float): The proportional gain for the PID controller.
      • KI (float): The integral gain for the PID controller.
      • KD (float): The derivative gain for the PID controller.

Additional Functionalities

 
  • verifyByLED(): This function, part of the commander module, likely triggers an LED sequence on the drone to indicate status or confirmation of connection. It doesn’t require any input parameters.
 
  • keyboardController(angle, yaw_rate): A function from the keyboard module that allows for drone control using keyboard inputs. It takes two parameters:
    • angle (int): The angle increment for roll and pitch adjustments based on keyboard input.
    • yaw_rate (int): The rate of yaw change when turning left or right with the keyboard.
 
  • handGestureController(angle, yaw_rate): Part of the handGesture module, this function enables the drone to be controlled by hand gestures, interpreted through a camera and computer vision algorithms. It also accepts two parameters:
    • angle (int): The angle increment used for translating hand gestures into pitch and roll commands.
    • yaw_rate (int): The rate at which the drone will yaw left or right in response to hand gestures.
 
  • packetMonitor(duration): A function from the communicator module that listens for incoming data packets from the drone for a specified duration and prints them to the console, which can be used for debugging and monitoring communication with the drone.
    • duration (float): The time in seconds that the packet monitor will listen for and print incoming packets.
 
  • The commented-out lines indicate potential sequences of commands that could be sent to the drone, such as taking off to a specific height, moving in various directions, and landing. These commands are interspersed with calls to packetMonitor to observe the communication packets, and time.sleep(2) to introduce delays in the sequence for timing purposes.
 
  • sys.exit(): This is a standard Python function to exit from Python. It’s typically used to stop the program after completing a sequence of operations or in case of an error or exception.

QubeBots Pvt Ltd is a startup that focuses on developing Edutech products to support the global STEM Education system.

Contact us

hello@qubebots.com

+94 77 069 5151

Colombo, Sri Lanka

Shopping Cart
Scroll to Top