Skip to content

SolanumLycopersicumX/3YP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BCI-based Robotic Arm Control System

Final Year Project (3YP) - 徐正 (Zheng XU)

本文件夹包含我在毕业设计中自己完成的所有工作,与原始CTNet GitHub项目区分开来。

中文版概览

该仓库整理了我在曼彻斯特大学毕业设计期间独立完成的主要工作,主题是基于脑机接口(BCI)的机械臂控制系统。系统将基于 CTNet 的运动想象 EEG 分类、面向目标到达任务的强化学习控制,以及 SO-101 机械臂的仿真到实物部署流程整合在一起。

仓库内容聚焦于我自己的代码、实验结果、训练模型和项目文档,并与原始 CTNet GitHub 项目分开维护。目前结果包括 PhysioNet 运动想象数据集上的 88.78% pooled accuracy、通道缩减与滤波消融实验,以及离线或仿真条件下的端到端评估。由于 NHS 伦理审批限制,真人被试硬件验证尚未完成。

中文快速链接:

English Overview

This repository contains the work I completed for my final-year project at The University of Manchester. The project develops a brain-computer interface (BCI) pipeline for robotic arm control by combining CTNet-based motor imagery EEG classification, reinforcement learning for target-reaching control, and simulation-to-real deployment on an SO-101 robotic arm.

This repository is kept separate from the original CTNet GitHub project and focuses on my own code, experiments, trained models, and documentation. Current results include 88.78% pooled accuracy on the PhysioNet motor imagery dataset, channel-reduction and filtering ablation studies, and offline or simulation-based end-to-end evaluation. Due to NHS ethics approval constraints, hardware validation with human subjects has not yet been completed.

Quick links:


📁 文件夹结构

English note: the repository tree below is kept in its original Chinese-labeled form for my own project workflow, but the surrounding sections now include English explanations so external readers can still understand the purpose of each directory.

3YP/
├── 01_Reports/                    # 报告与文档
│   ├── final_report_draft_v13.*   # 最终报告 (最新版)
│   ├── week_2026_03_24.*          # 周报
│   ├── ZhengXu_CV_v5.*            # 简历 (英文/中文)
│   ├── architecture_diagram.*     # 系统架构图
│   └── Risk assessment form-*.docx
│
├── 02_Code/                       # 代码
│   ├── EEG_Classification/        # EEG分类相关
│   │   ├── CTNet_model.py         # EEGTransformer模型 (基于原CTNet修改)
│   │   ├── physionet_loader.py    # PhysioNet数据加载器
│   │   ├── train_physionet_ctnet.py
│   │   ├── finetune_physionet_ctnet.py  # 微调脚本
│   │   ├── channel_reduction_study.py   # 通道消融实验
│   │   └── finetune_filter_comparison.py # 滤波消融实验
│   │
│   ├── Reinforcement_Learning/    # 强化学习
│   │   ├── dqn_model.py           # DQN模型
│   │   ├── dqn_transformer.py     # Transformer-based DQN
│   │   ├── train_dqn_rl.py        # DQN训练脚本
│   │   ├── ctnet_dqn_e2e_eval.py  # 端到端评估
│   │   └── rl_control_test.py     # RL控制测试
│   │
│   ├── Physical_Control/          # 物理机械臂控制
│   │   ├── serial_arm_env*.py     # SO-101串口控制
│   │   ├── phy_control.py         # 物理控制主程序
│   │   ├── brainflow_physical_control.py  # BrainFlow+物理臂
│   │   ├── openbci_stream.py      # OpenBCI数据流
│   │   └── serial_*.json          # 机械臂位置配置
│   │
│   ├── Simulation/                # PyBullet仿真
│   │   ├── pybullet_arm_env.py    # PyBullet环境
│   │   ├── arm_gym_env.py         # Gymnasium包装
│   │   └── gym_control.py         # 仿真控制
│   │
│   ├── Utils/                     # 工具脚本
│   │   ├── requirements.txt
│   │   └── plot_*.py
│   │
│   └── lerobot/                   # LeRobot框架 (HuggingFace, 备用)
│
├── 03_Experiments/                # 实验结果
│   ├── Channel_Reduction/         # 64→8通道消融
│   ├── Filter_Ablation/           # 8-30Hz滤波消融 (+18.44%)
│   ├── DQN_Training/              # DQN训练曲线
│   └── E2E_Evaluation/            # CTNet+DQN端到端评估
│
├── 04_Trained_Models/             # 训练好的模型
│   ├── physionet_ctnet*/          # PhysioNet预训练CTNet
│   └── dqn_*.pth                  # DQN策略网络
│
├── 05_Documentation/              # 文档与演示
│   ├── phy_control_arm.mp4        # 物理机械臂演示视频
│   └── gym_arm.gif                # 仿真演示
│
└── 06_Data/                       # 数据集
    ├── BCICIV_2a_gdf/             # BCI Competition IV-2a (575MB)
    ├── BCICIV_2b_gdf/             # BCI Competition IV-2b (272MB)
    ├── physionet_raw/             # PhysioNet EEG (1.8GB)
    └── true_labels/               # 标签文件

English summary of key folders:

  • 01_Reports/: report drafts, weekly reports, and formal submission materials.
  • 02_Code/: the main authored source code for EEG classification, RL, simulation, and hardware control.
  • 03_Experiments/: saved outputs from channel reduction, filtering ablations, DQN training, and end-to-end evaluation.
  • 04_Trained_Models/: trained checkpoints used by the experiments.
  • 05_Documentation/: supporting documents, demos, and media.
  • 06_Data/: locally stored benchmark datasets used during the project.

🔬 主要贡献 (我自己的工作)

English note: the following items summarise the parts of the project that I personally implemented, evaluated, or integrated, rather than the third-party reference material preserved elsewhere in the repository.

1. EEG分类 (基于原CTNet改进)

  • PhysioNet数据集适配: 109人跨被试预训练,达到88.78%准确率 English: I adapted the CTNet-style classifier to the 109-subject PhysioNet motor imagery dataset and used it for large-scale cross-subject and fine-tuning experiments.
  • 两阶��迁移学习: 预训练+微调,提升32个百分点 English: The workflow first pretrains on pooled data and then fine-tunes on individual subjects, recovering a large amount of subject-specific performance.
  • 通道消融研究: 64→8通道,保持72.54%准确率,识别C3为关键通道 English: This study identifies which electrodes remain most useful when moving toward an OpenBCI-compatible low-channel setup.
  • 滤波消融实验: 证明8-30Hz带通滤波提升+18.44%准确率 English: The default preprocessing choice is supported by an explicit ablation rather than by assumption.

2. 强化学习控制

  • Transformer-based DQN: 设计用于序列决策的DQN架构 English: I implemented and compared a Transformer-based Q-network for sequential control.
  • EEG-aware RL: 将EEG分类结果作为状态输入 English: The RL controller can consume predicted class and confidence from the EEG classifier.
  • 闭环误差补偿: 82%分类准确率下达到99%目标到达率 English: This shows that closed-loop control can still succeed even when neural decoding is imperfect.

3. 物理机械臂集成

  • SO-101串口控制: 实现多关节同步运动、速度规划 English: Serial communication and motion control were implemented for the physical robotic arm.
  • Sim2Real管线: PyBullet仿真→物理臂零样本迁移 English: Simulation was used as the main safe development path before hardware deployment.
  • OpenBCI集成: BrainFlow API实时脑电采集 English: BrainFlow is used as the intended real-time EEG acquisition interface.

4. 实验与评估

  • 系统的消融实验设计
  • 完整的端到端离线评估管线
  • 详细的实验报告和可视化 English: The repository includes ablation studies, end-to-end offline evaluation, and preserved visualisations so the software contribution can be inspected rather than only described.

⚠️ 注意事项

English note: the points below clarify repository boundaries, included datasets, and the current validation status of the hardware side of the project.

  1. 原始CTNet项目文件保留在 CTNet/ 文件夹中,包括: English: the original CTNet material is kept separately for reference and comparison.

    • 原始Jupyter notebooks
    • BCI IV-2a/2b数据集和标签
    • 原始README和LICENSE
  2. 数据集已包含在 06_Data/ 文件夹中: English: the main public datasets used in this project are already stored locally in the repository workspace.

    • PhysioNet: 06_Data/physionet_raw/ (1.8GB, 109人)
    • BCI IV-2a: 06_Data/BCICIV_2a_gdf/ (575MB, 9人, 4分类)
    • BCI IV-2b: 06_Data/BCICIV_2b_gdf/ (272MB, 9人, 2分类)
  3. 硬件验证状态:由于NHS伦理审批限制,所有评估均为仿真/离线,真人被试测试待完成。 English: live-subject hardware validation has not yet been completed, so the current evidence is limited to offline data and simulation.


🚀 快速开始

English note: these commands cover the main software path for reproducing the project workflow at a high level.

# Install dependencies
pip install -r 02_Code/Utils/requirements.txt

# Train the PhysioNet EEG classifier
python 02_Code/EEG_Classification/train_physionet_ctnet.py

# Run the channel reduction study
python 02_Code/EEG_Classification/channel_reduction_study.py

# Run the simulation controller
python 02_Code/Simulation/gym_control.py

作者 / Author: 徐正 (Zheng XU)
项目 / Project: 曼彻斯特大学 Final Year Project
日期 / Date: 2025-2026学年

About

3YP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors