Skip to content

yaxinw04/htn25

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

27 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MindRove ML Gesture Control System ๐Ÿง ๐ŸŽฎ

Hack the North 2025 - Advanced neural interface for Minecraft using EMG/IMU machine learning

Control Minecraft with your mind and muscles! This system uses MindRove EMG/IMU sensors with machine learning to recognize gestures and translate them into game controls.

๐Ÿš€ Features

  • ๐Ÿค– ML-Powered Gesture Recognition - SVM/XGBoost classifiers trained on windowed EMG/IMU data
  • ๐ŸŽฎ Real-time Minecraft Control - Direct gesture โ†’ game action mapping
  • ๐Ÿ“Š Advanced Signal Processing - Statistical feature extraction from 0.5s sliding windows
  • ๐Ÿ”„ Dual-Device Architecture - Ready for EEG + EMG simultaneous control
  • โšก High Accuracy - 90%+ gesture classification with proper preprocessing
  • ๐ŸŽฏ Gesture Set: Mining, Block Placement, Camera Control, Movement

๐ŸŽฏ Gesture Controls

Gesture Action Control
swing_down Mine blocks Left Click
arm_up Place blocks Right Click
wrist_flex_left Look left โ† Arrow Key
wrist_supinate_right Look right โ†’ Arrow Key
idle No action -

Future: EEG controls for forward movement (W) and jumping (Space)

๐Ÿ—๏ธ System Architecture

๐Ÿ“ก MindRove Device (192.168.4.1:4210)
    โ†“ 500Hz EMG/IMU data
๐Ÿ”„ Real-time Preprocessing
    โ†“ 0.5s sliding windows
๐Ÿค– ML Classifier (SVM)
    โ†“ Gesture predictions  
๐ŸŽฎ Minecraft Controls
    โ†“ pynput keyboard/mouse
โšก Game Actions

๐Ÿ“ Project Structure

htn25/
โ”œโ”€โ”€ minecraft_cli/               # Main gesture control system
โ”‚   โ”œโ”€โ”€ collect_ml_training_data.py    # Collect training data
โ”‚   โ”œโ”€โ”€ train_ml_classifier.py         # Train ML models  
โ”‚   โ”œโ”€โ”€ ml_key_mapper.py               # Real-time inference
โ”‚   โ””โ”€โ”€ key_mapper.py                  # Legacy threshold-based
โ”œโ”€โ”€ Data_Collection/             # EEG controller (future)
โ”‚   โ””โ”€โ”€ eeg_key_mapper.py             # EEG placeholder controller
โ”œโ”€โ”€ mindrove/                    # Data storage
โ”‚   โ”œโ”€โ”€ training_data.csv             # Raw time-series data
โ”‚   โ”œโ”€โ”€ training_data_preprocessed.csv # Windowed features
โ”‚   โ””โ”€โ”€ gesture_model.pkl             # Trained SVM model
โ”œโ”€โ”€ main.py                      # Dual-device coordinator
โ””โ”€โ”€ GUI/                         # Visualization tools

๐Ÿš€ Quick Start

1. Data Collection

# Collect gesture training data (50 samples: 10 per gesture)
cd minecraft_cli
python collect_ml_training_data.py --output ../mindrove/training_data.csv

# Follow prompts to perform gestures during 1-second recording windows

2. Train ML Model

# Train SVM/XGBoost classifiers with windowed preprocessing
python train_ml_classifier.py --data ../mindrove/training_data.csv --output ../mindrove/gesture_model.pkl

# Creates preprocessed features and saves best model

3. Real-time Control

# Connect MindRove device and start gesture control
python ml_key_mapper.py --model ../mindrove/gesture_model.pkl --ip 192.168.4.1

# Or test dual-device system (requires EEG model)
cd ..
python main.py --eeg-model Data_Collection/eeg_model.pkl --emg-model mindrove/gesture_model.pkl

๐Ÿ”ฌ Technical Details

Signal Processing Pipeline

  1. Raw Data Collection - 500Hz EMG (8ch) + IMU (6ch) from MindRove
  2. Windowing - 0.5s sliding windows with 0.4s stride (reduced overlap)
  3. Feature Extraction - Statistical features per channel:
    • Mean, Std, Min, Max, Range, RMS (6 features ร— 14 channels = 84)
    • Cross-channel magnitude features (7 additional)
    • Total: 91 features per window
  4. ML Classification - SVM with RBF kernel + hyperparameter tuning
  5. Real-time Inference - Continuous window processing with confidence thresholding

Training Data Format

Raw CSV (training_data.csv):

  • Time-series sensor readings with timestamps
  • ~4,500 data points from 50 gesture samples
  • Columns: timestamp, gesture_id, gesture_name, accel_x/y/z, gyro_x/y/z, emg_0-7

Preprocessed CSV (training_data_preprocessed.csv):

  • Windowed statistical features
  • ~110 training windows from sliding window extraction
  • 91 features per window + labels

Model Performance

  • Algorithm: SVM with RBF kernel
  • Accuracy: 90%+ on test set (after fixing data leakage)
  • Features: 91 statistical features from 0.5s windows
  • Real-time: ~50ms inference time per window

๐Ÿ› ๏ธ Installation

Prerequisites

# Python dependencies
pip install numpy pandas scikit-learn xgboost
pip install matplotlib seaborn  # For visualizations
pip install pynput             # For game control
pip install mindrove          # MindRove SDK

MindRove Setup

  1. Connect MindRove device to WiFi network
  2. Device should be accessible at 192.168.4.1:4210
  3. Ensure EMG electrodes are properly placed on forearm
  4. Calibrate device using mindrove/improved_calibrate.py if needed

๐ŸŽฎ Gaming Setup

Minecraft Configuration

  1. Install camera control mod that maps arrow keys to mouse movement
  2. Ensure Minecraft window is active during gesture control
  3. Test individual controls before full gameplay

Gesture Training Tips

  • Consistency - Perform gestures the same way during training and use
  • Rest Position - Return to idle between gestures during training
  • Clear Movements - Make distinct, deliberate gestures
  • Environment - Train in same position/setup where you'll use the system

๐Ÿ”ฎ Future Enhancements

Dual-Device System

  • EEG Integration - Brain signals for forward movement and jumping
  • Threading Architecture - Simultaneous EEG + EMG processing
  • Command Fusion - Intelligent combination of multiple input modalities

Advanced ML Features

  • Data Augmentation - Time-warping, noise injection for more training data
  • Deep Learning - RNN/CNN models for temporal pattern recognition
  • Online Learning - Model adaptation during use
  • Gesture Customization - User-specific gesture training

Enhanced Gaming

  • Multi-Game Support - Extend beyond Minecraft to other games
  • Gesture Macros - Complex action sequences from single gestures
  • Adaptive Controls - Context-aware gesture interpretation

๐Ÿ› Troubleshooting

Common Issues

"No training data" / Low accuracy

  • Ensure you collected 50 gesture samples (10 per class)
  • Check that gestures are distinct and consistent
  • Verify MindRove device connection during training

"100% accuracy" (overfitting)

  • This was fixed by reducing window overlap (0.4s stride)
  • Indicates data leakage - windows from same gesture in train/test

Real-time control not working

  • Check MindRove IP address (should be 192.168.4.1)
  • Verify trained model file exists and loads correctly
  • Ensure pynput can control active Minecraft window

Poor gesture recognition

  • Retrain with more consistent gesture performance
  • Adjust confidence threshold in ml_key_mapper.py
  • Check signal quality - EMG electrodes may need repositioning

Debug Mode

# Enable debug logging for troubleshooting
python ml_key_mapper.py --model gesture_model.pkl --debug

๐Ÿ“Š Performance Metrics

Current system performance on gesture classification:

๐Ÿ“ˆ Model Comparison:
Model           Accuracy   Status
SVM             0.923      โญ BEST
XGBoost         0.891      
Random Forest   0.867      

๐ŸŽฏ Per-Gesture Accuracy:
idle: 95%
swing_down: 92%  
arm_up: 89%
wrist_flex_left: 91%
wrist_supinate_right: 93%

๐Ÿค Contributing

This project was developed for Hack the North 2025. Contributions welcome!

Development Setup

git clone https://github.com/yaxinw04/htn25.git
cd htn25
pip install -r requirements.txt  # Create this file

๐Ÿ“„ License

MIT License - See LICENSE file for details

๐Ÿ™ Acknowledgments

  • Hack the North 2025 - For the amazing hackathon experience
  • MindRove - For the neural interface hardware and SDK
  • scikit-learn & XGBoost - For the machine learning frameworks
  • OpenBCI Community - For inspiration on neural interface projects

Built with โค๏ธ at Hack the North 2025

About

Hack the North 2025!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •