A Python library for controlling the Inspire Hand robotic hand via serial communication and Modbus TCP. This package provides a simple and intuitive API for connecting to and controlling the Inspire Hand through various motion commands and sensor readings.
- Dual Communication Protocols: Support for both Serial and Modbus TCP communication
- Simple API: Easy-to-use Python interface for hand control
- Motion Control: Set individual finger angles, perform predefined gestures
- Sensor Reading: Read current angles, forces, and temperature data
- Error Handling: Built-in error detection and recovery
- Cross-Platform: Works on Windows, Linux, and macOS
- Configurable: Customizable communication parameters
- Multi-Generation Support: Compatible with Gen3 and Gen4 Inspire Hands
- Stress Testing: Built-in stress testing and performance monitoring
# Clone the repository
git clone https://github.com/TechShare-inc/inspire_demos.git
cd inspire_demos
# Install in development mode
pip install -e .
# Or install with development dependencies
pip install -e ".[dev]"
pip install inspire-demos
from inspire_demos import InspireHandSerial
import time
# Create API instance for serial communication
api = InspireHandSerial(port="COM7", baudrate=115200)
# Connect to the hand
api.connect()
# Reset errors and open hand
api.reset_error()
api.perform_open()
time.sleep(1)
# Set custom finger angles (0-1000 range)
api.set_angle([500, 800, 600, 400, 200, 1000])
time.sleep(2)
# Perform predefined gestures
api.perform_close() # Close hand
time.sleep(1)
api.perform_open() # Open hand
# Disconnect
api.disconnect()
from inspire_demos import InspireHandModbus
import time
# Create API instance for Modbus TCP communication
api = InspireHandModbus(ip="192.168.11.210", port=6000, generation=3)
# Connect to the hand
api.connect()
# Set custom finger angles (0-1000 range)
api.set_angle([500, 800, 600, 400, 200, 1000])
time.sleep(2)
# Read current angles
current_angles = api.getangleact()
print(f"Current angles: {current_angles}")
# Disconnect
api.disconnect()
The examples/
directory contains demonstration scripts:
basic_serial_demo.py
: Basic serial communication and motion sequence demonstrationmodbus_demo.py
: Modbus TCP communication demonstrationdual_interface_demo.py
: Demonstrates using both serial and Modbus interfacesstress_test_demo.py
: Performance testing and stress testing capabilities
# Basic serial demo
python examples/basic_serial_demo.py
# Modbus demo
python examples/modbus_demo.py
# Dual interface demo
python examples/dual_interface_demo.py
# Stress test demo
python examples/stress_test_demo.py
Main class for controlling the Inspire Hand via serial communication.
connect()
: Establish serial connection to the handdisconnect()
: Close serial connection
set_angle(angles, hand_id=1)
: Set finger angles (list of 6 integers, 0-1000)perform_open()
: Open all fingersperform_close()
: Close all fingersreturn_to_zero()
: Return to zero positionset_speed(hand_id, speeds)
: Set motion speedsset_force(hand_id, forces)
: Set force limits
getangleact(hand_id=1)
: Get current finger anglesgetforceact(hand_id=1)
: Get current forcesgettemp(hand_id=1)
: Get temperature readingsgeterror(hand_id=1)
: Get error codes
reset_error()
: Clear error conditions
Main class for controlling the Inspire Hand via Modbus TCP.
InspireHandModbus(ip="192.168.11.210", port=6000, generation=3, debug=False)
connect()
: Establish Modbus TCP connection to the handdisconnect()
: Close Modbus TCP connection
set_angle(angles)
: Set finger angles (list of 6 integers, 0-1000)set_position(positions)
: Set finger positionsset_speed(speeds)
: Set motion speedsset_force(forces)
: Set force limits
getangleact()
: Get current finger anglesgetpositionact()
: Get current finger positionsgetforceact()
: Get current forcesgettemp()
: Get temperature readings
- Connect the Inspire Hand to your computer via USB
- Install appropriate drivers if needed
- Note the serial port:
- Windows: Usually
COM3
,COM7
, etc. - Linux: Usually
/dev/ttyUSB0
,/dev/ttyACM0
, etc. - macOS: Usually
/dev/tty.usbserial-*
- Windows: Usually
- Connect the Inspire Hand to your network via Ethernet
- Configure the hand's IP address (default:
192.168.11.210
) - Ensure network connectivity between your computer and the hand
- Default Modbus port:
6000
- Port:
COM3
(Windows) or/dev/ttyUSB0
(Linux/macOS) - Baudrate:
115200
- IP Address:
192.168.11.210
- Port:
6000
- Generation:
3
(use4
for Gen4 hands)
# Custom serial configuration
from inspire_demos import InspireHandSerial
api = InspireHandSerial(port="/dev/ttyUSB1", baudrate=9600)
# Custom Modbus TCP configuration
from inspire_demos import InspireHandModbus
api = InspireHandModbus(ip="192.168.1.100", port=502, generation=4, debug=True)
# Check available serial ports
import serial.tools.list_ports
ports = list(serial.tools.list_ports.comports())
for port in ports:
print(f"Port: {port.device}, Description: {port.description}")
# Clone the repository
git clone https://github.com/TechShare-inc/inspire_demos.git
cd inspire_demos
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode with dev dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
# Run all tests
pytest
# Run with coverage
pytest --cov=inspire_demos --cov-report=html
# Run specific test file
pytest tests/test_api.py
The library includes built-in stress testing capabilities for performance evaluation:
# Run stress test demo
python examples/stress_test_demo.py
# This will generate:
# - CSV data files with performance metrics
# - PNG visualization plots
# - TXT reports with statistics
Stress test outputs include:
- Response time measurements
- Success/failure rates
- Performance graphs and charts
- Detailed statistical reports
This project uses several tools to maintain code quality:
- Black: Code formatting
- Flake8: Linting
- MyPy: Type checking
- Pre-commit: Git hooks for code quality
# Format code
black src/ examples/ tests/
# Check linting
flake8 src/ examples/ tests/
# Type checking
mypy src/
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Python 3.8 or higher
- Core Dependencies:
pyserial>=3.4
: Serial communicationpymodbus>=3.0
: Modbus TCP communicationnumpy>=1.20
: Numerical computationsloguru>=0.6
: Loggingmatplotlib>=3.5
: Data visualization and plotting
- Hardware: Inspire Hand robotic device with serial or network connection
-
Serial Connection Failed:
- Check if the device is properly connected via USB
- Verify the correct COM port
- Ensure no other applications are using the port
- Try different baudrate settings
-
Modbus TCP Connection Failed:
- Verify network connectivity (
ping 192.168.11.210
) - Check if the hand's IP address is correct
- Ensure the Modbus port (6000) is not blocked by firewall
- Verify the hand is powered on and network-enabled
- Verify network connectivity (
-
Permission Denied (Linux/macOS):
sudo chmod 666 /dev/ttyUSB0 # Or add user to dialout group sudo usermod -a -G dialout $USER
-
Import Errors:
- Make sure the package is installed:
pip install -e .
- Check Python path includes the src directory
- Verify all dependencies are installed:
pip install -e ".[dev]"
- Make sure the package is installed:
-
Generation Compatibility:
- Use
generation=3
for Gen3 Inspire Hands - Use
generation=4
for Gen4 Inspire Hands - Check hand documentation for correct generation
- Use
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please open an issue on the GitHub repository.
- Added Modbus TCP communication support
- Enhanced API with dual protocol support (Serial + Modbus TCP)
- Added multi-generation support (Gen3/Gen4)
- Improved stress testing capabilities
- Updated documentation and examples
- Added debug mode for troubleshooting
- Initial release
- Basic API for hand control
- Example scripts
- Unit tests
- Documentation
## API Features
The library provides comprehensive functionality through two main classes:
### InspireHandSerial Features:
- Connect/disconnect via serial communication
- Reset errors and error handling
- Set finger angles and positions
- Set movement speed and force limits
- Read current angles, positions, forces, and sensor data
- Perform predefined actions (open/close)
- Support for multiple hand IDs
### InspireHandModbus Features:
- Connect/disconnect via Modbus TCP
- Set finger angles and positions
- Set movement speed and force limits
- Read current angles, positions, forces, and sensor data
- Support for Gen3 and Gen4 hand generations
- Debug mode for troubleshooting
- Network-based communication
## Error Handling
The API includes built-in error handling for:
- Serial communication issues
- Modbus TCP connection problems
- Invalid COM ports and network addresses
- Communication timeouts and retries
- Hardware error detection and reporting
- Graceful shutdown on keyboard interrupt
## Notes
- Make sure the hand is properly connected before running the scripts
- **Serial Communication**: Default baudrate is 115200
- **Modbus TCP**: Default IP is 192.168.11.210, port 6000
- The API supports both Windows and Linux systems
- All angle values are in the range of 0-1000
- Choose the appropriate communication method based on your hardware setup
- Use `generation=3` for Gen3 hands, `generation=4` for Gen4 hands
- Enable debug mode for troubleshooting network communication issues