Skip to content
 
 

Repository files navigation

DaMiao Motor Control

Python Platform License

A practical desktop control tool and Python driver for DaMiao brushless motors. Connect an adapter, discover the motor, watch it live, edit registers, and control position or velocity from one clean interface.

It works on Windows with DaMiao's DM-USB2FDCAN adapter and retains the original Linux SocketCAN library and CLI support. The aim is simple: make bringing up a motor feel quick and understandable.

Features

  • Automatic motor discovery with a safe Disable handshake
  • Live position, velocity, torque, temperature, and status plots
  • Clear one-click motor enable/disable control
  • Responsive position and velocity sliders
  • MIT, position/velocity, velocity, and force-position modes
  • Motor register editor and raw CAN traffic log
  • Native Windows DM-USB2FDCAN support through DaMiao's official SDK
  • Python API and damiao command-line tools

Windows quick start

Requirements

  • Windows 10 or 11, 64-bit
  • Python 3.10 or newer
  • Node.js and npm
  • DaMiao DM-USB2FDCAN adapter
  • DaMiao's official libdm_device.dll and libusb-1.0.dll runtime files

Clone and install this repository:

git clone https://github.com/Joeclinton1/python-damiao-driver.git
cd python-damiao-driver
py -m pip install -e .

cd damiao_motor\gui\webapp
npm install
npm run build
cd ..\..\..

damiao gui --port 5001

Open http://127.0.0.1:5001.

The driver automatically looks for the official SDK here:

%USERPROFILE%\damiao-motor-sdk\Python例程\u2canfd\dlls

You can use a different location by setting an environment variable:

$env:DAMIAO_DM_DEVICE_DIR = "C:\path\to\u2canfd\dlls"
damiao gui --port 5001

No Gitee account is required to install or run the tool.

Using the GUI

  1. Connect motor power, CANH, CANL, and signal ground.
  2. Select the detected DM-USB2FDCAN adapter and press Connect.
  3. Select the discovered motor in the left sidebar.
  4. Confirm the motor type so position, velocity, and torque use the correct scale.
  5. Enable control and use the live sliders.

The tested setup is a DM4310 at command ID 1, feedback ID 0, using classic CAN at 1 Mbit/s.

Control modes

Mode Use it for
MIT position Position control with adjustable stiffness, damping, and torque
Position + velocity limit Moving to a position at a limited speed
Velocity Continuous rotation at a requested speed
Force position Position control with velocity and torque limits

To spin the motor continuously, keep it disabled, choose Velocity, enable it, then move the velocity slider away from zero. Return the slider to zero or disable the motor to stop.

Mode changes update motor register 10 at runtime. They are not automatically written to flash.

What motor type means

Motor type selects the position, velocity, and torque ranges used to encode commands and decode feedback. It does not change the physical motor or its firmware. Selecting the wrong type produces incorrectly scaled commands and readings, so match the model printed on the motor.

Linux and SocketCAN

Install the published base package:

pip install damiao-motor

Configure a classic CAN interface at 1 Mbit/s:

sudo ip link set can0 down
sudo ip link set can0 type can bitrate 1000000
sudo ip link set can0 up

The original SocketCAN controller API remains available in this fork.

Python API

from damiao_motor import DaMiaoController

controller = DaMiaoController(channel="can0", bustype="socketcan")
motor = controller.add_motor(
    motor_id=1,
    feedback_id=0,
    motor_type="4310",
)

motor.ensure_control_mode("MIT")
motor.enable()
motor.send_cmd_mit(
    target_position=1.0,
    target_velocity=0.0,
    stiffness=10.0,
    damping=0.2,
    feedforward_torque=0.0,
)

print(motor.get_states())
motor.disable()
controller.shutdown()

Hardware can move as soon as it is enabled. Secure the motor and keep clear of the mechanism before running control code.

CLI

damiao scan --motor-type 4310
damiao send-cmd-mit --motor-type 4310 --id 1
damiao send-cmd-vel --motor-type 4310 --id 1
damiao set-zero-position --motor-type 4310 --id 1
damiao gui

Run damiao --help or damiao <command> --help for all options.

Supported motor presets

3507, 4310, 4310P, 4340, 4340P, 6006, 8006, 8009, 10010, 10010L, H3510, G6215, H6220, JH11, and 6248P.

Fork highlights

This fork adds native Windows USB2CANFD communication, a compact tabbed GUI, and reliable live motor control. The underlying driver is based on jia-xie/python-damiao-driver.

Documentation

License

MIT. See LICENSE.

About

DaMiao motor control for Windows and Linux with a live GUI, USB2CANFD support, registers, plots, and Python API

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages