Adapted from https://github.com/simlabrobotics/allegro_hand_linux_v4 and https://github.com/michguo/allegro_hand_linux_v4.
This interface allows communicating with a v4 Allegro hand via ZMQ, providing both C++ and Python APIs for controlling the hand.
allegro_hand_zmq/
├── cpp/ # C++ source code and headers
│ ├── src/ # C++ implementation files
│ ├── include/ # C++ header files
│ └── CMakeLists.txt # C++ build configuration
├── allegro_zmq/ # Python package
│ ├── allegro.py # Python wrapper for BHand library
│ ├── examples/ # Python usage examples
│ └── utils/ # Python utilities
├── build.sh # Build script for C++ components
├── run_zmq_server.sh # Script to start ZMQ server
└── README.md # This file
# Install required packages
sudo apt update
sudo apt install build-essential cmake pkg-config libpopt-dev
# Install ZMQ development libraries
sudo apt install libzmq3-dev libcppzmq-dev
# Install nlohmann/json for JSON parsing
conda install -c conda-forge nlohmann_json
Download, build, and install PCAN-USB driver for Linux: libpcan
# Download and extract the driver
tar -xzvf peak-linux-driver-x.x.tar.gz
cd peak-linux-driver-x.x
# Build and install
make NET=NO
sudo make install
- If encounter
Run
src/pcan-settings.c:47:10: fatal error: popt.h: No such file or directory 47 | #include <popt.h> | ^~~~~~~~ compilation terminated.
sudo apt install libpopt-dev
Download, build, and install PCAN-Basic API for Linux: libpcanbasic
# Download and extract
tar -xzvf PCAN_Basic_Linux-x.x.x.tar.gz
cd PCAN_Basic_Linux-x.x.x/libpcanbasic
# Build and install
make
sudo make install
sudo ldconfig
Download, build, and install Grasping Library for Linux: libBHand
# Extract the appropriate version (32-bit or 64-bit)
unzip LibBHand_64.zip # or LibBHand_32.zip for 32-bit systems
cd libBHand_64
# Install the library
sudo make install
sudo ldconfig
Use the provided build script to compile the C++ ZMQ server:
# Navigate to the repository root
cd allegro_hand_zmq
# Build the C++ components
./build.sh
# For a clean build (removes previous build files)
./build.sh clean
The build script will:
- Configure CMake with proper library paths
- Compile the C++ source code in
cpp/src/
- Create the executable at
build/bin/grasp
- Handle dependency linking automatically
Install the Python package for client-side control:
# Install in development mode
pip install -e .
- Connect the PCAN-USB adapter to your computer
- Connect the PCAN-USB to the Allegro Hand CAN interface
- Important: Ensure the Allegro Hand is powered OFF before starting the software
Launch the C++ ZMQ server that interfaces with the hand:
# Start the ZMQ server (keep this running)
./run_zmq_server.sh
The server will:
- Initialize the PCAN-USB connection
- Load the BHand control library
- Start the ZMQ server on the default port
- Wait for client connections
After the server is running and shows "Ready", power on the Allegro Hand.
Use the Python wrapper for high-level control:
from allegro_zmq.allegro import create_allegro_hand, AllegroMotionType
# Create hand controller
hand = create_allegro_hand("right")
hand.initialize_hand()
# Move to home position
home_cmd = hand.create_home_command()
hand.execute_command(home_cmd)
# PD control with custom positions
import numpy as np
positions = np.zeros(16) # 16 joint positions
pd_cmd = hand.create_pd_command(positions)
hand.execute_command(pd_cmd)
# Get hand state
state = hand.get_hand_state()
print(f"Current motion: {state['motion_type']}")
Run the provided examples:
# Rock Paper Scissors demo
python allegro_zmq/examples/run_rock_paper_scissors.py
The Python API supports all BHand library motion types:
eMotionType_NONE
- Power offeMotionType_HOME
- Home positioneMotionType_READY
- Ready positioneMotionType_GRAVITY_COMP
- Gravity compensationeMotionType_JOINT_PD
- Joint PD controleMotionType_GRASP_3
- 3-finger graspeMotionType_GRASP_4
- 4-finger graspeMotionType_PINCH_IT
- Index-thumb pincheMotionType_PINCH_MT
- Middle-thumb pincheMotionType_ENVELOP
- Enveloping graspeMotionType_MOVE_OBJ
- Object manipulationeMotionType_FINGERTIP_MOVING
- Fingertip control
- C++ Code: All C++ source files are in
cpp/src/
with headers incpp/include/
- Python Code: Python wrapper and utilities in
allegro_zmq/
- Build System: Modern CMake with automatic dependency detection
- Examples: Both C++ and Python examples provided
# Clean build
./build.sh clean