Skip to content

6 KB

Machine-translated by Robotheca from the original in Chinese (opens in a new tab). License: MIT (opens in a new tab).

DM-J4310-2EC Graphical Control Interface by DMM Motor

Introduction

This is a graphical control interface for the DMM DM-J4310-2EC motor, communicating via CAN using the WitMotion USB-CAN adapter.

Features

  • Connect to WitMotion USB-CAN adapter via serial port
  • Supports multiple motor models (DM-J4310-2EC, DM4340)
  • Supports MIT control mode
  • Supports trapezoidal acceleration and deceleration motion control
  • Real-time display of motor status (position, speed, torque, temperature, etc.)
  • Graphical parameter configuration interface

System Requirements

  • Python 3.7+
  • WitMotion USB-CAN adapter
  • DMM motor (supports the following models):
    • DM-J4310-2EC (max torque 10 Nm, max speed 30 rad/s)
    • DM4340 (max torque 28 Nm, max speed 10 rad/s)

Supported Motor Model Comparison

ParameterDM-J4310-2ECDM4340
Maximum Position (MIT Mode)±12.5 rad±12.5 rad
Maximum Speed30 rad/s10 rad/s
Maximum Torque10 Nm28 Nm
Maximum Kp500500
Maximum Kd55
FeaturesHigh speed, light loadHigh torque, heavy load

Selection Recommendations:

  • DM-J4310-2EC: High speed (30 rad/s), moderate torque (10 Nm), suitable for light-load, high-speed scenarios (e.g., small robotic arms, gimbals, fast-moving joints)
  • DM4340: High torque (28 Nm), low speed (10 rad/s), suitable for heavy-load, high-torque scenarios (e.g., heavy-duty robotic arms, mobile robots, joints requiring large torque)

Installing Dependencies

Method 1: Using pip (Recommended for existing Python environments)

Run the following command in the tools/motor_gui directory:

pip install -r requirements.txt

Method 2: Using conda (recommended for isolated environments)

If you use Anaconda or Miniconda, you can create an independent conda environment:

# Create a conda environment named motor_gui (Python 3.9)
conda create -n motor_gui python=3.9 -y

# Activate the environment
conda activate motor_gui

# Install pyserial
conda install -c conda-forge pyserial -y

# Alternatively, install using pip (within the conda environment)
pip install -r requirements.txt

# Run the program
python motor_gui.py

# Exit the environment after use
# conda deactivate

Note: Python in conda environments usually already includes tkinter, so no additional installation is required.

Dependency Notes

  • pyserial: Used for serial communication and data interaction with the USB-CAN adapter
  • tkinter: Python's built-in GUI library (may require separate installation on some Linux distributions)

Additional Installation on Linux Systems

On some Linux distributions, tkinter needs to be installed separately:

Ubuntu/Debian:

sudo apt-get install python3-tk

Fedora:

sudo dnf install python3-tkinter

Arch Linux:

sudo pacman -S tk

Quick Start

Using a conda environment (recommended)

# 1. Navigate to the project directory
cd /path/to/mockway_robotics/tools/motor_gui

# 2. Create and activate the conda environment
conda create -n motor_gui python=3.9 -y
conda activate motor_gui

# 3. Install dependencies
conda install -c conda-forge pyserial -y

# 4. Launch the GUI
python motor_gui.py

# 5. For subsequent use, simply activate the environment
# conda activate motor_gui
# python motor_gui.py

Using a pip Environment

# 1. Navigate to the project directory
cd /path/to/mockway_robotics/tools/motor_gui

# 2. (Optional) Create a virtual environment
python -m venv venv
source venv/bin/activate  # Linux/macOS
# or
venv\Scripts\activate     # Windows

# 3. Install dependencies
pip install -r requirements.txt

# 4. Launch the GUI
python motor_gui.py

Usage

Start the graphical interface

python motor_gui.py

Configuration Parameters

  1. Connection Configuration

    • COM port: Set the serial port number (Windows: COM9, Linux: /dev/ttyUSB0)
    • Serial baud rate: Default 921600
    • Motor Type: Select the motor model (DM-J4310-2EC or DM4340)
      • DM-J4310-2EC: Maximum torque 10 Nm, maximum speed 30 rad/s (high speed, light load)
      • DM4340: Maximum torque 28 Nm, maximum speed 10 rad/s (high torque, heavy load)
    • Click the "Connect" button to establish a connection
  2. Motor Parameter Configuration

    • Motor ID: CAN bus motor ID (default 2)
    • Master ID: Host ID for receiving feedback frames (default 0)
    • Kp: Position proportional coefficient (default 40.0)
    • Kd: Position differential coefficient (default 1.0)
    • Maximum speed: Maximum speed for trapezoidal acceleration/deceleration (default 8.0 rad/s)
    • Maximum acceleration: Maximum acceleration for trapezoidal acceleration/deceleration (default 15.0 rad/s²)
  3. Motor Control

    • After connection, click "Enable Motor" to activate the motor
    • Use the "Forward" and "Reverse" buttons to control motor movement
    • Hold the button: The motor accelerates to the target position
    • Release the button: The motor begins decelerating to a stop

Serial Port Settings

This program communicates with the WitMotion USB-CAN adapter via a serial port:

  • Windows: Serial port names are typically COM3, COM4, COM9, etc.
  • Linux: Serial port names are typically /dev/ttyUSB0, /dev/ttyUSB1, etc.
  • macOS: Serial port names are typically /dev/tty.usbserial-XXXX or /dev/cu.usbserial-XXXX
View available serial ports

Linux/macOS:

ls /dev/tty*
# or
python -m serial.tools.list_ports

Windows: View ports (COM and LPT) in Device Manager

Linux Serial Port Permission Settings

If you encounter permission issues, you need to add the current user to the dialout group:

sudo usermod -a -G dialout $USER

Then log out and log back in, or run:

newgrp dialout

File Description

  • motor_gui.py: Main graphical user interface program
  • dm_motor_driver.py: Motor driver program, including CAN communication and motor control logic
  • requirements.txt: List of Python dependency packages
  • README.md: This documentation file

Troubleshooting

Unable to open the serial port

  • Check whether the serial port name is correct
  • Check whether the USB-CAN adapter is properly connected
  • Check serial port permissions (Linux system)
  • Check if another program is occupying the serial port

Unable to receive motor feedback data

  • Check if the CAN bus connection is normal
  • Check if the motor ID and Master ID settings are correct
  • Check if the motor power supply is normal
  • Check the CAN baud rate setting (default: 1,000,000)

Motor Not Responding

  • Confirm that the motor is enabled
  • Check the motor's error status
  • Check if the motor temperature is too high
  • Check if the power supply voltage is normal

Files by @Jelatine, at commit a0e2f59, read from GitHub in your browser. Hardware license: MIT; software license: MIT. Robotheca doesn't review code: read it before running it.