An unofficial Damiao motor control library, developed based on the official SDK. 一个非官方的达妙电机控制库, 基于官方sdk二次开发
Project description
pydamiao
一个非官方的达妙电机 Python 库。
pydamiao 基于官方 SDK 的工作流做了更 Pythonic 的封装, 使其开发体验更好。pydamiao 提供串口通信、电机管理、参数读写和常见控制模式的高层接口,适合快速集成到自己的项目中。
特性
- 基于
pyserial的简单串口总线封装 - 提供
Motor和MotorManager高层接口 - 同时支持单电机和多电机场景
- 支持
MIT、VEL、POS_VEL、POS_FORCE等常见控制模式 - 可能会失败的接口, 使用类似 Rust 的
Result返回格式, 显式处理错误, 避免大量None判断
安装
从 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:协议相关枚举和辅助类型
使用文档 和 示例
文档正在补充中...
可先查看示例 examples 目录, 包含了本库几乎全部用法:
base.py: 基础用法, 包含常用 API 的使用motor_single.py: 单电机控制motor_muitl.py: 多电机控制calibration.py: 零点校准 (多电机)read_reg.py: 读取电机寄存器中的值
项目状态
项目仍在持续迭代中,正式稳定版本发布前 API 可能会继续调整。
许可证
MIT,详见 LICENSE。
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydamiao-0.1.2.tar.gz.
File metadata
- Download URL: pydamiao-0.1.2.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
722fd74ac1cec1a438f520080b2e9efd8fb55b8e6ac00095892b74435a57af44
|
|
| MD5 |
383e54c9d8167938b09638850b344b27
|
|
| BLAKE2b-256 |
97c330f4b35a306df4df71edc1dd8ebccee86b3402df2b1f21b841bf59ee5501
|
Provenance
The following attestation bundles were made for pydamiao-0.1.2.tar.gz:
Publisher:
test_and_publish.yml on DBinK/pydamiao
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydamiao-0.1.2.tar.gz -
Subject digest:
722fd74ac1cec1a438f520080b2e9efd8fb55b8e6ac00095892b74435a57af44 - Sigstore transparency entry: 1417943035
- Sigstore integration time:
-
Permalink:
DBinK/pydamiao@7560d66daffb926ed6715837e36be44bbcded6d8 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/DBinK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test_and_publish.yml@7560d66daffb926ed6715837e36be44bbcded6d8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydamiao-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pydamiao-0.1.2-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2a0b960024f7a824ac5b5af04100ea8286be20aa243f29689b7a6e49b387eeb
|
|
| MD5 |
040c8badac99750997df54657ef1594d
|
|
| BLAKE2b-256 |
b2786709d43f460fc17d00137878109662dce140b2644e8cdc15461b6373a30f
|
Provenance
The following attestation bundles were made for pydamiao-0.1.2-py3-none-any.whl:
Publisher:
test_and_publish.yml on DBinK/pydamiao
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydamiao-0.1.2-py3-none-any.whl -
Subject digest:
e2a0b960024f7a824ac5b5af04100ea8286be20aa243f29689b7a6e49b387eeb - Sigstore transparency entry: 1417943039
- Sigstore integration time:
-
Permalink:
DBinK/pydamiao@7560d66daffb926ed6715837e36be44bbcded6d8 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/DBinK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test_and_publish.yml@7560d66daffb926ed6715837e36be44bbcded6d8 -
Trigger Event:
push
-
Statement type: