Skip to main content

Synchronize trajectories based on their path length.

Project description

sensor-sync

sensor-sync is a Python module for estimating the relative time offset between two position-producing sensors.

It is designed for streams where both sensors observe the same motion but do not agree perfectly on timestamp alignment. The module combines timestamp calibration, path-length tracking, interpolation, and a Kalman filter to estimate a stable temporal shift.

What it provides

The public surface is centered around two main types:

  • Position: one timestamped 3D sample with a scalar velocity
  • Synchronizer: consumes primary and secondary sensor samples and maintains the current estimate

The Kalman state is maintained internally by Synchronizer.

The estimated state contains:

  • delta_t: estimated time shift between the sensor streams
  • bias: estimated path-length bias
  • sigma_delta_t: uncertainty of the time-shift estimate
  • sigma_bias: uncertainty of the bias estimate

Estimation model

The synchronizer works in two phases.

During calibration, it computes a rough per-sensor wall-clock offset from incoming timestamps. After calibration, it shifts each sensor stream by its average offset and begins trajectory-based matching.

For each incoming sample, the module accumulates traveled path length. Secondary samples are matched against neighboring primary samples, and the primary trajectory is linearly interpolated to the secondary timestamp. The difference in path length becomes the measurement used by the Kalman filter.

The filter estimates two quantities:

  • a time offset term
  • a bias term that absorbs residual path-length drift

Conceptually, the measurement model is:

$$ \Delta s \approx v \cdot \Delta t + b $$

where $\Delta s$ is the observed path-length difference, $v$ is interpolated velocity, $\Delta t$ is the time shift, and $b$ is a slowly varying bias.

Installation

Requirements:

  • Python 3.9 or newer

Using uv:

uv sync

To activate the virtual environment on Windows PowerShell:

.\.venv\Scripts\Activate.ps1

The project depends on:

  • numpy
  • matplotlib
  • trajectopy

Usage

Create a synchronizer and feed it timestamped position samples from both streams.

from sensor_sync import Position, Synchronizer

synchronizer = Synchronizer(calibration_samples=20)

primary_sample = Position(
	timestamp=1000.0,
	x=0.0,
	y=0.0,
	z=0.0,
	v=2.5,
)

secondary_sample = Position(
	timestamp=1000.1,
	x=0.2,
	y=0.0,
	z=0.0,
	v=2.4,
)

synchronizer.on_new_position_sensor_primary(primary_sample)
synchronizer.on_new_position_sensor_secondary(secondary_sample)

state = synchronizer.state
print(state["delta_t"], state["bias"])

In a real integration, keep feeding both sensors as samples arrive. Once calibration has completed and enough primary samples are available for interpolation, the estimate will be updated automatically.

Integration notes

  • The synchronizer is thread-safe at the input boundary and guards updates with a lock.
  • Incoming samples are expected to include velocity magnitude in Position.v.
  • Matching assumes that the primary stream can provide surrounding samples for interpolation.
  • Calibration currently depends on time.time() and incoming sample timestamps being comparable in the same clock domain.
  • The implementation mutates position.timestamp in place after applying the sensor-specific average offset.

Tuning

Synchronizer exposes three filter-tuning parameters at construction time:

  • delta_t_var: process noise for time-shift stability
  • bias_var: process noise for bias drift
  • delta_path_length_var: measurement noise for path-length observations

These can be passed directly to the constructor alongside calibration_samples and initial_dt.

synchronizer = Synchronizer(
	calibration_samples=20,
	initial_dt=0.0,
	delta_t_var=1e-12,
	bias_var=1e-3,
	delta_path_length_var=0.1,
)

Smaller process noise makes the estimate more stable but less responsive. Larger measurement noise makes the filter trust its prior more than new path-length observations.

Module layout

  • sensor_sync.py: core implementation of the estimator and synchronizer
  • pyproject.toml: package metadata and dependencies

Status

This repository currently exposes a single-module implementation intended for experimentation and integration work. It is not yet packaged as a multi-file library with a formal test suite or stable public API guarantees.

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

trajectory_sync-0.1.1.tar.gz (29.7 kB view details)

Uploaded Source

Built Distribution

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

trajectory_sync-0.1.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file trajectory_sync-0.1.1.tar.gz.

File metadata

  • Download URL: trajectory_sync-0.1.1.tar.gz
  • Upload date:
  • Size: 29.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for trajectory_sync-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6c17f557cddf9ed445986548d0038472e6d7b8bea9b206f7d1a65b987c0508b1
MD5 7987b6555eb612339233288760a4e331
BLAKE2b-256 a5b38c1e32f0faba0f809fad6ad024371d75c93abd1d5f5159ae60ccc51bd1bd

See more details on using hashes here.

File details

Details for the file trajectory_sync-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: trajectory_sync-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for trajectory_sync-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a679e97b596364a44ee310f10cb4c44633488ca397ead399e9bee79be32c59b3
MD5 55568f1e460f12ff89f5d49766b3dda7
BLAKE2b-256 0ccaa616677374cc4504457fdeaf621619c3f53e94392c0447702eb452ab03f3

See more details on using hashes here.

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