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.

Current status (important): angle write/control commands are temporarily considered unsupported in this project release line. Read/monitor APIs are the supported and recommended path.

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)

Note: set_angle is currently kept for API compatibility, but write-control behavior is not guaranteed at this stage.

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 (Temporarily Unsupported)

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

For now, treat movement control as experimental and disabled in production use. Use read/monitor methods for stable operation.

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.4.tar.gz (20.4 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.4-cp39-abi3-win_amd64.whl (194.1 kB view details)

Uploaded CPython 3.9+Windows x86-64

motorbridge_smart_servo-0.0.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (348.1 kB view details)

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

motorbridge_smart_servo-0.0.4-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (345.7 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

motorbridge_smart_servo-0.0.4-cp39-abi3-macosx_11_0_arm64.whl (304.4 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: motorbridge_smart_servo-0.0.4.tar.gz
  • Upload date:
  • Size: 20.4 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.4.tar.gz
Algorithm Hash digest
SHA256 fb65f3f6e765e6b1915071c255caaf112fad3796fa1761aeee0132d15b8a0989
MD5 297b91789db9e9924340e525c902c07a
BLAKE2b-256 e65645af87189dc49abbe46157b792b7c71f502a5f819f04e7485de0cfa52d9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for motorbridge_smart_servo-0.0.4-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ea3baa9ba25bcec5541f3d86d73a3406ba2fcffe5dbf900c22e058638fc31ab0
MD5 90908a30b51f9828813484c3d60c5dbd
BLAKE2b-256 2dfa539ea123a5660c22c5e5cdad62d7bc5e931c816a0ffd402ae6e4623ab45b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for motorbridge_smart_servo-0.0.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8c1982643c496c9f425fa9238f9a92ba601d77f4f2279df68c6868e7b997cbe1
MD5 76b1261e9d1036fbce69a9f2b00dd46e
BLAKE2b-256 9b6be65e7227a510236c6334cf054c501d3de2cbd463f4c594e42c6e965d5143

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for motorbridge_smart_servo-0.0.4-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 348cef6a647e5c7f9cc8e8ce1f3c806af4522e1087172bac2f8a1a0daa3592b6
MD5 fa3323d309cd320f8df8e4c26b199769
BLAKE2b-256 3fd271c87063b826433553ce8869b99df3e4f191b107710dd5c905e637512b10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for motorbridge_smart_servo-0.0.4-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8bc1f034fa9f96e23229a834db6e7cfe1368dba7b9a2a6f6dbd316448c4390dc
MD5 371210ff44bd09d9ebf66a3f4a463cc2
BLAKE2b-256 e9eebec4b3acf55cd18e7db83a6d951caccf699533dbd038c1f0b5f2d16d5208

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