Skip to content

123pc/move_base_control

Repository files navigation

DDSM210 Hub Motor Controller

Python Version License

A Python-based GUI controller for DDSM210 hub motors, built for Waveshare DDSM Driver HAT (A) and ESP32. This project enables intuitive speed adjustment, direction control (forward/backward/left/right/stop), and advanced motor configuration via a user-friendly interface.

📋 Project Overview

This controller communicates with ESP32 via HTTP/JSON (following Waveshare's official protocol) to control DDSM210 hub motors. It features differential reverse steering (left/right turns with 50% reverse differential speed) and built-in safety mechanisms like heartbeat timeout protection, making it ideal for mobile robots, smart cars, and other motor-driven projects. The project also supports lift control of 1610 lead screws via TCP/WiFi network switches.

✨ Key Features

  • Speed Regulation: Slider-based speed control (0-210 RPM, matching DDSM210's no-load max speed) with real-time RPM ↔ CMD value display.
  • Direction Control:
    • Forward/Backward: Dual motors run at the same speed (forward/reverse).
    • Left Turn: Right motor maintains set speed, left motor reverses at 50% of set speed.
    • Right Turn: Left motor maintains set speed, right motor reverses at 50% of set speed.
    • Stop: Instantly stop all motors.
  • Advanced Configuration: View motor ID/info, switch motor working modes.
  • Real-Time Logging: Record all command transmissions and responses for debugging.
  • Safety Protection: 2-second heartbeat timeout (motors stop automatically if no commands received).
  • Lead Screw Lift Control: TCP/WiFi network switch-based control for 57 stepper motor-driven 1610 lead screws (lift/lower, jog control, status query).

🛠️ Hardware Requirements

Component Specification
Main Controller ESP32 (configured with Wi-Fi hotspot/ LAN access, default IP: 192.168.4.1)
Motor Driver Waveshare DDSM Driver HAT (A)
Motor DDSM210 Hub Motor (or compatible DDSM series like DDSM115)
Power Supply DC power supply matching motor voltage/current requirements
Wiring Left motor → ID 1, Right motor → ID 2 (match MOTOR_IDS in code)
Lead Screw Kit (Optional) For lift control
Lead Screw 1610 specification (0.03mm precision, 600mm stroke)
Stepper Motor 57 stepper motor (drives lead screw)
Motor Driver DM556-IO 57 self-pulse driver
Network Switch 4-channel TCP (Ethernet + WiFi) network switch (fixed IP recommended)

📚 Software Environment

  • Python Version: 3.10
  • Required Libraries:
    • requests: For HTTP communication with ESP32
    • tkinter: For GUI (built-in with Python, no extra installation needed)
    • socket: For TCP communication with network switch (built-in)
    • threading: For asynchronous data reception (built-in)

🚀 Installation

1. Clone the Repository

git clone https://github.com/your-username/ddsm210-motor-controller.git
cd ddsm210-motor-controller

2. Install Dependencies

pip install requests

3. Verify Hardware Connection

  • Ensure motors are wired to the correct IDs (Left=1, Right=2) on the driver HAT.
  • Confirm ESP32 is powered and connected to the same network as your PC.
  • For lead screw: Connect 57 stepper motor to DM556-IO driver, wire driver's direction pin to network switch (NO terminal), ensure network switch is connected to the same router WiFi as PC.

🎮 Quick Start

1. Run the Motor Controller (DDSM210)

python test5.py

2. Run the Lead Screw Controller (Network Switch)

python net_switch.py

3. Interface Operation

Motor Controller Interface

Area Function
Speed Adjustment Use the slider to set target RPM (0-210). The label shows RPM and corresponding CMD value.
Direction Control Click buttons for Forward/Backward/Left/Right/Stop to control motor movement.
Advanced Settings Buttons to view motor ID, motor info, or switch motor working modes.
Log Area Displays command logs (send/response/errors) for debugging.

Lead Screw Controller Interface

Area Function
Connection Settings Enter network switch IP/port, click "Connect" to establish TCP connection.
Switch Control 4 buttons for 4-channel switch control (toggle ON/OFF to drive lead screw lift/lower).
Operation "Query Status" to check switch state; "Jog 1-4" for momentary control of each channel.
Data Display Shows sent commands and received responses for debugging.

4. Basic Workflow

For Motor Control

  1. Adjust the speed slider to set your desired RPM.
  2. Click a direction button to control the motors.
  3. Check the log area to confirm command execution status.

For Lead Screw Control

  1. Enter network switch IP (default: 192.168.1.100) and port (default: 8282).
  2. Click "Connect" to establish TCP connection (status turns green if successful).
  3. Use switch buttons to control lead screw lift/lower (button text toggles between ON/OFF).
  4. Use "Query Status" to verify switch state, or "Jog" buttons for momentary control.

⚙️ Core Configuration

Motor Controller (test5.py)

Modify the global variables in test5.py to adapt to your hardware/requirements:

# Network Configuration
ESP32_IP = "192.168.4.1"          # ESP32 IP address (update if using LAN)

# Motor Configuration
MAX_RPM = 210                     # Max RPM for DDSM210 (no-load)
DEFAULT_SPEED = 30                # Default startup speed (RPM)
CMD_PER_RPM = 10                  # RPM to CMD mapping (1 RPM = 10 CMD)
MOTOR_IDS = [1, 2]                # Motor ID mapping (Left=1, Right=2)
DEFAULT_ACT = 3                   # Acceleration time (0.1ms unit)
MOTOR_TYPE = 210                  # Motor model (210=DDSM210, 115=DDSM115)

# Safety Configuration
HEARTBEAT_TIME = 2000             # Heartbeat timeout (ms)
CMD_DELAY_MS = 5                  # Delay between motor commands (ms)

Lead Screw Controller (net_switch.py)

Modify default network switch parameters (if needed) in net_switch.py:

# Default network switch configuration (in create_widgets method)
self.ip_entry.insert(0, "192.168.1.100")  # Update to your network switch IP
self.port_entry.insert(0, "8282")          # Update to your network switch port

📡 Command Protocol

Motor Control Protocol (HTTP/JSON)

The controller sends JSON commands to ESP32 via HTTP (following Waveshare's official spec). Key commands:

Command Type (T) Function Key Parameters Example JSON
10010 Motor Speed Control id (motor ID), cmd (speed cmd), act (acceleration) {"T":10010, "id":1, "cmd":300, "act":3}
10031 View Motor ID - {"T":10031}
10032 View Motor Info id (motor ID) {"T":10032, "id":1}
10012 Switch Motor Mode id (motor ID), mode (mode value) {"T":10012, "id":1, "mode":2}
11001 Set Heartbeat Timeout time (timeout in ms) {"T":11001, "time":2000}
11002 Set Motor Type type (210=DDSM210, 115=DDSM115) {"T":11002, "type":210}

RPM ↔ CMD Mapping Rules

  • Forward: CMD = RPM × CMD_PER_RPM (e.g., 30 RPM → 300 CMD)
  • Reverse: CMD = 100 + abs(RPM × CMD_PER_RPM) (e.g., -15 RPM → 100 + 150 = 250 CMD)
  • Stop: CMD = 0

Lead Screw Control Protocol (TCP)

The controller sends ASCII commands to network switch via TCP. Key commands:

Command Function Response (Switch State)
aX Turn on X-th channel (X=1-4) fX (X-th channel on)
bX Turn off X-th channel (X=1-4) nX (X-th channel off)
qa Query all channels status f1/f2/n3/f4 (mixed)
cX Momentary control X-th channel (jog) Corresponding fX/nX

⚠️ Important Notes

  1. Ensure your PC/controller is on the same network as ESP32 (Wi-Fi hotspot or LAN).
  2. Motor IDs must match wiring (Left=1, Right=2) — incorrect IDs cause reversed direction.
  3. Motors stop automatically after heartbeat timeout; re-send a command to reactivate.
  4. Avoid running motors at max RPM for extended periods (prevents overheating).
  5. Adjust the reverse CMD base value (100) if using a non-standard driver HAT.
  6. For lead screw: Use fixed IP for network switch to avoid connection issues; ensure driver direction pin is wired to switch's NO terminal.
  7. Do not disconnect network switch TCP connection abruptly — use "Disconnect" button to avoid port occupation.

📍 Integration Roadmap

  1. Switch ESP32 to AP+STA mode, connect to the same router WiFi as network switch/PC.
  2. Merge test5.py (motor control) and net_switch.py (lead screw control) into a single GUI program.
  3. Unify control interface for both motor movement and lead screw lift/lower.
  4. Add interlock logic (e.g., stop motor movement when lead screw is in motion).

📖 References

📄 License

This project is licensed under the MIT License — see the LICENSE file for details.

🙏 Acknowledgments

  • Waveshare for open-sourcing the DDSM Driver HAT protocol documentation.
  • The Python community for tkinter and requests libraries.

DDSM210轮毂电机控制器—CN

Python版本 许可证

一个基于Python的DDSM210轮毂电机GUI控制器,适用于Waveshare DDSM驱动板HAT (A)和ESP32。该项目通过用户友好的界面实现直观的速度调节、方向控制(前进/后退/左/右/停止)以及高级电机配置,同时支持基于TCP/WiFi网络开关的1610丝杆升降控制。

📋 项目概述

该控制器通过HTTP/JSON(遵循Waveshare官方协议)与ESP32通信,以控制DDSM210轮毂电机。它具备差动反向转向功能(左右转向时采用50%反向差速)和内置安全机制(如心跳超时保护),非常适合移动机器人、智能小车和其他电机驱动项目。同时集成了网络开关控制逻辑,可驱动57步进电机实现1610丝杆的精准升降。

✨ 主要特性

  • 速度调节:基于滑块的速度控制(0-210 RPM,匹配DDSM210的空载最大速度),并实时显示RPM与CMD值。
  • 方向控制
    • 前进/后退:双电机以相同速度运行(正向/反向)。
    • 左转:右电机保持设定速度,左电机以设定速度的50%反转。
    • 右转:左电机保持设定速度,右电机以设定速度的50%反转。
    • 停止:立即停止所有电机。
  • 高级配置:查看电机ID/信息,切换电机工作模式。
  • 实时日志:记录所有命令传输和响应,便于调试。
  • 安全保护:2秒心跳超时(若未收到命令,电机自动停止)。
  • 丝杆升降控制:基于TCP/WiFi网络开关的57步进电机控制,支持丝杆升降、点动操作、状态查询。

🛠️ 硬件要求

组件 规格说明
主控制器 ESP32(已配置Wi-Fi热点/局域网接入,默认IP:192.168.4.1
电机驱动板 Waveshare DDSM Driver HAT (A)
电机 DDSM210轮毂电机(或兼容的DDSM系列,如DDSM115)
电源 符合电机电压/电流要求的直流电源
接线 左电机→ID 1,右电机→ID 2(与代码中的MOTOR_IDS匹配)
丝杆套件 (可选)用于升降控制
丝杆 1610规格(精度0.03mm,行程600mm,水平负载≤45kg,垂直负载≤35kg)
步进电机 57步进电机(驱动丝杆)
电机驱动器 DM556-IO 57自发脉冲驱动器
网络开关 4路TCP(网口+WiFi)网络开关(建议配置固定IP)

📚 软件环境

  • Python版本:3.10
  • 所需库
    • requests:用于与ESP32进行HTTP通信
    • tkinter:用于图形用户界面(Python内置,无需额外安装)
    • socket:用于与网络开关进行TCP通信(Python内置)
    • threading:用于异步接收网络开关数据(Python内置)

🚀 安装步骤

1. 克隆仓库

git clone https://github.com/your-username/ddsm210-motor-controller.git
cd ddsm210-motor-controller

2. 安装依赖

pip install requests

3. 验证硬件连接

  • 确保电机正确连接到驱动板上的对应ID(左=1,右=2)。
  • 确认ESP32已通电且与电脑连接到同一网络。
  • 丝杆部分:57步进电机连接至DM556-IO驱动器,驱动器方向接口接网络开关常开端,网络开关接入路由器WiFi并与电脑同网段。

🎮 快速开始

1. 运行轮毂电机控制器

python test5.py

2. 运行丝杆升降控制器

python net_switch.py

3. 界面操作

轮毂电机控制器界面

区域 功能
速度调节 使用滑块设置目标RPM(0-210)。标签显示RPM及对应的CMD值。
方向控制 点击前进/后退/左/右/停止按钮控制电机运动。
高级设置 用于查看电机ID、电机信息或切换电机工作模式的按钮。
日志区域 显示命令日志(发送/响应/错误),便于调试。

丝杆升降控制器界面

区域 功能
连接设置 输入网络开关IP/端口,点击“连接”建立TCP连接。
开关控制 4个按钮对应4路开关控制(切换开/关状态,驱动丝杆升降)。
操作区 “查询状态”按钮获取开关当前状态;“点动1-4”按钮实现对应通道点动控制。
数据显示 显示发送的指令和接收的响应数据,便于调试。

4. 基本工作流程

轮毂电机控制

  1. 调节速度滑块设置所需RPM。
  2. 点击方向按钮控制电机。
  3. 在日志区域查看命令执行状态。

丝杆升降控制

  1. 输入网络开关IP(默认:192.168.1.100)和端口(默认:8282)。
  2. 点击“连接”按钮建立TCP连接(状态变为绿色表示连接成功)。
  3. 点击开关按钮控制丝杆升降(按钮文字在“开/关”间切换)。
  4. 可点击“查询状态”验证开关当前状态,或通过“点动”按钮实现丝杆点动控制。

⚙️ 核心配置

轮毂电机控制器(test5.py)

修改test5.py中的全局变量以适应硬件/需求:

# 网络配置
ESP32_IP = "192.168.4.1"          # ESP32的IP地址(使用局域网时请更新)

# 电机配置
MAX_RPM = 210                     # DDSM210的最大RPM(空载)
DEFAULT_SPEED = 30                # 默认启动速度(RPM)
CMD_PER_RPM = 10                  # RPM到CMD的映射(1 RPM = 10 CMD)
MOTOR_IDS = [1, 2]                # 电机ID映射(左=1,右=2)
DEFAULT_ACT = 3                   # 加速时间(单位:0.1ms)
MOTOR_TYPE = 210                  # 电机型号(210=DDSM210,115=DDSM115)

# 安全配置
HEARTBEAT_TIME = 2000             # 心跳超时时间(ms)
CMD_DELAY_MS = 5                  # 电机命令之间的延迟(ms)

丝杆升降控制器(net_switch.py)

如需修改网络开关默认参数,调整net_switch.py中以下代码:

# 默认网络开关配置(在create_widgets方法中)
self.ip_entry.insert(0, "192.168.1.100")  # 改为你的网络开关实际IP
self.port_entry.insert(0, "8282")          # 改为你的网络开关实际端口

📡 命令协议

轮毂电机控制协议(HTTP/JSON)

控制器通过HTTP向ESP32发送JSON命令(遵循Waveshare官方规范)。主要命令:

命令类型(T) 功能 关键参数 示例JSON
10010 电机速度控制 id(电机ID)、cmd(速度指令)、act(加速度) {"T":10010, "id":1, "cmd":300, "act":3}
10031 查看电机ID - {"T":10031}
10032 查看电机信息 id(电机ID) {"T":10032, "id":1}
10012 切换电机模式 id(电机ID)、mode(模式值) {"T":10012, "id":1, "mode":2}
11001 设置心跳超时 time(超时时间,单位ms) {"T":11001, "time":2000}
11002 设置电机类型 type(210=DDSM210,115=DDSM115) {"T":11002, "type":210}

RPM与CMD映射规则

  • 前进CMD = RPM × CMD_PER_RPM(例如:30 RPM → 300 CMD)
  • 反转CMD = 100 + abs(RPM × CMD_PER_RPM)(例如:-15 RPM → 100 + 150 = 250 CMD)
  • 停止CMD = 0

丝杆升降控制协议(TCP)

控制器通过TCP向网络开关发送ASCII指令,核心指令如下:

指令 功能 响应(开关状态)
aX 打开第X路开关(X=1-4) fX(第X路已开)
bX 关闭第X路开关(X=1-4) nX(第X路已关)
qa 查询所有开关通道状态 f1/f2/n3/f4(混合状态)
cX 点动控制第X路开关 对应fX/nX响应

⚠️ 重要说明

  1. 确保电脑/控制器与ESP32处于同一网络(Wi-Fi热点或局域网)。
  2. 电机ID必须与接线匹配(左=1,右=2)——ID错误会导致方向反转。
  3. 心跳超时后电机自动停止;重新发送命令即可重新激活。
  4. 避免长时间以最大RPM运行电机(防止过热)。
  5. 若使用非标准驱动板,可调整反转CMD基准值(100)。
  6. 丝杆控制注意:网络开关建议配置固定IP,避免连接失效;驱动器方向引脚需接开关常开端。
  7. 请勿强制断开网络开关TCP连接,需点击“断开”按钮,避免端口占用。

📍 集成规划

  1. 将ESP32切换为AP+STA模式,接入与网络开关/电脑相同的路由器WiFi。
  2. test5.py(电机控制)与net_switch.py(丝杆控制)合并为单一GUI程序。
  3. 统一电机运动和丝杆升降的控制界面。
  4. 增加互锁逻辑(如丝杆运动时禁止电机移动)。

📖 参考资料

📄 许可证

本项目基于MIT许可证授权——详见LICENSE文件。

🙏 致谢

  • 感谢Waveshare开源DDSM驱动板协议文档。
  • 感谢Python社区提供的tkinterrequests库。

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors