Motion Capture System
This repository contains the code and documentation for a low-cost, modular motion capture system based on BNO055 IMU sensors. The system consists of ESP32 microcontrollers, multiple BNO055 IMU sensors connected via an I2C multiplexer, and a web application for real-time 3D visualization.
Table of Contents
System Architecture
The system consists of three main components:
Sensor Node: An ESP32-S3 microcontroller connected to eight BNO055 IMU sensors via a TCA9548A I2C multiplexer. The node reads sensor data and sends it to the receiver.
Receiver: Another ESP32-S3 microcontroller that acts as a bridge between the sensor node and the computer. It creates a WiFi access point for the node to connect to and communicates with the computer via USB CDC.
Control Application: A web application built with Svelte and Three.js for real-time 3D visualization and system control.
Hardware Components
- 2× Xiao ESP32-S3 microcontrollers (Node and Receiver)
- 8× BNO055 IMU sensors
- 1× TCA9548A I2C multiplexer
- Connecting wires and power supply
Communication Protocol
The system uses multiple communication protocols for different purposes:
Network Configuration
- The Receiver creates a WiFi access point with SSID "MotionCaptureAP"
- The Node connects to this access point as a client
- Static IP addressing is used:
- Receiver (AP): 192.168.4.1
- Node: 192.168.4.2
Communication Channels
TCP Protocol (Port 5006): Used for:
- Command and control messages
- System logs
- Status updates
- Heartbeat messages
UDP Protocol (Port 5005): Used for:
- High-frequency sensor data streaming
- Optimized for low latency and high throughput
- Includes sequence numbers for packet loss detection
USB CDC: Used for:
- Communication between Receiver and computer
- Data forwarding from both TCP and UDP channels
Command System
The system implements a robust command protocol over TCP:
Command |
Description |
S |
Start streaming sensor data |
X |
Stop streaming sensor data |
C |
Check sensor status |
I |
Initialize/reinitialize sensors |
N |
Restart node |
R |
Restart receiver |
P |
Ping node (connection test) |
D:n |
Set debug level (0=DEBUG, 1=INFO, 2=WARNING, 3=ERROR) |
Q |
Quit (emergency stop) |
Sensor Configuration
BNO055 Sensor Configuration
The BNO055 sensors provide 9-axis motion tracking with built-in sensor fusion. They output:
- Quaternion orientation data
- Calibration status
- Temperature readings
I2C Multiplexer Setup
The system connects 8 BNO055 sensors using a TCA9548A I2C multiplexer. The configuration is:
- TCA9548A I2C Address: 0x70
- BNO055 Sensors:
- Sensors alternate between addresses 0x28 and 0x29
- Each multiplexer channel hosts 2 sensors (one at each address)
Features
Node Features
Multi-Sensor Management:
- Efficiently reads data from 8 BNO055 sensors using I2C multiplexing
- Implements time-division access to each sensor
- Handles sensor calibration and status monitoring
Robust Communication:
- Sends sensor data via UDP for high-frequency streaming
- Uses TCP for commands, logs, and heartbeats
- Implements error handling and retry mechanisms
Advanced Error Recovery:
- Detects and handles sensor disconnections
- Provides I2C bus recovery mechanisms
- Implements multiplexer reset capabilities
System Monitoring:
- Tracks memory usage
- Reports active sensor count
- Provides detailed logging with configurable verbosity
Receiver Features
Network Management:
- Creates and manages WiFi access point
- Handles TCP and UDP socket creation
- Monitors network connections
Command Processing:
- Routes commands from computer to node
- Processes responses and forwards to computer
- Implements command validation and error handling
Data Streaming:
- Receives UDP sensor data from node
- Processes and forwards to computer
- Tracks packet statistics (lost packets, rate)
USB Communication:
- Provides interface between wireless network and computer
- Handles bidirectional communication
- Formats data for downstream processing
Web Application Features
Real-time Visualization:
- 3D model rendering with Three.js
- Real-time motion tracking
- Customizable visualization options
System Control:
- Command interface for system control
- Status monitoring and notifications
- Diagnostic tools
Data Processing:
- Sensor data parsing and interpretation
- Calibration and correction tools
- Performance analytics
Software Setup
Prerequisites
- Node.js 18+ and npm/pnpm
- Python 3.8+ (for development tools)
- Serial port access on your computer
Installation
Clone the repository:
git clone https://github.com/chandikajayaweera/MoCap-Suit.git
cd MoCap-Suit-master
Install dependencies:
cd app
npm install
Flash firmware to ESP32 devices:
- Connect the ESP32 for the receiver
- Use PyMakr or Thonny IDE to upload the
esp32/receiver
files
- Connect the ESP32 for the sensor node
- Use PyMakr or Thonny IDE to upload the
esp32/node
files
Start the application:
npm run dev
Access the interface:
Open your browser and navigate to http://localhost:5173
Usage
Connecting to the System
- Connect the receiver ESP32 to your computer via USB
- Power on the sensor node ESP32 using a portable power bank
- In the web interface, select the COM port for the receiver
- Click "Connect" to establish communication
Sensor Placement
Attach the sensors to the following body parts:
- Sensor 0: Right Lower Leg
- Sensor 1: Right Upper Leg
- Sensor 2: Left Lower Leg
- Sensor 3: Left Upper Leg
- Sensor 4: Left Lower Arm
- Sensor 5: Left Upper Arm
- Sensor 6: Right Lower Arm
- Sensor 7: Right Upper Arm
Calibration
- Stand in a T-pose position
- In the web interface, open the "Calibration" panel
- Click "Capture T-Pose" to set the reference orientation
- Use the advanced adjustments to fine-tune individual sensors if needed
Recording and Playback
- Open the "Recorder" panel in the web interface
- Enter a name for your recording
- Click "Start Recording" to begin capturing motion
- Click "Stop Recording" when finished
- Select a recording from the list to play it back
Command Interface
The system supports the following commands:
- S: Start streaming
- X: Stop streaming
- C: Check sensors
- I: Initialize sensors
- P: Ping node
- N: Restart node
- R: Restart receiver
- D:0-3: Set debug level
These commands can be sent from the web interface or using the CLI tool.
Command Line Interface
For advanced users, a command-line interface is available:
cd app
npm run cli
The CLI provides direct access to all system commands and real-time data monitoring.
Troubleshooting
Common Issues
- No serial ports detected: Ensure you have the correct drivers installed for your ESP32 devices
- Connection fails: Check that both ESP32 devices are powered and the receiver is properly connected via USB
- Sensors not responding: Verify the wiring and connections to the multiplexer
- Inaccurate motion: Follow the calibration procedure and ensure sensors are securely attached
Debug Mode
Enable debug mode in the web interface to view detailed logs and sensor data.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add some amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
License
This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License (CC BY-NC 4.0).
What this means:
- You are free to share and adapt this work for non-commercial purposes
- You must provide appropriate credit to the original author (Nambige C Jayaweera)
- You cannot use this work for commercial purposes without permission
For more details, see the full license text.
Acknowledgments
- Peter Hinch for the BNO055 MicroPython driver
- The original Adafruit CircuitPython BNO055 driver by Radomir Dopieralski
- Three.js community for 3D visualization tools
- Svelte team for the reactive UI framework
If you have any questions or feedback, please open an issue in the GitHub repository or email me at chandikajayaweera@pm.me