Skip to content

dzylikecode/dog-motor-xiaomi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

小米电机

灵足时代:

cybergear:

python 代码:

串口助手:SuperCom

指令编码

小米CyberGear微电机串口控制指令驱动

由于使用的是YourCee的USB-CAN模块,根据CAN_ID(报文标识符)说明进行编码

数据编码

flowchart LR
USB2CAN[USB转CAN] 
PC[电脑]
motor[电机]
PC --"USB_Data"--> USB2CAN --"Mi_Data"--> motor
Loading

USB-CAN模块采用的是 YourCee

Mi_Data 说明书上有,基本格式为(29 bits + 8 bytes)的格式

数据域 29 位 ID 8Byte 数据区
大小 bit28~bit24 bit23~8 bit7~0 Byte0~Byte7
描述 通信类型 数据区 2 目标地址 数据区 1

由于采用的是USB-CAN模块, 所以需要考虑USB_Data 到 Mi_Data 的转换

根据YourCeeCAN_ID(报文标识符)说明,ID的关系是这样的

$$ \text{USB-id}(\underbrace{\text{id}}_{\text{高 29 bits}} + 100) \rightarrow \text{Mi-id} $$

AT 模式的 USB 格式:

$$ AT + \text{USB-id} + \underbrace{08}_{\text{1 byte}} + \text{8 bytes} + \backslash r \backslash n $$

example

from controller import YourCeePort, RunMode, Args
import time
port = YourCeePort('COM10', 'AT', 0xFD)
id = port.search_id()
port.set_run_mode(id, RunMode.position)
port.enable(id)
port.write_single_arg(id, Args.limit_spd, 5.0)
port.write_single_arg(id, Args.loc_ref, -12.0)
time.sleep(3)
port.disable(id)
port.close()

dependencies

单一文件cybergear/controller,仅仅依赖pyserial这个包

pip install pyserial

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages