Skip to content

Seeed-Projects/HighTorque_Control

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LivelyBot High Torque Motor Control Library

A motor control library developed based on the High Torque Motor SDK protocol table, supporting implementations in Python, C++, Rust, and Arduino.

🌐 Languages: English | 中文 | Español

🔗 Official SDK: https://github.com/HighTorque-Robotics/livelybot_hardware_sdk

🚀 Quick Start

Environment Setup

# Install CAN tools
sudo apt-get install can-utils

# Configure CAN interface
sudo ip link set can0 type can bitrate 1000000
sudo ip link set up can0

Python Implementation

cd python
pip install -r requirements.txt

# Scan motors
python3 can_motor_scanner.py --channel can0

# Velocity control
python3 velocity_acceleration_control.py --motor_id 1 --mode interactive

# Angle control
python3 angle_stream_control.py --motor_id 1 --mode interactive

C++ Implementation ✅

cd cpp
make

# Scan motors
./can_motor_scanner 1 5

# Velocity control
./velocity_acceleration_control 1

# Angle control
./angle_stream_control 1 interactive

Rust Implementation ✅

cd rust
cargo build --release

# Scan motors
./target/release/can_motor_scanner --start-id 1 --end-id 5

# Velocity control
./target/release/velocity_acceleration_control --motor-id 1

# Angle control
./target/release/angle_stream_control --motor-id 1 interactive

📁 Project Structure

CUS_02/
├── python/                 # Python implementation
│   ├── can_motor_scanner.py           # Motor scanning tool
│   ├── velocity_acceleration_control.py # Velocity + Acceleration control
│   ├── angle_stream_control.py         # Angle stream control
│   └── requirements.txt               # Python dependencies
├── cpp/                    # C++ implementation
│   ├── can_motor_scanner.cpp          # Motor scanning tool
│   ├── velocity_acceleration_control.cpp # Velocity + Acceleration control
│   ├── angle_stream_control.cpp       # Angle stream control
│   ├── Makefile                       # Build system
│   └── README.md                      # C++ documentation
├── rust/                   # Rust implementation
│   ├── src/
│   │   ├── lib.rs
│   │   └── bin/
│   │       ├── can_motor_scanner.rs
│   │       ├── velocity_acceleration_control.rs
│   │       └── angle_stream_control.rs
│   ├── Cargo.toml
│   ├── Makefile
│   └── README.md
│   └── target/release/              # Compiled executables
├── arduino/                # Arduino implementation
│   └── libraries/
└── scripts/                # Build and configuration scripts

🔧 Features

Python Implementation (100Hz, 5ms latency) ✅

  • ✅ CAN bus motor scanning
  • ✅ Intelligent emergency stop velocity control
  • ✅ 0x90 stream command angle control
  • ✅ MIT style impedance control
  • ✅ Sine wave/step/ramp testing

C++ Implementation (200Hz, 1ms latency) ✅

  • ✅ High-performance real-time control (200Hz control loop)
  • ✅ Native SocketCAN interface
  • ✅ Multi-threaded control architecture
  • ✅ Intelligent emergency stop with maximum deceleration
  • ✅ MIT-style impedance control (0x90 stream commands)
  • ✅ Interactive and automated control modes
  • ✅ Sine wave, step, and multi-position testing

Rust Implementation (150Hz, 2ms latency) ✅

  • ✅ Memory safety guarantee (zero-cost abstractions)
  • ✅ Type-safe protocol handling
  • ✅ High-performance async control architecture
  • ✅ Cross-platform support (Linux native CAN)
  • ✅ Ownership and thread safety
  • ✅ Compile-time optimizations

Arduino Implementation (50-200Hz, 2-20ms latency) ⏳ TODO

  • ⏳ ESP32/Arduino support
  • ⏳ Low power operation
  • ⏳ Real-time feedback

📊 Supported Motors

Based on High Torque Motor SDK protocol table:

Motor Model Torque Max Speed Reduction Protocol Support
5046_20 17 Nm 50 rad/s 20:1
4538_19 17 Nm 44 rad/s 19:1
5047_36 60 Nm 50 rad/s 36:1
5047_09 17 Nm 33 rad/s 9:1

🔌 CAN Protocol

Communication Architecture

  • Master: Direct control via CAN interface
  • Motor: Support for multi-motor stream control
  • Baud Rate: 1Mbps (standard)
  • Frame Format: Extended frame (29-bit ID)

Key Protocols

1. Motor Scanning (Ping)

# CAN ID: 0x8000 | motor_id
# Data: [0x11, 0x00, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50]

2. Velocity + Acceleration Control (0xAD)

# CAN ID: 0x00AD
# Data: [PosL, PosH, VelL, VelH, AccL, AccH, 0x50, 0x50]

3. Angle Stream Control (0x90)

# CAN ID: 0x0090
# Data: [PosL, PosH, VelL, VelH, TqeL, TqeH, 0x50, 0x50]

🎯 Usage Examples

Python Motor Scanning

from python.can_motor_scanner import LivelyMotorScanner

scanner = LivelyMotorScanner('can0')
if scanner.connect():
    motors = scanner.scan_range(1, 14)
    print(f"Found motors: {motors}")

Python Velocity Control

from python.velocity_acceleration_control import MotorVelAccController

controller = MotorVelAccController('can0', motor_id=1)
controller.enable_sequence()
controller.start_control()
controller.set_velocity(5.0)  # 5 rad/s

Python Angle Control

from python.angle_stream_control import MotorAngleStreamController

controller = MotorAngleStreamController('can0', motor_id=1)
controller.connect()
controller.enable_motor()
controller.set_angle(90.0)  # 90 degrees

🛡️ Safety Features

  • Torque Limiting: Configurable maximum output torque
  • Position Limiting: Software position limits
  • Intelligent Emergency Stop: Automatic maximum deceleration at zero speed
  • Communication Monitoring: Real-time CAN communication status
  • Exception Handling: Comprehensive error handling and recovery

📈 Performance Comparison

Language Control Frequency Latency Memory Usage Status Target Platform
Python 100 Hz 5ms 50MB ✅ Complete Linux Development
C++ 200 Hz 1ms 10MB ✅ Complete Linux Production
Rust 150 Hz 2ms 8MB ✅ Complete Linux Production
Arduino 50-200Hz 2-20ms 10-50KB ⏳ TODO ESP32/MCU

🔍 Troubleshooting

CAN Interface Issues

# Check interface status
ip link show can0

# Reconfigure interface
sudo ip link set can0 down
sudo ip link set can0 up type can bitrate 1000000 restart-ms 100

Permission Issues

# Add user to dialout group
sudo usermod -a -G dialout $USER

# Or run with sudo
sudo python3 can_motor_scanner.py

Hardware Connection

  • Confirm 120Ω terminal resistor
  • Check CAN-H and CAN-L wiring
  • Verify motor power supply is normal
  • Confirm baud rate settings match

📚 Documentation

🗺️ Development Roadmap

✅ Completed

  • Python CAN protocol implementation
  • C++ high-performance implementation (200Hz control loop)
  • Rust memory-safe implementation (150Hz control loop)
  • Motor scanning tool (Python & C++ & Rust)
  • Velocity + acceleration control with intelligent emergency stop (Python & C++ & Rust)
  • Angle stream control (0x90 command) (Python & C++ & Rust)
  • MIT style impedance control (Python & C++ & Rust)
  • Multiple testing modes (interactive, sine wave, step, multi-position)
  • SocketCAN native interface support
  • Multi-threaded control architecture (C++ & async Rust)
  • Type-safe protocol handling (Rust)
  • Zero-cost abstractions (Rust)

⏳ To Implement

  • Arduino/ESP32 implementation
  • GUI control interface
  • Simulation test platform
  • Automatic calibration tools

🚀 Future Plans

  • Automatic motor parameter identification
  • Batch motor management
  • Real-time data visualization
  • Remote control interface
  • Fault diagnosis tools

🤝 Contributing

Issues and Pull Requests are welcome!

How to Contribute

  1. Fork this repository
  2. Create feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add some AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open Pull Request

📄 License

MIT License - See LICENSE file for details

Related Links


Developed based on High Torque Motor SDK protocol table, providing high-performance solutions for robot control

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 27.2%
  • C++ 27.0%
  • Rust 21.7%
  • Shell 14.0%
  • Makefile 10.1%