Skip to content

Feature/ganglion emg mechdog - #6

Merged
VinceIngram07 merged 48 commits into
htil:copyfrom
VinceIngram07:feature/ganglion-emg-mechdog
May 27, 2026
Merged

VinceIngram07 merged 48 commits into
htil:copyfrom
VinceIngram07:feature/ganglion-emg-mechdog

Conversation

@VinceIngram07

Copy link
Copy Markdown
Member

No description provided.

VinceIngram07 and others added 30 commits January 28, 2025 13:01
forward = Right
down = Left
Added new blocks (Move and Color)
Only Forward command is working with vex
WORK IN PROGRESS
Previous block functionality
still working on new block functions
Found problem: the number for the muscle energy window and the raw data doesn't match up
- need to connect the vex through AP before starting the application
- fixed colors
- no longer degrees for turn block (for kids)
- Shortcut is ready to be used (Neuroscope-EMG)
-Updated gitignore (pycache)
* src/main/index.js:
  - Fixed production build path from loadURL to loadFile with correct relative path
  - Added Python process spawning with virtual environment detection
  - Implemented WebSocket connection validation with 10s timeout
  - Added proper process cleanup on app quit and window close
  - Updated hardcoded references from Muse to Ganglion devices
  - Fixed port configuration from 3000 to 3002

* src/renderer/js/muse-client.js:
  - Fixed duplicate filters property that was overriding device name filters
  - Added Ganglion service (0xfe84) to optionalServices for proper discovery

* package.json:
  - Updated electron-builder config to include build/renderer directory
  - Added extraResources for Python executable bundling
  - Enhanced build scripts with python:build for PyInstaller integration
  - Updated serve script to use port 3002
  - Added build:local script for complete build process

* VEXServer.spec (new):
  - PyInstaller specification for Python server executable
  - Proper dependency handling for websockets and asyncio
  - Console executable configuration for debugging

* resources/python/VEXServer_dev.py (new):
  - Created simulation mode WebSocket server for development
  - Mock VEX robot with full command protocol (led_on, move, turn_left, turn_right)
  - Enables testing without physical VEX robot hardware
  - Runs on ws://127.0.0.1:8777 with JSON command interface

* requirements.txt:
  - Added PyInstaller>=5.0 for standalone executable creation

**Key Improvements:**
- Enables successful Windows executable creation with integrated Python server
- Two-process architecture provides reliable communication in both dev and production
- Fixed Bluetooth device scanning to properly detect Ganglion devices instead of Muse
- Automatic virtual environment detection in development mode
- Production builds now bundle Python server as standalone executable
- Enhanced development workflow with simulation server for hardware-free testing
…rking WebSocket management

**New Features:**
* Console UI: Replace frequency bands display with clean console output
* VEX Reconnect: Add functional reconnect button to restart VEX connection without app restart
* Enhanced Testing: Complete VEX simulation server with comprehensive test suite
* Robust WebSocket Management: Proper connection handling with reconnection support

**Console System (NEW):**
* src/renderer/js/console.js: Clean terminal-like console without timestamps/emojis
* src/renderer/index.html: Replace bands display with console container
* src/renderer/js/main.js: Integrate Console class replacing BandPowerVis
* src/renderer/js/wrapper-functions.js: Connect blockly_print to console output

**VEX Reconnect System (FULLY FUNCTIONAL):**
* src/main/index.js: Complete WebSocket connection management with proper scoping
  - Added stopPythonServer() and reconnectVEX() process management
  - Moved WebSocket variables and functions to global scope for proper access
  - Implemented createWebSocketConnection() with timeout and error handling
  - Fixed function scoping issues that prevented reconnection
* src/main/preload.js: Expose vexReconnect IPC method to renderer
* src/renderer/index.html: Add VEX reconnect button in sidebar (orange refresh icon)
* src/renderer/js/events.js: Implement reconnect button handler with visual feedback

**Enhanced VEX Testing:**
* resources/python/VEXServer_dev.py: Complete simulation server with full command support
* test_vex_server.py: Comprehensive WebSocket test suite for validation

**Key Technical Improvements:**
- Fixed variable scoping: ws and createWebSocketConnection now accessible globally
- Proper WebSocket lifecycle management: Close old connections before creating new ones
- Enhanced error handling with timeout protection and graceful fallbacks
- Clean console replaces cluttered frequency bands display
- Robust reconnection process with proper server restart sequence
- Enhanced print blocks accept any data type and output to console

**WebSocket Reconnection Flow:**
1.  Close existing WebSocket connection
2.  Stop Python VEX server gracefully (SIGTERM with SIGKILL fallback)
3.  Wait 2 seconds for cleanup
4.  Restart Python VEX server
5.  Wait 3 seconds for server initialization
6.  Re-establish WebSocket connection with timeout protection
7.  Resume VEX command functionality
**Block-to-Text Converter:**
* src/renderer/js/simple-text-view.js: Text coding environment using Blockly's built-in code generation
* src/renderer/index.html: Add toggle buttons for block/text modes and export functionality
* src/renderer/js/main.js: Integrate text view with existing Blockly system
… app rename

Python (resources/python):

Add resilient AIM connection loop; server stays alive and retries when robot is offline

Add reconnect_robot action to reset robot connection without restarting server

Add disconnect_robot cleanup to close websocket threads and sockets before re-init

Add status action reporting robot_connected for UI

Improve connection logs (attempting / connected / retry)

Electron main (src/main):

Detect and spawn bundled VEXServer.exe in production

Replace waitOn websocket probe with lightweight TCP port polling

Guard reconnectVEX against overlap and clear force-kill timer to avoid killing new process

Periodically poll server status and relay to renderer via vex-status

Fix false-positive connected state by distinguishing wsConnected vs robotConnected

Add lazy-init UDP sockets for Tello (no bind to 9000/8890 until needed)

Renderer:

Add connectivity status dot showing wsConnected (grey/yellow) and robotConnected (green)

Add onVexStatus and requestVexStatus to preload for UI updates

Packaging/build:

Ensure PyInstaller bundle includes vex module/resources and fix spec path resolution

Use process.resourcesPath/python/VEXServer.exe in production and improve spawn/path logging

Naming/branding:

Rename app to "NeuroBlock EMG for VEX" (productName/appId, window title, HTML title)

Docs:

Update README with "Adding a New Blockly Block (Example: VEX Kicker)" section and build notes

Notes:

Reconnect button sends reconnect_robot when local websocket is up; only restarts Python process if websocket is down

Status dot: grey = websocket down, yellow = websocket up/robot down, green = robot connected

Avoid binding to port 9000 unless Tello is actively used
…X integration

### Application Branding & Identity
- Rename app from 'NeuroBlock EMG for VEX' → 'NeuroBlock EEG for VEX'
- Update package.json productName, window title, and HTML title
- Update appId to reflect EEG focus: com.htil.neuroblock-emg-vex

### EEG Signal Processing (Muse Headset)
- Restore Signal class for real-time EEG data buffering (512-sample buffer)
- Restore BandPowerVis for frequency band visualization (delta, theta, alpha, beta, gamma)
- Restore FeatureExtractor for band power computation from raw EEG samples
- Restore BLE (Bluetooth Low Energy) integration for Muse headset connection
- Wire Muse eegReadings callback → Signal.add_data() for live data streaming

### UI Layout - Two-Panel Design
- Left panel (45% width):
  * Top card (40vh): 4 EEG channel graphs (channels 0-3 from Muse)
  * Bottom card (40vh): Band power frequency spectrum visualization
- Right panel (55% width):
  * Blockly visual programming editor for robot control
  * VEX AIM robot command center and status display
  * Console output and device connection status
…band power metrics and fixing controls_if handler
Copilot AI review requested due to automatic review settings May 27, 2026 17:09
@VinceIngram07
VinceIngram07 merged commit a74efa0 into htil:copy May 27, 2026
1 check failed
@VinceIngram07
VinceIngram07 removed the request for review from Copilot May 27, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants