pub struct Path { /* private fields */ }Expand description
Unified path abstraction over parametric, spline, and evaluator representations.
Construct via Path::from_parametric,
Path::from_waypoints,
Path::from_evaluator_2nd, or
Path::from_evaluator_3rd, then
query a batch of parameter values with the evaluate_* family of methods.
The valid parameter domain is [s_min, s_max] (set at construction time).
Out-of-range behaviour is controlled by OutOfRangeMode: the default is to
return an error; it can be changed to silent clamping.
Implementations§
Source§impl Path
impl Path
Sourcepub fn from_parametric<F>(
q_fn: F,
s_min: f64,
s_max: f64,
) -> Result<Self, PathError>
pub fn from_parametric<F>( q_fn: F, s_min: f64, s_max: f64, ) -> Result<Self, PathError>
Build a parametric path from an analytic closure.
Derivatives up to third order are computed automatically via Jet3
forward-mode AD. The closure only needs to express q(s) symbolically;
no manual differentiation is required.
§Arguments
q_fn: closure mapping scalarsto adim-dimensional position vectors_min: lower bound of the path parameters_max: upper bound of the path parameter (s_max > s_minrequired)
§Errors
PathError::InvalidRange:s_min >= s_maxor either value is non-finitePathError::InvalidDimension: closure returned an empty vector
Sourcepub fn from_evaluator_2nd<E>(
evaluator: E,
s_min: f64,
s_max: f64,
) -> Result<Self, PathError>where
E: PathEvaluator2nd + 'static,
pub fn from_evaluator_2nd<E>(
evaluator: E,
s_min: f64,
s_max: f64,
) -> Result<Self, PathError>where
E: PathEvaluator2nd + 'static,
Build a path from an evaluator that provides explicit derivatives up to second order.
Use this constructor when derivatives are already available from an
external source and automatic differentiation is not desired. The
evaluator is owned by the returned Path through an internal
Arc, so the path can be passed around without borrowing the original
value.
§Arguments
evaluator: object that writes column-major derivative bufferss_min: lower bound of the path parameters_max: upper bound of the path parameter (s_max > s_minrequired)
§Errors
PathError::InvalidRange:s_min >= s_maxor either value is non-finitePathError::InvalidDimension: evaluator dimension is zero
Build a path from a shared explicit-derivative evaluator up to second order.
This is the same representation as Path::from_evaluator_2nd, but accepts
an already shared evaluator. It is useful when multiple paths or
application components need to hold the same evaluator object.
§Errors
PathError::InvalidRange:s_min >= s_maxor either value is non-finitePathError::InvalidDimension: evaluator dimension is zero
Sourcepub fn from_evaluator_3rd<E>(
evaluator: E,
s_min: f64,
s_max: f64,
) -> Result<Self, PathError>where
E: PathEvaluator3rd + 'static,
pub fn from_evaluator_3rd<E>(
evaluator: E,
s_min: f64,
s_max: f64,
) -> Result<Self, PathError>where
E: PathEvaluator3rd + 'static,
Build a path from an evaluator that provides explicit derivatives up to third order.
This is the constructor to use when the path will be evaluated by
third-order APIs such as TOPP3/COPP3 sampling. For TOPP2/COPP2-only
usage, Path::from_evaluator_2nd avoids requiring a third derivative
implementation.
§Errors
PathError::InvalidRange:s_min >= s_maxor either value is non-finitePathError::InvalidDimension: evaluator dimension is zero
Build a path from a shared explicit-derivative evaluator up to third order.
§Errors
PathError::InvalidRange:s_min >= s_maxor either value is non-finitePathError::InvalidDimension: evaluator dimension is zero
Sourcepub fn from_evaluator<E>(
evaluator: E,
s_min: f64,
s_max: f64,
) -> Result<Self, PathError>where
E: PathEvaluator3rd + 'static,
pub fn from_evaluator<E>(
evaluator: E,
s_min: f64,
s_max: f64,
) -> Result<Self, PathError>where
E: PathEvaluator3rd + 'static,
Build a path from a third-order explicit-derivative evaluator.
This compatibility constructor is equivalent to
Path::from_evaluator_3rd. New code should prefer
Path::from_evaluator_2nd or Path::from_evaluator_3rd to make the
supported derivative order explicit.
Build a path from a shared third-order explicit-derivative evaluator.
This compatibility constructor is equivalent to
Path::from_shared_evaluator_3rd.
Sourcepub fn from_waypoints(
waypoints: &DMatrix<f64>,
cfg: SplineConfig,
) -> Result<Self, PathError>
pub fn from_waypoints( waypoints: &DMatrix<f64>, cfg: SplineConfig, ) -> Result<Self, PathError>
Build a spline path by interpolating a waypoint matrix.
Internally solves the Hermite spline system with an O(N) block-Thomas
algorithm; all dimensions are solved in parallel.
The default configuration (SplineConfig::default) uses a quintic
(order-5) spline with s in [0, 1].
§Arguments
waypoints: matrix of shape(dim, n_points); each column is one waypointcfg: spline configuration (order, parameter range, boundary derivatives, out-of-range mode)
§Errors
PathError::InvalidDimension:waypointshas zero rowsPathError::NotEnoughWaypoints: fewer than 2 columnsPathError::InvalidOrder:order < 3PathError::InvalidRange: invalid parameter rangePathError::SingularSystem: spline system is singular (extremely rare)
Sourcepub fn from_waypoints_view(
waypoints: DMatrixView<'_, f64>,
cfg: SplineConfig,
) -> Result<Self, PathError>
pub fn from_waypoints_view( waypoints: DMatrixView<'_, f64>, cfg: SplineConfig, ) -> Result<Self, PathError>
Build a spline path from a borrowed waypoint matrix view.
This accepts nalgebra views such as waypoints.as_view() and compatible
strided column-major views. See Path::from_waypoints for the full
interpolation semantics, configuration, and error conditions.
Sourcepub fn evaluate_q(&self, s: &[f64]) -> Result<PathDerivatives, PathError>
pub fn evaluate_q(&self, s: &[f64]) -> Result<PathDerivatives, PathError>
Evaluate position q only at the query points (cheapest; no derivatives).
§Arguments
s: one-dimensional parameter samples (lengthN)
§Returns
PathDerivatives with dq / ddq / dddq all None;
q has shape (dim, N).
§Errors
PathError::OutOfRangeS: a query value is out of range (only inErrormode)
Sourcepub fn evaluate_up_to_2nd(
&self,
s: &[f64],
) -> Result<PathDerivatives, PathError>
pub fn evaluate_up_to_2nd( &self, s: &[f64], ) -> Result<PathDerivatives, PathError>
Evaluate position, velocity, and acceleration (q, dq, ddq); jerk is not computed.
§Arguments
s: one-dimensional parameter samples (lengthN)
§Returns
PathDerivatives with dddq = None;
q / dq / ddq each have shape (dim, N).
Sourcepub fn evaluate_up_to_3rd(
&self,
s: &[f64],
) -> Result<PathDerivatives, PathError>
pub fn evaluate_up_to_3rd( &self, s: &[f64], ) -> Result<PathDerivatives, PathError>
Evaluate position and all three derivative orders (q, dq, ddq, dddq).
This is the most expensive evaluation method. If jerk is not needed,
prefer evaluate_up_to_2nd.
§Arguments
s: one-dimensional parameter samples (lengthN)
§Returns
PathDerivatives with all four fields populated; each matrix has shape (dim, N).
§Errors
PathError::OutOfRangeS: a query value is out of range
§Example
use copp::path::{Path, sin, cos};
use copp::path::autodiff::Jet3;
let path = Path::from_parametric(
|s: Jet3| vec![sin(s), cos(s)],
0.0, 1.0,
).unwrap();
let s = [0.0, 0.25, 0.5, 0.75, 1.0];
let out = path.evaluate_up_to_3rd(&s).unwrap();
let dq = out.dq.as_ref().unwrap();
let dddq = out.dddq.as_ref().unwrap();
// dim 0 is sin(s); its first derivative is cos(s)
assert!((dq[(0, 0)] - 1.0_f64.cos()).abs() < 1e-10);
// dim 1 is cos(s); its third derivative is sin(s)
assert!((dddq[(1, 0)] - 0.0_f64.sin()).abs() < 1e-10);Auto Trait Implementations§
impl Freeze for Path
impl !RefUnwindSafe for Path
impl Send for Path
impl Sync for Path
impl Unpin for Path
impl !UnwindSafe for Path
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.