Skip to main content

Flix Python library

The Flix Python library allows you to remotely connect to a Flix quadcopter. It provides access to telemetry data, supports executing console commands, and controlling the drone's flight.

To use the library, connect to the drone's Wi-Fi. To use it with the simulator, ensure the script runs on the same network as the simulator.

Installation

If you have cloned the repo, install the library from the repo:

cd /path/to/flix/repo
pip install -e tools

Alternatively, install from pip:

pip install pyflix

Usage

The API is accessed through the Flix class:

from pyflix import Flix
flix = Flix()  # create a Flix object and wait for connection

If using ESP-NOW connection, specify the proxy device name in FLIX_DEVICE environment variable or pass it to the constructor: Flix(device='/dev/cu.usbserial-0001').

Telemetry

Basic telemetry is available through object properties. The property names generally match the corresponding variables in the firmware code:

print(flix.connected)       # True if connected to the drone
print(flix.mode)            # current flight mode (str)
print(flix.armed)           # True if the drone is armed
print(flix.landed)          # True if the drone is landed
print(flix.voltage)         # battery voltage (NaN - unknown, ~0 - USB powered)
print(flix.attitude)        # attitude quaternion [w, x, y, z]
print(flix.attitude_euler)  # attitude as Euler angles [roll, pitch, yaw]
print(flix.rates)           # angular rates [roll_rate, pitch_rate, yaw_rate]
print(flix.channels)        # raw RC channels (list)
print(flix.motors)          # motor outputs (list)
print(flix.acc)             # accelerometer output (list)
print(flix.gyro)            # gyroscope output (list)

The library uses the Front-Left-Up coordinate system — the same as the firmware:

All angles are in radians.

Events

The Flix object implements the Observable pattern, allowing to listen for events. You can subscribe to events using on method:

flix.on('connected', lambda: print('Connected to Flix'))
flix.on('disconnected', lambda: print('Disconnected from Flix'))
flix.on('print', lambda text: print(f'Flix says: {text}'))

Unsubscribe from events using off method:

flix.off('print')  # unsubscribe from print events
flix.off(callback)  # unsubscribe specific callback

You can also wait for specific events using wait method. This method returns the data associated with the event:

gyro = flix.wait('gyro')  # wait for gyroscope update
attitude = flix.wait('attitude', timeout=3)  # wait for attitude update, raise TimeoutError after 3 seconds

The second argument (value) specifies a condition for filtering events. It can be either an expected value or a callable:

flix.wait('armed', True)  # wait until armed
flix.wait('armed', False)  # wait until disarmed
flix.wait('mode', 'AUTO')  # wait until flight mode is switched to AUTO
flix.wait('motors', lambda motors: not any(motors))  # wait until all motors stop
flix.wait('attitude_euler', lambda att: att[0] > 0)  # wait until roll angle is positive

Full list of events:

Event Description Associated data
connected Connected to the drone
disconnected Connection is lost
armed Armed state update Armed state (bool)
mode Flight mode update Flight mode (str)
landed Landed state update Landed state (bool)
voltage Battery voltage update Voltage (float)
print The drone prints text to the console Text
attitude Attitude update Attitude quaternion (list)
attitude_euler Attitude update Euler angles (list)
rates Angular rates update Angular rates (list)
channels Raw RC channels update Raw RC channels (list)
motors Motor outputs update Motor outputs (list)
acc Accelerometer update Accelerometer output (list)
gyro Gyroscope update Gyroscope output (list)
mavlink Received MAVLink message Message object
mavlink.<message_name> Received specific MAVLink message Message object
mavlink.<message_id> Received specific MAVLink message Message object
value Named value update (see below) Name, value
value.<name> Specific named value update (see below) Value

Basic methods

Get and set firmware parameters using get_param and set_param methods:

pitch_p = flix.get_param('CTL_ATT_P_P')  # get parameter value
flix.set_param('CTL_ATT_P_P', 5)         # set parameter value

Execute console commands using cli method. This method returns the command response:

imu = flix.cli('imu')    # get detailed IMU data
time = flix.cli('time')  # get detailed time data
flix.cli('reboot')       # reboot the drone

You can arm and disarm the drone using set_armed method (warning: the drone will fall if disarmed in the air):

flix.set_armed(True)   # arm the drone
flix.set_armed(False)  # disarm the drone

You can pass pilot's controls using set_controls method:

flix.set_controls(roll=0, pitch=0, yaw=0, throttle=0.6)

Automatic flight

To perform automatic flight, switch the mode to AUTO, either from the remote control, or from the code:

flix.set_mode('AUTO')

In this mode you can set flight control targets. Setting attitude target:

flix.set_attitude([0.1, 0.2, 0.3], 0.6)  # set target roll, pitch, yaw and thrust
flix.set_attitude([1, 0, 0, 0], 0.6)  # set target attitude quaternion and thrust

Setting angular rates target:

flix.set_rates([0.1, 0.2, 0.3], 0.6)  # set target roll rate, pitch rate, yaw rate and thrust

You also can control raw motor outputs directly:

flix.set_motors([0.5, 0.5, 0.5, 0.5])  # set motor outputs in range [0, 1]

In AUTO mode, the drone will arm automatically if the thrust is greater than zero, and disarm if thrust is zero. Therefore, to disarm the drone, set thrust to zero:

flix.set_attitude([0, 0, 0], 0)  # disarm the drone

The following methods are in development and are not functional yet:

  • set_position — set target position.
  • set_velocity — set target velocity.

To exit AUTO mode move control sticks and the drone will switch to STAB mode.

Additional methods

LED control

You can control the onboard LED (and the connected RGB LED strip) using set_led method:

flix.set_led(True)  # turn on single onboard LED
flix.set_led(False)  # turn off single onboard LED
flix.set_led((255, 0, 0))  # control single RGB LED
flix.set_led(((0, 255, 0, 0), (1, 0, 255, 0), (2, 0, 0, 255))) # control multiple RGB LEDs
flix.cli('led rainbow')  # control LED strip using console command

See the led.py script as an example of RGB LED strip control.

Usage alongside QGroundControl

You can use the Flix library alongside the QGroundControl app, using proxy mode. To do that:

  1. Run proxy for pyflix and QGroundControl in background:

    flix-proxy
    
  2. Go to QGroundControl settings ⇒ Comm Links.

  3. Add new link with the following settings:

    • Name: Proxy
    • Automatically Connect on Start: ✓
    • Type: UDP
    • Port: 14560
  4. Restart QGroundControl.

Now you can run pyflix scripts and QGroundControl simultaneously.

Tools

The following scripts demonstrate how to use the library:

  • cli.py — remote access to the drone's command line interface.
  • log.py — download flight logs from the drone.
  • example.py — a simple example, prints telemetry data and waits for events.

Advanced usage

You can access the most recently received messages using messages property:

print(flix.messages.get('HEARTBEAT'))  # print the latest HEARTBEAT message

You can wait for a specific message using wait method:

heartbeat = flix.wait('mavlink.HEARTBEAT')

You can send raw messages using mavlink property:

from pymavlink.dialects.v20 import common as mavlink

flix.mavlink.heartbeat_send(mavlink.MAV_TYPE_GCS, mavlink.MAV_AUTOPILOT_INVALID,
                            mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED, 0, 0)

Named values

You can pass arbitrary named values from the firmware to the Python script using NAMED_VALUE_FLOAT, NAMED_VALUE_INT, DEBUG, DEBUG_VECT, and DEBUG_FLOAT_ARRAY MAVLink messages.

All these named values will appear in the values dictionary:

print(flix.values['some_value'])
print(flix.values['some_vector'])

You can send values from the firmware like this (mavlink.ino):

// Send float named value
mavlink_msg_named_value_float_pack(SYSTEM_ID, MAV_COMP_ID_AUTOPILOT1, &msg, t, "loop_rate", loopRate);
sendMessage(&msg);

// Send vector named value
mavlink_msg_debug_vect_pack(SYSTEM_ID, MAV_COMP_ID_AUTOPILOT1, &msg, "gyro_bias", t, gyroBias.x, gyroBias.y, gyroBias.z);
sendMessage(&msg);

Logging

You can control Flix library verbosity using Python's logging module:

import logging

logger = logging.getLogger('flix')
logger.setLevel(logging.DEBUG)  # be more verbose
logger.setLevel(logging.WARNING)  # be less verbose

Metadata

Release files for pyflix 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyflix 1.1.0
File Size Uploaded Provenance Actions
pyflix-1.1.0.tar.gz 14.0 kB Without provenance Details for pyflix-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyflix 1.1.0
File Interpreter ABI Platform Actions
pyflix-1.1.0-py3-none-any.whl Python 3 none any Details for pyflix-1.1.0-py3-none-any.whl

Total release size: 29.1 kB

Release files / pyflix-1.1.0.tar.gz

Download URL pyflix-1.1.0.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d0d866d476e11755c16f3c059b95783888d67de9e497b9dfb0112d147cd9203a
BLAKE2b-256 checksum
How to use checksums
0bb3a0070f973aaf7f44166026393003ef9ccdb81f074eaebd450c8fcafdc5cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.11

Release files / pyflix-1.1.0-py3-none-any.whl

Download URL pyflix-1.1.0-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a06a8b6a305e7f32ca7d460faa97a15b58efe6690079b0c8dfc3b0eb1614d66
BLAKE2b-256 checksum
How to use checksums
a88ae32efe625a823a235da48f0545dceb1ede9353773443445d56be28d1f709
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.11

Security for pyflix 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page