Interpolation API
skelarm.interpolation
From-scratch interpolation for resampling reference trajectories.
A recorded or generated reference trajectory is a finite series of samples
(t_i, y_i) that usually does not line up with the controller's time grid, so it
must be resampled. This module implements three schemes by hand (no SciPy):
linear— piecewise-linear; cheap and shape-preserving, but onlyC^0.cubic_spline— the natural cubic spline;C^2with analytic first and second derivatives, the right default for deriving smoothq̇/q̈references.lagrange— the barycentric form of the global Lagrange polynomial; exact for polynomial data but oscillatory for many nodes (Runge), so reserve it for short series.
The series may be a 1-D signal of shape (N,) or a multi-column signal of shape
(N, k) (e.g. tip (x, y) or per-joint angles), interpolated column-wise.
See docs/reference/09_trajectory_filtering.md for the theory.
INTERPOLATORS = ('linear', 'cubic_spline', 'lagrange')
module-attribute
The supported interpolation method names (the method argument).
interpolate(times, values, query, *, method='cubic_spline')
Resample a sampled series onto new query times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
ArrayLike
|
Strictly increasing sample times, shape |
required |
values
|
ArrayLike
|
Sample values, shape |
required |
query
|
ArrayLike
|
Times to evaluate at, a scalar or shape |
required |
method
|
str
|
One of :data: |
'cubic_spline'
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
The interpolated values: shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/skelarm/interpolation.py
resample_with_derivatives(times, values, query, *, method='cubic_spline')
Resample a series and return its value, first, and second time derivatives.
For cubic_spline the derivatives are analytic; for linear and lagrange
they fall back to finite differences of the resampled value on the query grid (so
pass a reasonably dense, near-uniform query for those methods).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
ArrayLike
|
As in :func: |
required |
values
|
ArrayLike
|
As in :func: |
required |
query
|
ArrayLike
|
As in :func: |
required |
method
|
ArrayLike
|
As in :func: |
required |
Returns:
| Type | Description |
|---|---|
tuple[NDArray, NDArray, NDArray]
|
|