HKIE BME Dual Grip Game - A kid-friendly game for controlling exoskeleton hand braces using EMG sensors
Project description
HKIE BME HOH Game
Cross-platform Python game for the HKIE BME booth. It uses two EMG channels (flexor/extensor) to control one exo hand over BLE and guides users through repeatable flexion/extension cycles to earn stars.
The app runs on macOS, Ubuntu, and Windows, defaults to full-screen, and supports simulation mode when hardware is not connected.
Highlights
- One-hand control loop using two EMG channels:
emg_flexorandemg_extensor - BLE device scan/bind flow for EMGS + exo-hand devices
- Real-time EMG bars, raw EMG charts, circular hand-position gauge, and star progress
- Start/Stop output safety control and quick Reset
- Optional mirrored layout for left/right operator preference
- Simulation mode for testing without BLE hardware
Project Layout
app/__main__.py- app entrypoint and runtime wiringapp/game/scenes.py- gameplay + settings scenes and UI behaviorapp/ble/ble_manager.py- BLE orchestration and scanning/bindingapp/ble/emgs_client.py- EMGS UART command/notification helpersapp/ble/exo_client.py- exo-hand client command/feedback handlingapp/io/input_manager.py- EMG processing and normalizationapp/ui/widgets.py- reusable Pygame widgetsconfig/devices.sample.json- sample device/config template
EMG Porting Guide
For colleagues implementing the same control behavior in another language, see:
docs/emg_control_reference.md
It focuses on:
- channel-specific EMG callbacks (
_on_flexor_emg,_on_extensor_emg) - signal processing (
EMGProcessor.update_batch, dynamic MVC update) - game control mapping (
_choose_active_muscle,GameScene.update)
Install
Option 1 (from Git)
pip install git+https://github.com/o0fung/hkie_bme_hoh.git
Run:
run_hoh_game
Option 2 (local source)
git clone https://github.com/o0fung/hkie_bme_hoh.git
cd hkie_bme_hoh
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -e .
Run:
run_hoh_game
Run Modes
Full-screen (default):
python -m app
Windowed:
GAME_FULLSCREEN=0 python -m app
# Windows PowerShell:
# $env:GAME_FULLSCREEN=0; python -m app
Configuration
At startup, the app expects config/devices.json in the current working directory. If it does not exist, it attempts to create it from config/devices.sample.json (or built-in defaults as fallback).
Config schema (from config/devices.json)
{
"simulation": false,
"settings": {
"emg_max_range_flexor": 100,
"emg_max_range_extensor": 100,
"hand_start_percent": 70,
"threshold_percent": 20,
"countdown_seconds": 3,
"target_flexion_percent": 90,
"target_extension_percent": 30,
"grip_step_percent": 1,
"command_rate_hz": 10,
"activation_hysteresis_percent": 2,
"deactivation_hysteresis_percent": 5,
"dynamic_mvc_alpha_up": 0.2,
"dynamic_mvc_alpha_down": 0.01,
"dynamic_mvc_up_margin_ratio": 0.03,
"dynamic_mvc_hold_activity_ratio": 0.85,
"dynamic_mvc_decay_trigger_ratio": 0.6,
"dynamic_mvc_decay_grace_seconds": 2.0
},
"emg_flexor": {
"name": "EMGS",
"mac_address": "E2:15:14:6B:66:E9",
"service_uuid": "",
"write_characteristic_uuid": "6e400002-b5a3-f393-e0a9-e50e24dcca9e",
"notify_characteristic_uuid": "6e400003-b5a3-f393-e0a9-e50e24dcca9e"
},
"emg_extensor": {
"name": "EMGS",
"mac_address": "EA:5E:82:04:33:79",
"service_uuid": "",
"write_characteristic_uuid": "6e400002-b5a3-f393-e0a9-e50e24dcca9e",
"notify_characteristic_uuid": "6e400003-b5a3-f393-e0a9-e50e24dcca9e"
},
"exo_hand": {
"name": "Exo-Hand",
"mac_address": "08:F9:E0:EC:41:3A",
"service_uuid": "",
"write_characteristic_uuid": "484f4802-4200-4c00-4500-000032303233",
"feedback_characteristic_uuid": "484f4803-4200-4c00-4500-000032303233"
}
}
Notes:
- Backward compatibility exists for legacy
settings.target_close_percent. simulationaccepts boolean or string values like"true"/"false".
Controls
ESC- quitF11- toggle full-screen- On-screen buttons -
Settings,Reset,Start/Stop,Mirror,Exit - Simulation keyboard input:
- Hold
Ffor flexor activation - Hold
Efor extensor activation
- Hold
Gameplay Cycle
Each star requires a two-phase cycle on one exo hand:
- Flexion phase: reach and hold at/above
target_flexion_percent. - Extension phase: reach and hold at/below
target_extension_percent. - Complete both phases to earn one star.
- Earn 3 stars to complete the session.
BLE Tips
- macOS: allow Bluetooth access for Terminal/app in Privacy settings.
- Ubuntu: ensure BlueZ is installed and adapter is enabled.
- Windows: ensure Bluetooth is enabled and adapter drivers are working.
- If scan results are empty, move closer, power-cycle devices, and scan again.
Troubleshooting
- No window or blank display: try windowed mode (
GAME_FULLSCREEN=0). - Import/runtime errors: verify active venv and reinstall (
pip install -e .). - No simulation response: click the game window to focus, then use
F/E. - No BLE data: verify MAC/UUID config and system Bluetooth permissions.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hoh_game-1.4.4.tar.gz.
File metadata
- Download URL: hoh_game-1.4.4.tar.gz
- Upload date:
- Size: 630.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7031d02f497064cfe62f68f4bc5fd1313af76193f4a380fe62d30ca34035534c
|
|
| MD5 |
280d038333e545f870989c0940438893
|
|
| BLAKE2b-256 |
393d27edf2ed257a17d4e716495237b178816739bc510d7af7053d052cb22369
|
Provenance
The following attestation bundles were made for hoh_game-1.4.4.tar.gz:
Publisher:
publish.yml on o0fung/hkie_bme_hoh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hoh_game-1.4.4.tar.gz -
Subject digest:
7031d02f497064cfe62f68f4bc5fd1313af76193f4a380fe62d30ca34035534c - Sigstore transparency entry: 1328137492
- Sigstore integration time:
-
Permalink:
o0fung/hkie_bme_hoh@9ca3b4d48645a272f505c6624804452bcae0edbb -
Branch / Tag:
refs/tags/v1.4.4 - Owner: https://github.com/o0fung
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9ca3b4d48645a272f505c6624804452bcae0edbb -
Trigger Event:
release
-
Statement type:
File details
Details for the file hoh_game-1.4.4-py3-none-any.whl.
File metadata
- Download URL: hoh_game-1.4.4-py3-none-any.whl
- Upload date:
- Size: 638.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
152e47aa237e4a72995b335b01041fe698b54376da14c4655cf83ff8be123de2
|
|
| MD5 |
8af66ae0646bc25e3529715f309ea04f
|
|
| BLAKE2b-256 |
6b3dafe4c88eb1e5c0d987860df83938bedcb707bb2bce99dc991a39647ac7fe
|
Provenance
The following attestation bundles were made for hoh_game-1.4.4-py3-none-any.whl:
Publisher:
publish.yml on o0fung/hkie_bme_hoh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hoh_game-1.4.4-py3-none-any.whl -
Subject digest:
152e47aa237e4a72995b335b01041fe698b54376da14c4655cf83ff8be123de2 - Sigstore transparency entry: 1328137494
- Sigstore integration time:
-
Permalink:
o0fung/hkie_bme_hoh@9ca3b4d48645a272f505c6624804452bcae0edbb -
Branch / Tag:
refs/tags/v1.4.4 - Owner: https://github.com/o0fung
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9ca3b4d48645a272f505c6624804452bcae0edbb -
Trigger Event:
release
-
Statement type: