DM电机控制
这个项目提供了一个用于控制DM系列电机的Python库。它支持多种控制模式,包括MIT模式、位置速度模式、速度模式和转矩位置模式。
特性
-
支持多种DM电机型号
-
多种控制模式:MIT、位置速度、速度、转矩位置
-
参数读取和设置
-
电机状态监控
-
兼容新旧固件版本
-
支持电机零点设置
-
支持电机内部参数修改和保存
安装
pip install dmcan
使用方法
- 导入必要的模块:
from dmcan import Motor, MotorControl, DM_Motor_Type, Control_Type
- 创建电机对象:
motor = Motor(DM_Motor_Type.DM4310, SlaveID=0x01, MasterID=0x11)
- 创建电机控制对象:
import serial
ser = serial.Serial('COM8', 921600, timeout=0.5) # 根据实际情况修改串口
motor_control = MotorControl(ser)
- 添加电机到控制对象:
motor_control.addMotor(motor)
- 使能电机:
motor_control.enable(motor)
- 控制电机:
# MIT模式控制
motor_control.controlMIT(motor, kp=50, kd=0.3, q=0, dq=0, tau=0)
# 位置速度模式控制
motor_control.control_Pos_Vel(motor, P_desired=10, V_desired=2)
# 速度模式控制
motor_control.control_Vel(motor, Vel_desired=5)
# 力位混合模式控制
motor_control.control_pos_force(motor, pos=10, vel=1000, torque=100)
- 读取电机状态:
motor_control.refresh_motor_status(motor)
print("位置:", motor.getPosition(), "速度:", motor.getVelocity(), "力矩:", motor.getTorque())
- 修改电机内部参数:
motor_control.switchControlMode(motor, Control_Type.POS_VEL)
motor_control.change_motor_param(motor, DM_variable.KP_APR, 54)
motor_control.save_motor_param(motor)
示例
请参考 DM_Motor_Test.py 文件以获取更多使用示例。
注意事项
-
MasterID不要设置为0x00
-
建议在每帧控制后延迟1-2ms
-
参数修改请在失能状态下进行
-
电机状态需要发送控制帧或刷新状态后才会更新
贡献
欢迎提交问题报告和拉取请求。对于重大更改,请先开issue讨论您想要更改的内容。
许可证
本项目采用 MIT 许可证 - 有关详细信息,请查看 LICENSE 文件。
技术支持
如需技术交流,欢迎加入QQ群:677900232
Metadata
Release files for dmcan 0.1.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dmcan-0.1.3.5.tar.gz | 10.5 kB | Without provenance | Details for dmcan-0.1.3.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dmcan-0.1.3.5-py3-none-any.whl | Python 3 | none | any | Details for dmcan-0.1.3.5-py3-none-any.whl |
Total release size: 20.2 kB
Release files / dmcan-0.1.3.5.tar.gz
| Download URL | dmcan-0.1.3.5.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ce856c7cfb891df86784eb30424c0c9ed35a649d3e76d3c2ada284de6301e91c
|
|
BLAKE2b-256 checksum How to use checksums |
bfd7b46f824d5dfd1365f8050578f1862ed9acfffa143150f6d4fe5cc16aefdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.21
|
Release files / dmcan-0.1.3.5-py3-none-any.whl
| Download URL | dmcan-0.1.3.5-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a7b8ff928e4fa4739f576a52ad29ac512880f6c443806f6553bfebaf3ecd7eb0
|
|
BLAKE2b-256 checksum How to use checksums |
e57b74127b5f8ef71d997955684a298eec2d0c08caffe32c83b18e7cd1425c76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.21
|
Security for dmcan 0.1.3.5
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.