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.1.2.tar.gz (42.0 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.1.2-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mini_quadlib-0.1.2.tar.gz
  • Upload date:
  • Size: 42.0 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.1.2.tar.gz
Algorithm Hash digest
SHA256 8c8248e650fa2cc84bd4255046e87c6dcd9b339b1ed4f48b84488de74db513c5
MD5 74d36dc6b7d3fed8248ef9c31fffe588
BLAKE2b-256 7bf5f5d85d5f95a59d386b5ec8ba0b79616f1a848f7d430179463d084537731b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mini_quadlib-0.1.2.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.1.2-py3-none-any.whl.

File metadata

  • Download URL: mini_quadlib-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 34.0 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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c924ea290617640442f198814592c75fa4d0dea1586cf995052282699baaa93a
MD5 25c7332edd12325b91c89ce4e58fce81
BLAKE2b-256 437f4b61a585209dce55d1faeb8a8f4665d9847426508630875bff25685637e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for mini_quadlib-0.1.2-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