Skip to content

Configuration

Lupin3000 edited this page Mar 29, 2025 · 8 revisions

This Python solution uses 2 different libraries to communicate with the controllers.

  • macOS: hidapi
  • Linux: evdev

Therefore the controllers are configured differently for both systems!

Controller configuration

In the config folder you will find examples of predefined controllers. However, you can change/adjust existing configurations and add new ones.

Python evdev

If you use Python evdev, you can find out the controller configuration very quickly with just one command!

# get controller configuration
(venv) $ python3 -m evdev.evtest

For more details, create a tiny script:

from evdev import InputDevice


# the path can be different
DEVICE_PATH: str = '/dev/input/event8'


if __name__ == "__main__":
    controller = InputDevice(DEVICE_PATH)
    print(controller.capabilities(verbose=True))

evdev template

[Identification]
name = <str>

[Buttons]
# Button assignment
btn_takeoff_value = <int>
btn_landing_value = <int>
btn_photo_value = <int>

[AnalogSticks]
# Analog stick assignment
analog_middle_value = <int>
analog_threshold_value = <int>
analog_left_x_index = <str>
analog_left_y_index = <str>
analog_right_x_index = <str>
analog_right_y_index = <str>

Python hidapi

To find vendor and product ids, list all hid devices.

from hid import enumerate


if __name__ == "__main__":
    for device in enumerate():
        print(device)

Now you can create an other Python script (with correct values for constants) and collect configuration values.

from signal import signal, SIGINT
from hid import device
from sys import exit
from time import sleep
from types import FrameType
from typing import Optional


VENDOR: int = 6353
PRODUCT: int = 37888
REPORT_LENGTH: int = 64
DELAY: float = 0.25


def signal_handler(sig: int, frame: Optional[FrameType]) -> None:
    """
    Handles incoming system signals and raises always an KeyboardInterrupt.

    :param sig: The signal number.
    :type sig: int
    :param frame: The current stack frame.
    :type frame: Optional[FrameType]
    :return: None
    """
    _ = frame

    print(f'[INFO] Signal "{sig}" received.')
    raise KeyboardInterrupt


if __name__ == '__main__':
    signal(SIGINT, signal_handler)

    controller = None

    try:
        controller = device()
        controller.open(VENDOR, PRODUCT)
        controller.set_nonblocking(True)
        controller_name = controller.get_product_string()
        controller_manufacturer = controller.get_manufacturer_string()
        print(f'[INFO] Connected with "{controller_name}" controller from "{controller_manufacturer}".')
    except Exception as err:
        print(f'[ERROR] Failed to connect to controller: {err}')
        exit(1)

    try:
        while True:
            data = controller.read(REPORT_LENGTH)

            if data:
                print(data)

            sleep(DELAY)
    except KeyboardInterrupt:
        print('[INFO] Application stopped by user.')
    finally:
        controller.close()

hidapi template

[Identification]
vendor = <int>
product = <int>

# Max value from report buffer
report_length = <int>

[Buttons]
# Button assignment
btn_byte_index = <int>
btn_takeoff_value = <int>
btn_landing_value = <int>
btn_photo_value = <int>

[AnalogSticks]
# Analog stick assignment
analog_middle_value = <int>
analog_threshold_value = <int>
analog_left_x_index = <int>
analog_left_y_index = <int>
analog_right_x_index = <int>
analog_right_y_index = <int>

Constants

Inside file main.py you can modify following constants:

  • CONTROLLER_CONFIG: name of configuration file inside directory config/ (which controller you use to fly).
  • SPEED: integer value between 1 and 100 (the higher the value, the faster the drone flies).
  • STREAM: True to fly with HUD (video stream on) or False for no HUD (video stream off).
  • WINDOW_NAME: Title of HUD (video stream) window.

You should not change the values of the constants DELAY and SHUTDOWN. This can cause problems if you don't know 100% what you are changing.

Set STREAM to False on headless systems or if screen resolution is smaller height: 720px width: 960px.

Clone this wiki locally