A Rust library for kinematic path planning from 1st to 4th order, with full boundary conditions and trajectory stitching.
| Order | Constrained | Free | Profile shape |
|---|---|---|---|
| 1st | v_max |
a = ∞ |
Step in velocity |
| 2nd | v_max, a_max |
j = ∞ |
Trapezoidal velocity |
| 3rd | v_max, a_max, j_max |
s = ∞ |
S-curve (trapezoidal accel) |
| 4th | v_max, a_max, j_max, s_max |
— | Double S-curve |
Every planner takes a BoundaryConditions struct:
use motion_profiles::boundary::{BoundaryConditions, State};
// Full specification
let bc = BoundaryConditions::new(
State::new(q0, v0, a0, j0), // initial
State::new(q1, v1, a1, j1), // final
);
// Convenience helpers
let bc = BoundaryConditions::position_only(0.0, 10.0);
let bc = BoundaryConditions::with_velocities(0.0, 1.0, 10.0, -0.5);Higher-order planners honour more derivatives; lower-order planners ignore the ones they don't control (they should be set to 0.0).
use motion_profiles::{
BoundaryConditions,
second_order::{plan, SecondOrderLimits},
};
let bc = BoundaryConditions::with_velocities(0.0, 0.0, 10.0, 0.0);
let limits = SecondOrderLimits { v_max: 3.0, a_max: 6.0 };
let traj = plan(bc, limits);
// Sample at a specific time
let s = traj.sample(1.5);
println!("q={:.3} v={:.3} a={:.3}", s.state.position, s.state.velocity, s.state.acceleration);
// Sample uniformly
let samples = traj.sample_uniform(500);Because boundary velocities (and accelerations, for 3rd order) are fully specified, you can chain segments without discontinuities:
let seg1 = plan(BoundaryConditions::with_velocities(0.0, 0.0, 5.0, 2.0), limits);
let seg2 = plan(BoundaryConditions::with_velocities(5.0, 2.0, 9.0, 0.0), limits);
let full = seg1.append(seg2);append automatically time-shifts the second trajectory.
cargo testcargo run --example first_order # → first_order.svg
cargo run --example second_order # → second_order.svg (stitched, 3 segments)
cargo run --example fourth_order # → fourth_order.svg (4-panel: pos/vel/acc/jerk)
cargo run --example stitching # → stitching.svg (2nd + 3rd + 2nd order)src/
lib.rs — re-exports
boundary.rs — State, BoundaryConditions
profile.rs — Segment, Trajectory, Sample
first_order.rs — bang-bang velocity
second_order.rs — trapezoidal (3-phase)
third_order.rs — S-curve (7-phase)
fourth_order.rs — double S-curve (13-phase, snap-limited)
tests/
integration_tests.rs
examples/
first_order.rs / second_order.rs / fourth_order.rs / stitching.rs
third_order.rs: the 7-phase solver handles symmetric cases well; adding a full asymmetric boundary-condition solver (Berscheid & Kröger 2021 style) is the natural next step.fourth_order.rs: a time-optimal solver for arbitrary(q0,v0,a0) → (q1,v1,a1)at 4th order is research-level; the current code handles rest-to-rest correctly.- Multi-DOF: wrap single-axis planners in a
MultiAxisTrajectorythat time-scales all axes to the slowest one. - plotters: swap the hand-rolled SVG renderer in examples for
plottersto get nicer charts.