Project files
- .github1 file
- 3D-Models38 files
- CreateAnimation2 files
- images10 files
- RaspberryPi17 files
- UnityArkit1538 files
- Windows11 files
- .gitignore2 KB
- AGENTS.md5 KB
- CHECKLIST.md5 KB
- CONTRIBUTING.md6 KB
- LICENSE1 KB
- PACKAGING.md3 KB
- README.md12 KB
README.md
Machine-translated by Robotheca from the original in Chinese (opens in a new tab). License: MIT (opens in a new tab).
๐ค HeadNeckControl
๐ฏ Biomimetic Neck Servo Control System Based on RBF
๐ฆพ Real-time control and animation playback of a bionic head via tendons
๐น Demo
๐ป Bionic Neck Operation Demonstration

โจ Real-time tracking demonstration of the bionic neck โจ
๐ Project Introduction
HeadNeckControl is a complete bionic neck control system that simulates muscle movement by using a Raspberry Pi and PCA9685 to drive servos that pull tendons, controlling the movement of a bionic head. The system supports multiple control methods: ARKit facial tracking via a smartphone, animation file playback, manual control and testing mode on Windows, and can precisely control the three degrees of freedomโpitch, yaw, and rollโof the head.
โจ Features
- ๐ฑ ARKit Real-time Tracking: Capture facial poses using ARKit on iOS devices and send them directly to the Raspberry Pi via UDP for real-time control
- ๐ฎ Unity iOS App: Provides a complete Unity project for generating ARKit facial tracking iOS apps, supporting customization and extension
- ๐ฌ Animation Playback: Supports playing preset head motion sequences, with animation files stored locally on the Raspberry Pi
- ๐ฑ๏ธ Windows Manual Control: Offers a graphical interface with sliders to directly control servo angles
- ๐ง Test Mode: A test mode for debugging and calibrating servos
- ๐จ Smooth Transitions: Uses RBF (Radial Basis Function) interpolation algorithms to achieve smooth motion transitions
- ๐ Multiple Input Sources: Supports flexible switching between various input sources
๐๏ธ System Architecture
โโโโโโโโโโโโโโโโโโโ UDP โโโโโโโโโโโโโโโโโโโโ
โ Windows App โ โโโโโโโโโโโ> โ Raspberry Pi โ
โ (C# .NET 8) โ โ (Python 3.11) โ
โ โ โ โ
โ - TrackBar โ โ - BaseInput โ
โ - Manual Controlโ โ - HeadMapper โ
โโโโโโโโโโโโโโโโโโโ โ - ServoControllerโ
โโโโโโโโโโฌโโโโโโโโโโ
โ
UDP โ I2C
โโโโโโโโโโโโโโโโโโโ โ
โ iOS Device โ โโโโโโโโโโโโโโโโโโโโโโโค
โ (ARKit) โ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ PCA9685 โ
โ (PWM Driver) โ
โโโโโโโโฌโโโโโโโโ
โ
Servos
โผ
โโโโโโโโโโโโโโโโ
โ Bionic Head โ
โโโโโโโโโโโโโโโโ
๐ก Data Flow Description:
- ๐ป Windows Side: Manually control servo angles via sliders and send servo angle data to the Raspberry Pi over UDP
- ๐ iOS ARKit Side: Directly send facial pose data captured by ARKit to the Raspberry Pi over UDP
- ๐๏ธ Animation Playback: Animation files (
.anim) are stored locally on the Raspberry Pi and read/played by the Raspberry Pi - ๐ฅง Raspberry Pi: Acts as the control center, receiving data from all input sources, mapping it via HeadMapper, and controlling the servos
๐ Hardware List
๐ฆ Required Hardware
- ๐ฅง Raspberry Pi: 3B+ or higher version
- ๐ป Windows PC: Any, must be on the same local network as the Raspberry Pi
- ๐ PCA9685 PWM Driver Board: One piece
- โ๏ธ Servo Motors: MG996R or similar metal-gear servos (8 pieces), each requiring a cross-shaped servo horn, pre-set to 90 degrees
- ๐ Power Supply: 12V 100W power supply + 2-4 5V/5A buck converter modules (adjust based on actual needs)
- ๐ Dupont Wires, Jumper Wires: Several, for connecting power supply, Raspberry Pi, PCA9685, and servos
- ๐งต Dyneema Rope: 1.5mm diameter, 5 meters long; must be pre-stretched (hang a heavy object for a day or two) and cut into 12 pieces, each 35cm long
- ๐ฌ Teflon Tubes: Inner diameter 2mm * outer diameter 3mm, 2 meters long; cut into appropriate lengths based on the images in the
imagefolder - ๐ Ceramic Eyes: Outer diameter 3.9mm * hole 2.3mm * total height 6mm (25 pieces)
- โญ Small Bearings: 9 * 14 * 2.5mm (8 pieces)
- ๐ซง TPU O-rings: 8mm diameter * 2mm width (8 pieces); rubber bands of similar size can be used as substitutes
- ๐ง Glue: 502 or other quick-drying adhesive
- ๐ฉ Screws: Flat-head self-tapping M3 * 8mm (50 pieces), flat-head M3 * 5mm (8 pieces), flat-head self-tapping M2 * 10mm (32 pieces), flat-head self-tapping M2 * 8mm (12 pieces), M2 * 10mm + nuts (8 sets) (it's recommended to prepare extra screws as they are easily lost ๐ )
๐ ๏ธ Optional Hardware
- ๐งฉ Breadboard (optional): Used for circuit connections
- ๐งด Edge-straightening liquid (optional): Used to smooth out frayed wire ends for easier threading; ordinary office glue can be used as a substitute
- ๐ช Lubricating grease (optional): For lubricating joint connections, preferably included
๐ง Tools you might want to have
- โ๏ธ Screwdrivers, pliers: If you don't have these, you might as well give up on this project ๐
- ๐จ๏ธ FDM 3D printer: Ideally with a build volume larger than 200 ร 200 ร 200 mm; if you donโt have one, find a printing service
- ๐ช Rotary tool: For cleaning up rough details on printed parts; if you donโt have one, sandpaper will do in a pinch
๐ What we hope you can have
- ๐ Strong hands-on ability: All components of this project need to be assembled by yourself ๐
- ๐ Great patience: The proportions of this neck are designed based on the size of a real 5-6-year-old child. Many parts are very small and difficult to install, so if you've already started, please be patient โค
๐ Quick Start
๐งฉ Model Assembly and Control
- Please watch the video on Bilibili: Daughter's Neck Open Source! (opens in a new tab)
๐ฅง Raspberry Pi Environment Configuration
1๏ธโฃ System Requirements
- Operating System: Raspberry Pi OS
- Python Version: Python 3.10 or higher (this system uses Python 3.11)
- Memory: At least 2GB RAM (4GB recommended)
2๏ธโฃ Clone the project (recommended to clone on a PC, not on a Raspberry Pi; then copy the RaspberryPi folder to the Raspberry Pi)
cd ~
git clone https://github.com/yourusername/HeadNeckControl.git
cd HeadNeckControl/RaspberryPi
3๏ธโฃ Install Python Dependencies
# Update the system
sudo apt update
sudo apt upgrade -y
# Install system dependencies
sudo apt install -y python3-pip python3-dev
# Install Python packages
pip3 install -r requirements.txt
4๏ธโฃ Enable the I2C interface
# Method 1: Use raspi-config
sudo raspi-config
# Select Interface Options -> I2C -> Enable
# Method 2: Command line
sudo apt install -y i2c-tools
sudo raspi-config nonint do_i2c 0
# Reboot the Raspberry Pi
sudo reboot
5๏ธโฃ Verify I2C Connection
After rebooting, check if the PCA9685 is detected: ๐
# List all I2C devices
i2cdetect -y 1
# You should see output similar to the following (0x40 is the default address of PCA9685):
# 0 1 2 3 4 5 6 7 8 9 a b c d e f
# 00: -- -- -- -- -- -- -- -- -- -- -- -- --
# 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# 40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- --
# ...
If you see 40, the PCA9685 is correctly connected.
6๏ธโฃ Configuring config.py
Edit the RaspberryPi/config.py file and modify the following configurations according to your hardware and network environment:
class Config():
DEBUG = True # Debug mode: True = do not operate hardware, only print values; False = actually control servos
ip = '' # Raspberry Pi IP address (leave blank for auto-detection, or manually fill in like '192.168.1.100')
port = 9003 # UDP listening port (receives ARKit/Windows data)
servo_count = 8 # Total number of servos
test_servo_count = 8 # Number of servos in test mode
pca9685_address = [0x40] # PCA9685 driver board I2C address (supports multiple boards)
pca_frequency = 50 # PWM frequency (Hz), typically 50 for servos
is_anim = False # Whether to load animation file; no need to change, will be automatically updated based on options
anim_file = 'anim_data/neck.anim' # Animation file path
neck_config_file = 'controller/neck_matrix_config.json' # Servo angle mapping configuration file, exported from Windows matrix file
โ๏ธ Configuration Notes:
- For the first run, it is recommended to keep
DEBUG = True. After verifying that data reception and mapping logic are normal, change it toFalse. - When
ipis left blank, the Raspberry Pi's IP address will be auto-detected. If the network environment is complex, you can manually specify it. - The
portmust match the sending port on the Windows and iOS sides. - To add more PCA9685 boards, add their addresses to the
pca9685_addresslist (e.g.,[0x40, 0x41]). - The configuration in
neck_config_fileis generated by the tool on the Windows side.
๐ Project Structure
HeadNeckControl/
โโโ RaspberryPi/ # Raspberry Pi code (Python)
โ โโโ main.py # Main program entry
โ โโโ config.py # Configuration file
โ โโโ controller/ # Controller module
โ โ โโโ servo_controller.py # Servo controller
โ โ โโโ head_mapper.py # Head pose mapper
โ โโโ input/ # Input source module
โ โ โโโ base_input.py # Base input class
โ โ โโโ input_arkit.py # ARKit input source
โ โ โโโ input_anim.py # Animation file input source
โ โ โโโ input_ai.py # AI input source
โ โ โโโ input_test.py # Test input source
โ โโโ utils/ # Utility module
โ โ โโโ filetools.py # File processing tools
โ โโโ anim_data/ # Animation file directory
โ โโโ requirements.txt # Python dependencies
โ
โโโ Windows/ # Windows code (C#)
โ โโโ NeckControlOutput/
โ โโโ Form1.cs # Main form
โ โโโ Form1.Designer.cs # Form designer (auto-generated)
โ โโโ Models.cs # Data models
โ โโโ RBFHelper.cs # RBF interpolation helper
โ โโโ WeightMatrixHelper.cs # Weight matrix calculator
โ โโโ Program.cs # Program entry
โ โโโ NeckControlOutput.csproj # Project file
โ
โโโ UnityArkit/ # Unity iOS ARKit app
โ โโโ Assets/ # Unity assets and scripts
โ โ โโโ Scenes/ # Scene files
โ โ โโโ Scripts/ # C# scripts
โ โ โโโ Samples/ # AR Foundation samples
โ โโโ Packages/ # Unity package configuration
โ โโโ ProjectSettings/ # Project settings
โ โโโ UnityArkit.sln # Solution file
โ
โโโ 3D-Models/ # 3D printing model files
โ โโโ OBJ/ # Wavefront OBJ format models
โ โโโ 3MF/ # Bambu Studio slicing format models
โ โโโ README.md # 3D printing instructions
โ
โโโ AGENTS.md # Developer guide
โโโ CHECKLIST.md # Project checklist
โโโ CONTRIBUTING.md # Contribution guide
โโโ LICENSE # MIT License
โโโ PACKAGING.md # Packaging and release guide
โโโ README.md # This file
โโโ .gitignore # Git ignore rules
๐ค Contributing
Contributions to the code, bug reports, and improvement suggestions are welcome! Please read CONTRIBUTING.md for details.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Adafruit's CircuitPython (opens in a new tab) library
๐บ Welcome to watch my Bilibili
- ๐บ Bilibili ๆ็ถ็ธ็ธๅ (opens in a new tab)
Made with โค๏ธ by ๐ Robotics Enthusiasts ๐คโจ
Files by @xingyaodad, at commit 839e836, read from GitHub in your browser. Hardware license: MIT; software license: MIT. Robotheca doesn't review code: read it before running it.