Skip to content

Compose emgpredictor#142

Open
ECEEvanCampbell wants to merge 279 commits into
latestfrom
compose_emgpredictor
Open

Compose emgpredictor#142
ECEEvanCampbell wants to merge 279 commits into
latestfrom
compose_emgpredictor

Conversation

@ECEEvanCampbell

Copy link
Copy Markdown
Collaborator

This branch composes the online EMGPredictor/adaptation workflow. The most recent work on it (this session) adds three things:

  1. Atomic shared-memory reads ( + _count share a lock)
    The streamer writes each modality buffer and its sample counter under separate locks, and readers copied them in two separate critical sections. A batch landing between the two reads made the counter run ahead of the copied buffer, so log_to_file spliced dropped/duplicated samples into the saved signal (visible as "noise" that visualize never showed, because it is stateless per frame).

SharedMemoryManager.get_variables([...]) — copies several variables under a single held lock (one acquire when they share a lock; deadlock-safe id-ordered acquisition otherwise).
assign_shared_memory_locks(...) — gives and _count the same lock; used by all streamer factories in streamers.py.
OnlineDataHandler.get_data and MemoryManager.process_data now take an atomic (data, count) snapshot. SharedMemoryOutputWriter shares the buffer's lock with its _count.
Because every writer updates data before count, an atomic read can only ever see the count lagging the data (self-correcting) — never leading it, which is the failure mode.

  1. Online Adaptation tutorial
    New Sphinx page (docs/source/documentation/adaptation/) documenting the adaptation suite: a within-subject SGT initialization followed by an online environment that adapts the model in the loop. Grounded in the CoAdaptUnderCurriculum reference workflow and trimmed to the minimal wiring (the four cooperating processes, get_edil_adaptation_objects, the model/memory/feedback interfaces the user supplies, and the save_dir/file_path/load_dir linkages). Wired into the Modules toctree and the API reference (emg_toolbox.rst).

  2. Doc toolchain bump
    requirements.txt # For Docs pins bumped to Sphinx>=8.1.3, myst-parser>=4.0.0, sphinx-rtd-theme>=3.0.2. Sphinx 5.0.0 fails to import on Python 3.13 (removed stdlib imghdr) and the old myst/rtd-theme pins are incompatible with modern Sphinx. The full docs (including the new tutorial) now build cleanly.

Reviewer notes
The docs build was verified locally end-to-end (sphinx-build docs/source) — build succeeds; remaining warnings are all pre-existing in other pages.
The lock/snapshot change touches the shared-memory contract used by every streamer; the shared-lock convention is applied uniformly so existing streamers keep working.
This branch also carries the earlier compose_emgpredictor commits (incremental-learning updates, SiFi streamer, numpy>2.0).

cbmorrell and others added 30 commits August 23, 2024 16:12
An error was thrown if our method of calculating steady state frames failed (like in cases where there weren't any steady state frames).

Added a try catch to deal with this.
Added an animation tab to Modules and described some of the animations you can make.
Users could pass in function handles to change metadata operations, but there are some operations that are very common and require users to define function handles (like grabbing the last sample).

Added ability to pass in strings for some common operations.
Add string parameters for common metadata operations
Data could not be standardized online.

Added a method to install standardization to online models.
Some changes were not reverted properly, causing the FeatureExtractor in OnlineStreamer to use the old interface.

Updated to use the current interface (no breaking API).
Feature extraction in visualize_heatmap used old modified API for FeatureExtractor.

Reverted to expected version.
Online regressor method visualize() had lag when plotting.

Modified so it uses the matplotlib animation API instead.
Added skeleton for Controller class and potential ideas for implementation.
There was a check for when the queue reached the max length that would manually pop the oldest window.

This functionality is already built into deque by specifying the maxlen parameter, so replaced the check with maxlen.
Created base Controller class that all controllers (including keyboard) will inherit from. Also created a SocketController class that all controllers communicating over a port will inherit from.
Added another abstract parsing function because messages should also include a timestamp, so the user may want to parse those as well.
Implementation of a regressor controller. Hasn't been tested yet.
Check for Correct MacOS String in OyMotion Streamer
Online Model Feature Queue and Feature Standardization
Users may not have access to the model itself in a script, so passing in the model may not work.

Modified so users just pass in the IP and port.
Created concept for ClassifierController, but still hasn't been tested.
Online regressor method visualize() had lag when plotting.

Modified so it uses the matplotlib animation API instead.
Added ability to grab timestamp when calling get_data.
ECEEvanCampbell and others added 29 commits May 1, 2025 14:40
Sphinx 5.0.0 cannot be imported on Python 3.13 (it imports the stdlib
`imghdr` module removed in 3.13), and the pinned myst-parser 0.18.1 /
sphinx-rtd-theme 1.0.0 are incompatible with modern Sphinx. Bump the
`# For Docs` pins to Sphinx>=8.1.3, myst-parser>=4.0.0, and
sphinx-rtd-theme>=3.0.2 so `sphinx-build docs/source` succeeds, including
the new Online Adaptation tutorial.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ECEEvanCampbell ECEEvanCampbell requested a review from eeddy July 5, 2026 23:29
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.

6 participants