Skip to main content

zread

pydamiao

一个非官方的达妙电机 Python 库。

pydamiao 基于官方 SDK 的工作流做了更 Pythonic 的封装, 使其开发体验更好。pydamiao 提供串口通信、电机管理、参数读写和常见控制模式的高层接口,适合快速集成到自己的项目中。

基本特性

  • 包含完整的类型注解, 为开发者提供舒适的开发体验。
  • 可能会失败的接口, 使用类似 Rust 的 Result 返回格式, 显式处理错误, 避免大量 None 判断
  • 提供 Motor 和 MotorManager 等高层接口
  • 支持 MIT、VEL、POS_VEL、POS_FORCE 等常见控制模式
  • 同时支持单电机和多电机场景

开发者体验 (DX) 升级

本项目从达妙官方提供的 单文件脚本 重构为现代化的 Python 库,在易用性和可维护性上进行了全方位升级:

  • 极速环境构建:全面采用 uv 管理项目依赖与虚拟环境,提升开发与部署效率。
  • 现代类型推导:基于 Python 3.10+,全面覆盖核心 API 的原生类型注解,大幅提升 IDE 代码提示与静态检查体验。
  • 模块化代码解耦:将巨石架构拆分为 bus、protocol、motor 等独立模块,并封装了底层硬编码的字节位移操作,显著降低源码阅读与二次开发门槛。

安装

从 PyPI 安装

uv pip install pydamiao 

或

pip install pydamiao 

从源码安装:

git clone https://github.com/DBinK/pydamiao.git
cd pydamiao
pip install -e .

快速开始

import math
import time

from pydamiao import Motor, MotorManager, ControlMode, MotorType, MotorReg, SerialBus

# 初始化所有对象
bus = SerialBus("COM3", baudrate=921600, timeout=0.01)
manager = MotorManager(bus)

motor1 = Motor(bus, MotorType.DM4310, 0x06, 0x12)
motor2 = Motor(bus, MotorType.DM4310, 0x05, 0x12)

# 注册电机到管理器
manager.register(motor1)
manager.register(motor2)

# 统一控制电机
manager.clean_error_all()
manager.disable_all()
manager.set_mode_all(ControlMode.MIT)

# 查看电机参数
for id, motor in manager.motors.items():
    print(f"电机 ID {id}:")
    print("CTRL_MODE:", motor.read_param(MotorReg.CTRL_MODE).value)
    print("MST_ID:", motor.read_param(MotorReg.MST_ID).value)

# 单独控制电机
if not motor1.set_mode(ControlMode.POS_VEL).is_ok:
    print("motor1 切换到 POS_VEL 失败")

if not motor2.set_mode(ControlMode.VEL).is_ok:
    print("motor2 切换到 VEL 失败")

# 运动测试
for _ in range(1000):
    q = math.sin(time.time())
    motor1.set_pos_vel(q * 8, 3)
    motor2.set_velocity(8 * q)
    time.sleep(0.001)

# 程序结束前, 记得失能所有电机 (虽然有自动失能兜底, 但是推荐养成好习惯)
manager.disable_all()
bus.close()

API 概览

  • SerialBus:共享串口通信总线
  • Motor:单个电机的高层控制对象
  • MotorManager:同一总线上的多电机管理器
  • ControlMode、MotorType、MotorReg:协议相关枚举和辅助类型

使用文档 和 示例

文档正在补充中...

可先查看 Zread 生成的说明文档

或先查看示例 examples 目录, 包含了本库几乎全部用法:

项目状态

项目仍在持续迭代中,正式稳定版本发布前 API 可能会继续调整。

许可证

MIT,详见 LICENSE。

Release files for pydamiao 0.1.4

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

Source distribution (sdist)

Source distribution for pydamiao 0.1.4
File Size Uploaded
pydamiao-0.1.4.tar.gz 18.1 kB Details

Built distribution (wheel)

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

Total release size: 39.7 kB

Release files / pydamiao-0.1.4.tar.gz

Download URL pydamiao-0.1.4.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
72ee4abaf0ccbd7b9eea1ac6dab56a13bb1e1b0c8c8ff0ac47dd1dec596b746e
BLAKE2b-256 checksum
How to use checksums
05cf0a99b85a56ad2b680c16a06e4e92bc4685f850b9fed3997f20090bf9205e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 1, 2026.

Transparency log

Release files / pydamiao-0.1.4-py3-none-any.whl

Download URL pydamiao-0.1.4-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d707e35398023005eb27bd475969fc0a3a7d5b16d0699ade277913b0a0b7fa5f
BLAKE2b-256 checksum
How to use checksums
64178f8286ed672aef8ce92eb0ba69383639a6bf5cc522db1426c08a6e911b18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

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