Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,28 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
cache: pip
- run: pip install -r requirements-dev.txt
- run: pip install -e ".[dev]"
- run: pytest -q

package:
# Build the distributions and prove that a core-only install (no pandas,
# scipy or matplotlib) can still run the flashing and logging commands.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install build
- run: python -m build
- name: Core-only install
run: |
python -m venv /tmp/core
/tmp/core/bin/pip install dist/*.whl
/tmp/core/bin/nav --version
/tmp/core/bin/nav --workspace /tmp/ws doctor
/tmp/core/bin/python -c "import sys, navkit.cli, navkit.flash, navkit.firmware, navkit.logger; assert not {'pandas','scipy','matplotlib'} & set(sys.modules)"
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
57 changes: 57 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Release

# Pushing a tag like v0.2.0 builds the package and publishes a GitHub Release
# with the wheel and sdist attached. The tag must match the version in
# src/navkit/__init__.py.
#
# PyPI: set the repository variable PYPI_PUBLISH=true after registering this
# workflow as a trusted publisher for the `navkit` project on pypi.org
# (Publishing → Add a new pending publisher: this repo, workflow release.yml,
# environment "pypi").

on:
push:
tags: ["v*"]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install build
- run: python -m build
- name: Check the tag matches the package version
run: |
version="$(ls dist/*.tar.gz | sed -E 's/.*navkit-(.*)\.tar\.gz/\1/')"
test "v${version}" = "${GITHUB_REF_NAME}" || {
echo "Tag ${GITHUB_REF_NAME} does not match package version ${version}"; exit 1; }
- run: sha256sum dist/* > dist/SHA256SUMS
- name: Publish GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "$GITHUB_REF_NAME" dist/* --title "navkit $GITHUB_REF_NAME" --generate-notes
- uses: actions/upload-artifact@v4
with:
name: dist
path: |
dist/*.whl
dist/*.tar.gz

pypi:
needs: build
if: vars.PYPI_PUBLISH == 'true'
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

### Added
- **`navkit` package and the `nav` command.** The pipeline is now an
installable Python package (`pip install navkit`, `navkit[pipeline]` for
the analysis stages) with subcommands: `flash`, `firmware`, `ports`,
`doctor`, `record`, `process`, `calibrate`, `sessions`, `log`, `wizard`,
`where`.
- `nav flash`: detects the chip, downloads the matching firmware release,
verifies its SHA-256 and flashes it with esptool. Images are cached.
- `nav doctor`: checks Python, serial access, drivers and the workspace.
- A workspace directory (`~/navkit`, `--workspace`, or `NAVKIT_HOME`) holds
sessions, outputs and calibration parameters, so the tool no longer has
to run from a source checkout.

### Fixed
- On Windows, writing the session summary failed because of the `μ` in it;
all files are now written as UTF-8.

### Changed
- Modules moved from `pipeline/` to `src/navkit/`; `session_trimmer.py` is
now `trimmer.py`.
- Flashing and logging no longer import pandas, scipy or matplotlib.
- Without a terminal attached, a missing calibration file aborts the run
(strict) instead of waiting for input.
- `run_pipeline.py` is a thin wrapper around the wizard and keeps using the
checkout as its workspace.

### Added
- `pipeline/wire.py`: decoder for the firmware's binary wire protocol v1
(COBS framing, CRC-16), tested against a golden stream produced by the
Expand Down
138 changes: 94 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The pipeline follows a deterministic multi-stage flow:
| Stage | Module | Responsibility | Output |
|---|---|---|---|
| **1. Log** | `logger.py` + `wire.py` | Binary frames (or CSV debug stream) → CSV | `raw/raw.csv`, `raw/firmware.json` |
| **2. Trim** | `session_trimmer.py` | Signal/Noise segmentation | `clean/signal_v1.csv` |
| **2. Trim** | `trimmer.py` | Signal/Noise segmentation | `clean/signal_v1.csv` |
| **3. Diagnose** | `diagnostics.py` | Timing, jitter & alignment | `diagnostics/timing_v1.json` |
| **4. Calibrate** | `calibrator.py` | Bias, scale & hard-iron | `calibrated/calibrated_v1.csv` |
| **5. Plot** | `plotter.py` | Visual validation | `outputs/plots/*.png` |
Expand All @@ -40,7 +40,7 @@ graph LR

subgraph Pipeline["<b>Repo 2: Data Pipeline</b>"]
LOG["logger.py<br/>Serial Listener"] --> RAW[/"raw.csv"/]
RAW --> TRIM["session_trimmer.py<br/>Signal Trimmer"]
RAW --> TRIM["trimmer.py<br/>Signal Trimmer"]

TRIM --> CLN[/"signal_v1.csv"/]

Expand Down Expand Up @@ -184,62 +184,112 @@ Each session is categorized as:

---

## Repo-02 Structure
## Install

`navkit` is the Python package in this repo; it installs the `nav` command.

```bash
# Flash and log only (small: pyserial + esptool)
pip install "navkit @ git+https://github.com/multi-sensor-navigation-system/data-pipeline"

# Everything, including trim / diagnose / calibrate / plot
pip install "navkit[pipeline] @ git+https://github.com/multi-sensor-navigation-system/data-pipeline"
```
data-pipeline/
├── data/ # Raw and processed session data
├── outputs/
│ ├── plots/ # Visual validation plots
│ └── reports/ # Markdown session summaries
├── pipeline/
│ ├── logger.py # High-speed UART listener
│ ├── wire.py # Wire protocol v1 decoder (binary + CSV detection)
│ ├── session_trimmer.py # Signal/Noise segmenter
│ ├── diagnostics.py # Timing & jitter analysis
│ ├── calibrator.py # Bias, scale & hard-iron calibration
│ └── plotter.py # Multi-stage signal visualisation
├── run_pipeline.py # Unified CLI entry point
└── README.md # Technical documentation

From a checkout, for development:

```bash
python -m venv .nav && source .nav/bin/activate
pip install -e ".[dev]"
pytest
```

Requires Python 3.10+.

---

## Setup
## Quick start

1. **Environment:** Create a virtualenv and install dependencies:
```bash
python -m venv .nav
source .nav/bin/activate
pip install -r requirements.txt
```
2. **Hardware:** Connect the ESP32 via USB and identify the port (e.g., `/dev/cu.usbserial-0001`).
3. **Run:** Execute the pipeline and follow the prompts.
```bash
nav doctor # is this machine ready? is a board connected?
nav flash # detect the board, download the latest firmware, verify, flash
nav record --type static_calib --note "flat on desk" # log (Ctrl-C to stop), then process
nav record --type free_label --note "bike ride"
nav sessions
```

`nav wizard` walks through the same steps as an interactive menu.

---

## Automation & CLI
## Commands

The pipeline can be run interactively or fully automated via command-line arguments.
| Command | What it does |
|---|---|
| `nav doctor [--online]` | Checks Python, serial access, drivers, the workspace and (with `--online`) firmware releases |
| `nav ports` | Lists serial ports that look like a board |
| `nav flash [--board ID] [--version TAG] [--port P]` | Downloads a firmware release, verifies its SHA-256 and flashes it. `--board auto` (default) detects the chip. `--file image.bin` flashes a local build |
| `nav firmware list` / `nav firmware fetch` | Lists releases and their boards / downloads an image without flashing |
| `nav record --type T [--note N]` | Logs a new session from the board, then runs the whole pipeline on it |
| `nav process SESSION [--from STEP]` | Runs the pipeline on an existing session, from `trim`, `diagnose`, `calibrate` or `plot` |
| `nav calibrate SESSION` | Computes calibration parameters from a static session |
| `nav sessions` | Lists sessions with type, duration and validity |
| `nav log [-o FILE]` | Logs the serial stream to one CSV file and does nothing else |
| `nav wizard` | Interactive menu |
| `nav where` | Shows where sessions, outputs and cached firmware live |

```bash
# Interactive mode (default)
python run_pipeline.py
Session types: `static_calib`, `accel_6pos`, `mag_rotation`, `free_label`.

When a dynamic session has no calibration parameters, `record` and `process` ask what to do. Decide up front with `--strict` (abort), `--allow-uncalibrated` (continue; the session is flagged `valid_for_analysis: false`) or `--calib-path FILE`. A custom path wins over the other two. Without a terminal attached the default is strict.

`python run_pipeline.py` still works from a checkout and uses the checkout itself as the workspace.

---

## Workspace

Sessions, plots and calibration parameters live in one directory, the workspace:

# Automated mode (Action 2 = Run on existing, Action 3 = Re-run from step)
python run_pipeline.py --action 2 --session-dir data/session_XYZ --calib-mode 0
```
### Key CLI Arguments
| Argument | Options | Description |
|---|---|---|
| `--action` | `1-5` | Choose log, process, re-run, calibrate or list |
| `--session-type` | `static_calib`, `free_label`, etc | Set the session intent |
| `--session-dir` | session_id | Target session for processing |
| `--start-from` | `trim`, `diagnose`, `calibrate`, etc | Entry point for re-runs |
| `--calib-mode` | `0` (Strict), `1` (Permissive) | Handling of missing params |
| `--calib-path` | path/to/params.json | Custom path for calibration params |
~/navkit/
├── data/<session>/
│ ├── raw/ raw.csv, firmware.json
│ ├── clean/ signal_v*.csv, noise_v*.csv, cleaning_v*.json
│ ├── diagnostics/ timing_v*.json, jitter_v*.png, alignment_v*.png
│ ├── calibrated/ calibrated_v*.csv, calibration_v*.json
│ └── metadata.json
├── outputs/
│ ├── plots/<session>/
│ └── reports/
└── calibration_params.json
```

*If --calib-path is provided, it overrides --calib-mode.*
It defaults to `~/navkit`. Change it with `nav --workspace DIR …` or the `NAVKIT_HOME` environment variable. Downloaded firmware is cached separately in the per-user cache directory (`nav where` prints both).

For complete list, use `python run_pipeline.py --help`
---

## Repo-02 Structure
```
data-pipeline/
├── src/navkit/
│ ├── cli.py # The `nav` command
│ ├── pipeline.py # Orchestration, calibration gate, metadata, wizard
│ ├── logger.py # High-speed UART listener
│ ├── wire.py # Wire protocol v1 decoder (binary + CSV detection)
│ ├── trimmer.py # Signal/Noise segmenter
│ ├── diagnostics.py # Timing & jitter analysis
│ ├── calibrator.py # Bias, scale & hard-iron calibration
│ ├── plotter.py # Multi-stage signal visualisation
│ ├── firmware.py # Firmware releases: resolve, download, verify, cache
│ ├── flash.py # esptool wrapper, chip detection
│ ├── doctor.py # Environment checks
│ ├── ports.py # Serial port discovery
│ └── workspace.py # Where sessions and outputs live
├── tests/ # pytest suite on synthetic sessions and a golden wire stream
├── run_pipeline.py # Backwards-compatible entry point (wizard)
├── pyproject.toml # Package metadata and tooling
└── README.md
```

---

Expand Down
61 changes: 58 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,61 @@
# Tooling configuration only. Packaging metadata arrives with the navkit
# restructure; until then the pipeline runs from a source checkout.
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "navkit"
dynamic = ["version"]
description = "Host tools for the Multi-Sensor Navigation System: flash firmware, log sessions, calibrate."
readme = "README.md"
license = "MIT"
license-files = ["LICENSE"]
requires-python = ">=3.10"
authors = [{ name = "Shivtej Gaikwad" }]
keywords = ["esp32", "imu", "gps", "sensor-fusion", "calibration", "data-logging"]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
"Topic :: System :: Hardware",
"Programming Language :: Python :: 3",
]
# Core: everything needed to flash a board and log from it.
dependencies = [
"pyserial>=3.5",
"esptool>=5.0",
"platformdirs>=4.0",
]

[project.optional-dependencies]
# Trim, diagnose, calibrate and plot.
pipeline = [
"pandas>=2.0",
"numpy>=1.24",
"matplotlib>=3.7",
"scipy>=1.10",
]
dev = [
"navkit[pipeline]",
"pytest>=8.0",
"ruff>=0.6",
]

[project.scripts]
nav = "navkit.cli:main"

[project.urls]
Homepage = "https://github.com/multi-sensor-navigation-system"
Repository = "https://github.com/multi-sensor-navigation-system/data-pipeline"
Changelog = "https://github.com/multi-sensor-navigation-system/data-pipeline/blob/main/CHANGELOG.md"

[tool.hatch.version]
path = "src/navkit/__init__.py"

[tool.hatch.build.targets.wheel]
packages = ["src/navkit"]

[tool.hatch.build.targets.sdist]
include = ["src", "tests", "README.md", "LICENSE", "CHANGELOG.md"]

[tool.ruff]
target-version = "py310"
Expand All @@ -18,4 +74,3 @@ ignore = [

[tool.pytest.ini_options]
testpaths = ["tests"]
pythonpath = [".", "pipeline"]
3 changes: 0 additions & 3 deletions requirements-dev.txt

This file was deleted.

8 changes: 3 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pyserial>=3.5
pandas>=2.0
numpy>=1.24
matplotlib>=3.7
scipy>=1.10
# Kept for people who run from a checkout. The package metadata in
# pyproject.toml is the source of truth: pip install -e ".[pipeline]"
-e .[pipeline]
Loading
Loading