Skip to main content

An unofficial Damiao motor control library, developed based on the official SDK. 一个非官方的达妙电机控制库, 基于官方sdk二次开发

Project description

pydamiao

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

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

特性

  • 基于 pyserial 的简单串口总线封装
  • 提供 MotorMotorManager 高层接口
  • 同时支持单电机和多电机场景
  • 支持 MITVELPOS_VELPOS_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:同一总线上的多电机管理器
  • ControlModeMotorTypeMotorReg:协议相关枚举和辅助类型

使用文档 和 示例

文档正在补充中...

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

项目状态

项目仍在持续迭代中,正式稳定版本发布前 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

pydamiao-0.1.2.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

pydamiao-0.1.2-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

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

Hashes for pydamiao-0.1.2.tar.gz
Algorithm Hash digest
SHA256 722fd74ac1cec1a438f520080b2e9efd8fb55b8e6ac00095892b74435a57af44
MD5 383e54c9d8167938b09638850b344b27
BLAKE2b-256 97c330f4b35a306df4df71edc1dd8ebccee86b3402df2b1f21b841bf59ee5501

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydamiao-0.1.2.tar.gz:

Publisher: test_and_publish.yml on DBinK/pydamiao

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pydamiao-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e2a0b960024f7a824ac5b5af04100ea8286be20aa243f29689b7a6e49b387eeb
MD5 040c8badac99750997df54657ef1594d
BLAKE2b-256 b2786709d43f460fc17d00137878109662dce140b2644e8cdc15461b6373a30f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydamiao-0.1.2-py3-none-any.whl:

Publisher: test_and_publish.yml on DBinK/pydamiao

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