Skip to main content

Python bindings for mini-quadlib: A lightweight C library for quadrotor control

Project description

Mini-QuadLib

A lightweight C library for quadrotor control systems, with Python bindings.

License: MIT

Features

  • Geometric Controller - SE(3) geometric control for quadrotors
  • L1 Adaptive Control - Robust adaptive augmentation for disturbance rejection
  • Robotics Utilities - Coordinate transforms, frame conversions, rotation representations
  • Lightweight - Requires minimal dependencies
  • Cross-platform - C library works anywhere, Python bindings for Linux

Repository Structure

mini-quadlib/
├── include/
│   └── mini_quadlib.h      # Main C header (all API documentation here)
├── src/
│   └── *.c                 # C implementation
├── python/
│   └── mini_quadlib/       # Python package
├── build/                  # Build output (generated)
├── CMakeLists.txt
└── README.md

C Library

Building (Linux)

Prerequisites

  • CMake >= 3.8
  • GCC or Clang

Build Static Library

# Clone the repository
git clone https://github.com/sigma-pi/mini-quadlib.git
cd mini-quadlib

# Create build directory
mkdir build && cd build

# Configure and build
cmake ..
make -j$(nproc)

This produces:

  • build/libmini_quadlib.a - Static library

Build Shared Library (for Python bindings)

# Create a virtual environment before building
conda create --name mini_quadlib
conda activate mini_quadlib

# Build
cd /path/to/mini-quadlib
mkdir -p build && cd build
cmake .. -DBUILD_PYTHON=ON
make -j$(nproc)

# Copy .so to package directory
cp libmini_quadlib.so ../python/mini_quadlib/

# Install
cd ../python
pip install -e .

This produces:

  • build/libmini_quadlib.so - Shared library

Using the C Library

Include in Your Project

#include "mini_quadlib.h"

int main() {
  // Get library version
  printf("mini-quadlib version: %s\n", quadlib_version());
  
  // Create state and setpoint
  state_t current_state = {
      .pos = {0.0f, 0.0f, 0.0f},
      .vel = {0.0f, 0.0f, 0.0f},
      .quat = {1.0f, 0.0f, 0.0f, 0.0f},  // w, x, y, z
      .omega = {0.0f, 0.0f, 0.0f}
  };
  
  setpoint_t desired = {
      .pos = {1.0f, 0.0f, -1.0f},  // NED frame
      .vel = {0.0f, 0.0f, 0.0f},
      .acc = {0.0f, 0.0f, 0.0f},
      .jerk = {0.0f, 0.0f, 0.0f},
      .snap = {0.0f, 0.0f, 0.0f},
      .yaw = 0.0f,
      .yaw_dot = 0.0f,
      .yaw_ddot = 0.0f
  };
  
  // Controller parameters
  geometric_params_t ctrl_params = {
      .k_p = {1.0f, 1.0f, 2.0f},
      .k_v = {0.5f, 0.5f, 1.0f},
      .k_R = {1.0f, 1.0f, 1.0f},
      .k_W = {0.1f, 0.1f, 0.1f}
  };
  
  quadx_params_t quad_params = {
      .mass = 1.0f,
      .inertia = {0.01f, 0.01f, 0.02f}
  };
  
  // Compute control
  control_4f_t output;
  quadlib_result_t result = geometric_control_fM_fullparam(
      &output, &current_state, &desired, &ctrl_params, &quad_params
  );
  
  if (result == QUADLIB_SUCCESS) {
      printf("Thrust: %.2f, Moments: [%.2f, %.2f, %.2f]\n",
             output.u1, output.u2, output.u3, output.u4);
  }
  
  return 0;
}

Compile Your Program

gcc -I/path/to/mini-quadlib/include \
  -L/path/to/mini-quadlib/build \
  your_program.c -lmini_quadlib -lm -o your_program

C API Reference

All C API documentation is in the header file:

📖 include/mini_quadlib.h

Key sections:

  • Data Structures - vector3f_t, quaternion4f_t, state_t, setpoint_t, etc.
  • Geometric Control - geometric_control_fM_fullparam()
  • L1 Adaptive Control - l1_adaptive_control_fullparam()
  • Coordinate Transforms - enu_to_ned(), ned_to_enu(), coordinate_transform_omni()
  • Rotation Utilities - Quaternion/Euler/RotationMatrix conversions

Python Bindings

Quick Install (from source)

cd mini-quadlib

# Build C library first
mkdir build && cd build
cmake .. -DBUILD_PYTHON=ON
make -j$(nproc)
cd ..

# Install Python package
cd python
pip install -e .

Run Basic Tests

python ./python/tests/test_python_api.py

Quick Test

import mini_quadlib as mql
import numpy as np

print(f"Version: {mql.get_version()}")

# Create a quaternion
q = mql.Quaternion(0.707, 0.0, 0.0, 0.707)
print(f"Quaternion: {q}")

# Coordinate transform
ned = np.array([1.0, 2.0, 3.0])
enu = mql.ned_to_enu(ned)
print(f"NED {ned} -> ENU {enu}")

For detailed Python documentation, see:

📖 python/README.md


License

MIT License - see LICENSE for details.

Author

Chengyu Yang (chengyuy520@gmail.com)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mini_quadlib-0.2.0.tar.gz (41.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mini_quadlib-0.2.0-py3-none-any.whl (33.4 kB view details)

Uploaded Python 3

File details

Details for the file mini_quadlib-0.2.0.tar.gz.

File metadata

  • Download URL: mini_quadlib-0.2.0.tar.gz
  • Upload date:
  • Size: 41.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mini_quadlib-0.2.0.tar.gz
Algorithm Hash digest
SHA256 895020f68a3aa00d93ea97ce429c41dac1ef4b46a3208866a5a36e7d318aa406
MD5 e459b7683f6113b33e721a3a8707f32e
BLAKE2b-256 59d5932650fdaab24fb3da940bd5a8f3ff99b2f129bd1d06f3e7796a45d1e710

See more details on using hashes here.

Provenance

The following attestation bundles were made for mini_quadlib-0.2.0.tar.gz:

Publisher: python-publish.yml on sigma-pi/mini-quadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mini_quadlib-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mini_quadlib-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 33.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mini_quadlib-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d25cfaf6f896a7a4641e95b4cf4f1130a4af64c236b5b14ba471bd510510874
MD5 6238f53012082fe97e5b48a349fb5835
BLAKE2b-256 8bdf91c4b78eb26325db91a61adac27952b6a5d2b9e24941e50264e9e13db04c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mini_quadlib-0.2.0-py3-none-any.whl:

Publisher: python-publish.yml on sigma-pi/mini-quadlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page