Skip to main content

A GRU model that improves the performance of adaptive oscillators in stop-go and go-stop situations.

Project description

ao_compensation_model

CI PyPI Docker

A GRU-based compensation model that improves the performance of adaptive oscillators (AOs) during stop-go and go-stop gait transitions. The model learns the phase error between the AO output and the ground-truth gait phase, and applies a real-time correction on edge devices via TFLite.

Pipeline

Step Command Description
1 prep Bandpass-filters raw IMU hip angles, aligns AO phase, and computes target_cos and target_sin training targets.
2 train Trains a GRU network on sliding windows of AO features and exports an optimized TFLite model.
3 validate Runs frame-by-frame TFLite inference on test data and visualises predicted phase and its sin/cos outputs alongside raw kinematics.
4 txt2csv Converts raw sensor text files (tab / comma / semicolon delimited) in a folder to semicolon-delimited CSVs.

Install

From PyPI:

pip install ao-compensation-model

From source:

git clone https://github.com/lhharry/ao_compensation_model.git
cd ao_compensation_model
uv sync

Usage

CLI

All commands follow the pattern:

uv run python -m ao_compensation_model <command> [options]

Data Preparation

# Prepare ground-truth targets from all raw CSVs
uv run python -m ao_compensation_model prep

# Prepare a single file
uv run python -m ao_compensation_model prep --file 20260304_17_13_22_stopgo.csv

# Prepare with a manual stationary threshold (default: auto)
uv run python -m ao_compensation_model prep --file recording.csv --threshold 0.1

Training

uv run python -m ao_compensation_model train

Validation

# Validate all test files
uv run python -m ao_compensation_model validate

# Validate a specific test file
uv run python -m ao_compensation_model validate --file 20260304_14_26_34_4km_stopgo.csv

File Conversion

# Opens a folder picker GUI
uv run python -m ao_compensation_model txt2csv

# Convert a specific folder
uv run python -m ao_compensation_model txt2csv --file /path/to/folder

CLI Flags

Flag Applies to Description
--file prep, validate, txt2csv prep: single CSV to process. validate: single test CSV. txt2csv: folder path.
--threshold prep Amplitude threshold for stationary detection. Omit or pass auto for automatic (default: auto).
--log-level all Log level (TRACE, DEBUG, INFO, SUCCESS, WARNING, ERROR, CRITICAL).
--stderr-level all Stderr log level.

As a Library

from ao_compensation_model.training import build_gru_model
from ao_compensation_model.utils import bandpass_filter, align_ao_phase
from ao_compensation_model.validation import validate_prediction

Development

  1. Install uv from Astral.
  2. git clone git@github.com:lhharry/ao_compensation_model.git
  3. make init — create virtual environment and install dependencies
  4. make format — format code and run type checks
  5. make test — run the test suite with coverage
  6. make clean — delete temporary files and directories

Publishing

Pushing a version tag triggers automatic publishing to PyPI via GitHub Actions (Trusted Publishing):

# Update version in pyproject.toml, then:
git tag v0.1.1
git push origin --tags

Structure

├── src
│   └── ao_compensation_model
│       ├── __init__.py
│       ├── __main__.py
│       ├── app.py
│       ├── definitions.py
│       ├── gt_dataprep.py
│       ├── training.py
│       ├── txt2csv.py
│       ├── utils.py
│       ├── validation.py
│       ├── dataset/
│       └── model/
├── tests
│   ├── __init__.py
│   ├── conftest.py
│   ├── app_test.py
│   ├── gt_dataprep_test.py
│   ├── training_test.py
│   └── utils_test.py
├── .github/workflows/
├── CONTRIBUTING.md
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
└── pyproject.toml

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ao_compensation_model-0.1.6.tar.gz (7.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ao_compensation_model-0.1.6-py3-none-any.whl (7.5 MB view details)

Uploaded Python 3

File details

Details for the file ao_compensation_model-0.1.6.tar.gz.

File metadata

  • Download URL: ao_compensation_model-0.1.6.tar.gz
  • Upload date:
  • Size: 7.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ao_compensation_model-0.1.6.tar.gz
Algorithm Hash digest
SHA256 21c72393c4b736f0b46f49ce72ff06909f68e2d58221c43565a376fae23504de
MD5 8f933a62db2acbd18c314dd419ecf7b2
BLAKE2b-256 271773d6c0aa6b5782c56a36b24c9d0fabd27e69d0d0eb0042f4765665d3a83f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ao_compensation_model-0.1.6.tar.gz:

Publisher: pypi-publish.yml on lhharry/ao_compensation_model

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ao_compensation_model-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for ao_compensation_model-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 48366bda0922a066519b8f41ed41109a66b0bb510fbe0632d1d3614f49437aa6
MD5 71883bfec1643ea363ee53a48cf45d0f
BLAKE2b-256 7be2e083cb5ede7ef2f627f649b556f313c9b0f3af7a1dc98e899a1a62125202

See more details on using hashes here.

Provenance

The following attestation bundles were made for ao_compensation_model-0.1.6-py3-none-any.whl:

Publisher: pypi-publish.yml on lhharry/ao_compensation_model

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page