Skip to content

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

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 image folder
  • ๐Ÿ’Ž 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
๐Ÿฅง 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 to False.
  • When ip is left blank, the Raspberry Pi's IP address will be auto-detected. If the network environment is complex, you can manually specify it.
  • The port must match the sending port on the Windows and iOS sides.
  • To add more PCA9685 boards, add their addresses to the pca9685_address list (e.g., [0x40, 0x41]).
  • The configuration in neck_config_file is 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

๐Ÿ“บ Welcome to watch my Bilibili


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.