Skip to main content

Two-point interpolation with constant acceleration and constant jerk

Project description

Two Points Interpolation Python

Calculate optimal trajectory (position, velocity, acceleration) between two points with kinematic constraints.

Overview

This library provides two trajectory planning algorithms:

  1. Constant Acceleration: Generates smooth trajectories with acceleration limits
  2. Constant Jerk: Generates even smoother trajectories with jerk (acceleration derivative) limits

Installation

From PyPI (when published)

pip install two-point-interpolation

From Source

git clone https://github.com/yuokamoto/two_points_interpolation_py.git
cd two_points_interpolation_py
pip install -e .

For Development

git clone https://github.com/yuokamoto/two_points_interpolation_py.git
cd two_points_interpolation_py
pip install -e ".[dev]"

# Install pre-commit hooks for automatic code formatting and type checking
pre-commit install

The pre-commit hooks will automatically run before each commit to:

  • Format code with autopep8
  • Check types with mypy (strict for constant_acc module)
  • Validate code style with flake8
  • Remove trailing whitespace
  • Validate YAML files

You can also run the hooks manually on all files:

pre-commit run --all-files

Quick Start

Constant Acceleration

from two_point_interpolation import TwoPointInterpolation

# Create interpolator
interp = TwoPointInterpolation()

# Set start, end, and constraints
interp.init(p0=0.0, pe=100.0, acc_max=2.0, vmax=10.0, dec_max=4.0)

# Calculate trajectory
total_time = interp.calc_trajectory()

# Get state at any time
pos, vel, acc = interp.get_point(t=5.0)

Constant Jerk

from two_point_interpolation.constant_jerk import TwoPointInterpolationJerk

interp = TwoPointInterpolationJerk()
interp.init(p0=0.0, pe=100.0, amax=2.0, vmax=10.0, jmax=1.0)

total_time = interp.calc_trajectory()
pos, vel, acc, jerk = interp.get_point(t=5.0)

Note: Constant jerk implementation is currently under review. See TODO section below.

Examples

Run example scripts to see visualizations:

# Basic constant acceleration
python3 examples/example_constant_acc.py

# Constant jerk (smoother)
python3 examples/example_constant_jerk.py

Testing

The library includes a comprehensive YAML-based testing system.

Quick Start

# Run all tests
python -m pytest tests/test_yaml_cases.py -v

# Generate trajectory visualizations
python tests/generate_plots.py

# List available test categories
python tests/generate_plots.py --list

Detailed Documentation

For comprehensive testing information, debugging guides, and visualization usage:

๐Ÿ“– See tests/README.md for complete testing documentation

Project Structure

two_points_interpolation_py/
โ”œโ”€โ”€ two_point_interpolation/              # Main package
โ”‚   โ”œโ”€โ”€ __init__.py                       # Package exports
โ”‚   โ”œโ”€โ”€ constant_acc.py                   # Acceleration-based planning (enhanced)
โ”‚   โ””โ”€โ”€ constant_jerk.py                  # Jerk-based planning (TODO: needs review)
โ”œโ”€โ”€ examples/                             # Example scripts
โ”‚   โ””โ”€โ”€ images/                           # Generated plots
โ”œโ”€โ”€ tests/                                # YAML-based test suite (51+ tests)
โ”‚   โ”œโ”€โ”€ test_cases.yaml                   # Test case definitions
โ”‚   โ”œโ”€โ”€ test_case_loader.py               # YAML parsing utilities
โ”‚   โ”œโ”€โ”€ test_yaml_cases.py                # Test runner
โ”‚   โ”œโ”€โ”€ generate_plots.py                 # Visualization tool
โ”‚   โ””โ”€โ”€ plots/                            # Generated test plots
โ””โ”€โ”€ docs/                                 # Documentation
    โ”œโ”€โ”€ CONSTANT_ACC_DERIVATION.md        # Mathematical details
    โ”œโ”€โ”€ QUADRATIC_COEFFICIENTS_DERIVATION.md  # Quadratic solution derivation
    โ”œโ”€โ”€ edge_cases_analysis.md             # Edge cases and overspeed analysis
    โ””โ”€โ”€ CHANGELOG.md                      # Version history

Example Results

Case 0: vmax not reached

Case 0

Parameters: t0=1.0, p0=5, pe=15, acc_max=2.0, dec_max=3.0, vmax=10.0, v0=0, ve=0

Trajectory when the peak velocity is below vmax. Shows two phases: acceleration and deceleration.

Case 1: vmax reached

Case 1

Parameters: t0=0, p0=0, pe=50, acc_max=2.0, dec_max=4.0, vmax=8.0, v0=2.0, ve=1.0

Trajectory when vmax is reached. Shows three phases: acceleration, constant velocity, and deceleration.

Documentation

Known Issues & TODO

Constant Jerk Implementation Issues

The constant_jerk module requires significant improvements:

  1. API Contract Violation: The ve (final velocity) parameter is accepted in init() but never used in calculations
  2. Debug Output: calc_trajectory() prints debug information to stdout (should use logging or be removed)
  3. Time Boundary Bug: Case 3 condition uses 4*t1+2*2*t2+t3 instead of correct 4*t1+2*t2+t3, causing phase transition errors
  4. Missing Tests: No test coverage for constant jerk functionality
  5. Support acc_max != dec_max: Extend to support independent acceleration/deceleration limits

Other

  • Add comprehensive test suite for constant_jerk module
  • Verify mathematical correctness of jerk-based trajectories

Requirements

  • Python 3.6+
  • NumPy
  • Matplotlib (for examples)

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

This software is provided "AS IS" without warranty of any kind.

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

two_point_interpolation-1.2.1.tar.gz (42.4 kB view details)

Uploaded Source

Built Distribution

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

two_point_interpolation-1.2.1-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file two_point_interpolation-1.2.1.tar.gz.

File metadata

  • Download URL: two_point_interpolation-1.2.1.tar.gz
  • Upload date:
  • Size: 42.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for two_point_interpolation-1.2.1.tar.gz
Algorithm Hash digest
SHA256 2457d488751e99e2a45f290a2e048a3c272f0bdb52f92f4a1b00c18e8f626dbb
MD5 4ca1b8fdf60b3582e13f1726b90d60ba
BLAKE2b-256 0add8db5dc0d06c7613c6166e19d6f85652eb7dd13110fde5969c8bf62088272

See more details on using hashes here.

File details

Details for the file two_point_interpolation-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for two_point_interpolation-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fae969718ae0ebdd057c4b0931827925baba1576d5abca25a0a1646300c92ca4
MD5 778a8d7a2a865b724b8904f7cdbaf43f
BLAKE2b-256 67ea64866fd7b4e38852c222f092d9165da0757fe66c9ac2b44fb0388cb6cdce

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