Skip to main content

PyO3 bindings for MotorBridge Smart Servo

Project description

motorbridge-smart-servo Python Binding Guide

This package is the PyO3 + maturin Python binding for MotorBridge Smart Servo. It currently targets the FashionStar UART smart-servo protocol.

The Rust core is compiled into motorbridge_smart_servo._native, so the wheel contains native code directly. There is no runtime ctypes.CDLL(...) loading step and no external ABI DLL/SO required by Python.

What "Raw" vs "Calibrated/Filtered" Data Means

read_angle() returns an AngleSample with:

  • raw_deg: protocol angle from the servo packet.
  • filtered_deg: reliability-filtered angle for application logic.
  • reliable: False when the filter is temporarily holding the last safe value.

For control/planning/business logic, use filtered_deg.

sample = bus.read_angle(servo_id=0, multi_turn=True)
raw_angle = sample.raw_deg
safe_angle = sample.filtered_deg
is_reliable = sample.reliable

API Summary

Main classes:

  • SmartServoBus (vendor-neutral entry)
  • FashionStarServo (direct vendor class)

Common methods:

  • scan(max_id=253) -> list[int]
  • ping(servo_id) -> bool
  • read_angle(servo_id, multi_turn=True) -> AngleSample
  • read_raw_angle(servo_id, multi_turn=True) -> float
  • read_filtered_angle(servo_id, multi_turn=True) -> float
  • monitor(servo_id, multi_turn=True, interval_s=0.02, count=None)
  • set_angle(servo_id, angle_deg, multi_turn=False, interval_ms=0)

Quick Start (Development Install)

Linux/macOS:

cd bindings/python
python -m pip install -U pip maturin
python -m pip install -e .

Windows PowerShell:

cd bindings\python
python -m pip install -U pip maturin
python -m pip install -e .

Basic Usage

from motorbridge_smart_servo import SmartServoBus

with SmartServoBus.open(
    vendor="fashionstar",
    port="/dev/ttyUSB0",   # e.g. "COM5" on Windows
    baudrate=1_000_000,
) as bus:
    online = bus.scan(max_id=20)
    print("online:", online)

    sample = bus.read_angle(0, multi_turn=True)
    print(
        f"raw={sample.raw_deg:.3f}, "
        f"filtered={sample.filtered_deg:.3f}, "
        f"reliable={sample.reliable}"
    )

    # Use filtered angle in your control logic.
    angle_for_control = sample.filtered_deg

Direct vendor class:

from motorbridge_smart_servo import FashionStarServo

with FashionStarServo("/dev/ttyUSB0", 1_000_000) as bus:
    print(bus.ping(0))

Continuous Monitoring

with SmartServoBus.open(vendor="fashionstar", port="/dev/ttyUSB0") as bus:
    for sample in bus.monitor(0, multi_turn=True, interval_s=0.02):
        print(
            f"raw={sample.raw_deg:9.3f} "
            f"filtered={sample.filtered_deg:9.3f} "
            f"reliable={sample.reliable}"
        )

monitor() keeps streaming after transient timeout once at least one valid sample has been observed. In those moments you can see reliable=False while filtered_deg holds the last safe value.

Move Command

with SmartServoBus.open(vendor="fashionstar", port="/dev/ttyUSB0") as bus:
    bus.set_angle(0, -45.0, multi_turn=False, interval_ms=500)

Build a Wheel (.whl)

Linux/macOS:

cd bindings/python
python -m pip install -U pip maturin build twine
python -m maturin build --release --out dist
python -m twine check dist/*
python -m pip install --force-reinstall dist/*.whl

Windows PowerShell:

cd bindings\python
python -m pip install -U pip maturin build twine
python -m maturin build --release --out dist
python -m twine check dist\*
python -m pip install --force-reinstall (Get-ChildItem dist\*.whl | Select-Object -Last 1).FullName

Build Wheels for Publishing (Recommended)

For distribution, build in CI for each target platform (Windows/Linux/macOS) to avoid local toolchain differences.

Suggested targets:

  • Windows: x86_64
  • Linux: x86_64, aarch64
  • macOS: arm64 (and optionally x86_64)

This package uses abi3 (cp39-abi3), so one wheel per platform/arch can cover multiple Python versions (3.9+), but you still need separate wheels per OS/architecture.

Publish to PyPI

  1. Update version in bindings/python/pyproject.toml.
  2. Build wheels and (optionally) source dist.
  3. Validate artifacts:
python -m twine check dist/*
  1. Upload to TestPyPI first:
python -m twine upload --repository testpypi dist/*
  1. Install from TestPyPI and run smoke test:
python -m pip install -i https://test.pypi.org/simple/ motorbridge-smart-servo
python -c "import motorbridge_smart_servo; print('ok')"
  1. Upload to production PyPI:
python -m twine upload dist/*

Use API tokens for Twine auth (__token__ username).

Release Checklist

  • cargo test --workspace
  • python -m compileall bindings/python/src examples/python
  • Import smoke: python -c "import motorbridge_smart_servo as m; print(m.__name__)"
  • CLI smoke: python -m motorbridge_smart_servo.cli --help
  • twine check dist/*

Troubleshooting

  • externally-managed-environment (PEP 668): use a virtual environment.
  • No such file or directory when opening serial port: wrong port path.
  • Permission denied on Linux serial device: add user to dialout and relogin.
  • library_path argument is unsupported with PyO3 backend by design.

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

motorbridge_smart_servo-0.0.3.tar.gz (16.0 kB view details)

Uploaded Source

Built Distributions

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

motorbridge_smart_servo-0.0.3-cp39-abi3-win_amd64.whl (175.9 kB view details)

Uploaded CPython 3.9+Windows x86-64

motorbridge_smart_servo-0.0.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (326.4 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

motorbridge_smart_servo-0.0.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (322.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

motorbridge_smart_servo-0.0.3-cp39-abi3-macosx_11_0_arm64.whl (284.5 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file motorbridge_smart_servo-0.0.3.tar.gz.

File metadata

  • Download URL: motorbridge_smart_servo-0.0.3.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for motorbridge_smart_servo-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ffee10accea9bef5bffb80bfee89d032032bea7b5803ab50b0e3e9c5949cac44
MD5 c949d6b2f0a10b17b6c34475d562e4a2
BLAKE2b-256 b57cdeac0b68e7d0b7deb376f9e2c79fc752e5094e066b702ad9c757919ec4b2

See more details on using hashes here.

File details

Details for the file motorbridge_smart_servo-0.0.3-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for motorbridge_smart_servo-0.0.3-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 45e779ae5fbaacf378d41092ae48c057180d564bc537678f61ea5b0576fb04f9
MD5 adb267214fcb0b34b62654b3720b0204
BLAKE2b-256 afca1d656a3b93ff46f516ca377c46371a7331845040509af5ed38ad6691a8ac

See more details on using hashes here.

File details

Details for the file motorbridge_smart_servo-0.0.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for motorbridge_smart_servo-0.0.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a56e2bef556429e42b9568dc1c0ce9e08ad7636da64c7d0ff5444277b9be643f
MD5 91e21975673265a9f3405d8347bcec69
BLAKE2b-256 3a6df04bf9a009a5f848f0471670403ca300fb16561d5ae2da339874d6b3c6e9

See more details on using hashes here.

File details

Details for the file motorbridge_smart_servo-0.0.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for motorbridge_smart_servo-0.0.3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 955c69f00159548e4e3ab2b2d438082e446d9df1d487e3c528483f9f51c5cc21
MD5 58b991c4efebfe67a389ee4ae05fe9c7
BLAKE2b-256 842a2e253ab50f75658e08e47aca14ff4037e58c99e68871b4da1aa29201ec78

See more details on using hashes here.

File details

Details for the file motorbridge_smart_servo-0.0.3-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for motorbridge_smart_servo-0.0.3-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 10e672eab9b31db00d399acbac61a7e9704ccc5a280cb3cc460e31e98c187415
MD5 71d488c64c6c5c54bd03b86dfe97445f
BLAKE2b-256 75d870d828557e5c34c34b22234264d2981f2ed33920b8eab00e387e6a86f005

See more details on using hashes here.

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