Skip to content

Brain Computer Interface system for robot control using EMG/EEG. Workflow: Electrodes -> Arduino -> Host -> ESP32 -> engine

Notifications You must be signed in to change notification settings

JuaniRaggio/Robrain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

115 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Robrain

BCI (Brain Computer Interface) system for robot control using EMG/EEG signals.

TODO List pendiente

YA

  • (host) Leer info del arduino

  • (host) Realizar promedio de muestras de forma vectorizada (en el futuro esto seria procesamiento)

  • (host) Enviar indicaciones al esp32 via BLE

  • (esp32) Leer indicaciones

  • (esp32) Actuar

Note

Importante tener en cuenta la siguiente data:

Baudrate Tiempo para 256 bytes (aprox.)
9600 ~267 ms
115200 ~22 ms
1000000 ~2.5 ms

Que hacer ahora?

  • Configuracion de Comunicacion serial entre Arduino y Host
  • Protocolo de comunicacion serial
  • Implementar la comunicacion
  • Configuracion de Conexion BLE
  • Protocolos de comunicacion entre esp32 y el host
  • Implementar la comunicacion

Paso "intermedio" para tener algo funcionando

  • Implementar un procesamiento MUY simple de señales
  • Control de motores

Para el final (Lo mas jodido)

  • Filtrar señales
  • Implementar procesamiento ML-based

Project Structure

robrain/
├── common/           # Shared protocol between components
├── docs/             # Technical documentation
├── firmware/
│   ├── arduino-emg/  # EMG signal capture (PlatformIO)
│   └── esp32-robot/  # Robot motor control (PlatformIO)
└── host/             # Laptop application (CMake)

Data Flow

[Electrodes] --> [Arduino] --serial--> [Laptop] --BLE--> [ESP32] --> [Motors]
                    EMG                 processes         robot
                                        signals

Requirements

Host (Laptop)

  • CMake >= 3.16
  • C++17 compiler (GCC, Clang)
  • Boost
  • SimpleBLE (for BLE communication)
# Ubuntu/Debian
sudo apt install cmake build-essential libboost-dev libbluetooth-dev

# macOS
brew install cmake boost

# SimpleBLE (all platforms)
# https://github.com/OpenBluetoothToolbox/SimpleBLE
git clone https://github.com/OpenBluetoothToolbox/SimpleBLE.git
cd SimpleBLE && mkdir build && cd build
cmake .. && make && sudo make install

Firmwares (Arduino and ESP32)

  • PlatformIO Core (CLI) or PlatformIO IDE
# Install PlatformIO CLI
pip install platformio

# Or with pipx (recommended)
pipx install platformio

Building

There are multiple targets for flashing devices and compiling code in the root's cmake file, where you can read the command options you have, for each you need to run from the root directory:

mkdir build
cd build
cmake ..
make <command>
# eg commands: 
# firmware-esp32
# firmware-arduino
# firmware-all
# upload-ep32
# upload-arduino

Build Options (Host)

Sanitizers (development/debug only)

Sanitizers help detect bugs at runtime:

cd robrain/build

# AddressSanitizer (buffer overflow, use-after-free, memory leaks)
cmake -DENABLE_ASAN=ON ..
make

# UndefinedBehaviorSanitizer (integer overflow, null pointer, etc)
cmake -DENABLE_UBSAN=ON ..
make

# ThreadSanitizer (data races, deadlocks)
cmake -DENABLE_TSAN=ON ..
make

# Combine ASan + UBSan
cmake -DENABLE_ASAN=ON -DENABLE_UBSAN=ON ..
make

Developer Environment Setup

1. Install dependencies

# PlatformIO (for firmware builds)
pipx install platformio

# Host dependencies (macOS)
brew install cmake boost

# Host dependencies (Ubuntu/Debian)
sudo apt install cmake build-essential libboost-dev libbluetooth-dev

2. Build firmware once (installs PlatformIO toolchains)

cd firmware/arduino-emg && pio run

3. Editor setup

Neovim / Emacs (clangd)

These editors use clangd as LSP. Since clangd doesn't natively understand AVR, the project includes a script that generates everything needed for clangd:

./scripts/setup-clangd.sh
  1. Generates compile_commands.json for firmware (via pio run -t compiledb) and host (via cmake)
  2. Generates .clangd files for firmware/arduino-emg/ and host/ with the correct include paths, defines, and diagnostic suppressions

VSCode

Install these extensions:

  • PlatformIO IDE
  • CMake Tools
# Build host once to generate compile_commands.json
mkdir build && cd build && cmake ..

About

Brain Computer Interface system for robot control using EMG/EEG. Workflow: Electrodes -> Arduino -> Host -> ESP32 -> engine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •