Skip to main content

Crate sampling_planning

Crate sampling_planning 

Source
Expand description

§Sampling-based motion planning

Sampling-based motion planners for continuous configuration spaces: RRT, RRT*, RRT#, RRT-Connect, PRM, PRM*, SPARS, SPARS2, FMT*, BFMT*, BIT*, AIT*, SST, SST* and KPIECE. The crate is #![no_std] with alloc.

This is a motion planning crate. It is named sampling-planning because the crate name motion-planning was already taken on crates.io.

§Building blocks

A Problem bundles everything a planner needs:

Planners keep their nodes in a NearestNeighbors structure, LinearScan by default; KdTree is much faster in low-dimensional Euclidean spaces and returns identical results. Randomness always comes from a caller-provided rand_core::Rng, so a seeded RNG makes a run fully reproducible. Float math goes through libm, so results are also identical across platforms.

§Example

use rand_core::SeedableRng;
use sampling_planning::{
    Euclidean, GoalRegion, Problem, StraightLine, UniformBox, Validity, ValidityChecker,
    trees::{RrtStar, RrtStarConfig},
};

/// Free space everywhere.
struct Free;

impl ValidityChecker<Euclidean<2>> for Free {
    fn check_state(&self, _: &[f64; 2]) -> Validity {
        Validity::Valid
    }

    fn check_motion(&self, _: &Euclidean<2>, _: &[f64; 2], _: &[f64; 2]) -> Validity {
        Validity::Valid
    }
}

let problem = Problem {
    space: Euclidean::<2>,
    sampler: UniformBox::new([0.0, 0.0], [10.0, 10.0]),
    checker: Free,
    steering: StraightLine::new(1.0),
    start: [1.0, 1.0],
    goal: GoalRegion::new([9.0, 9.0], 0.5),
};

let mut rng = rand_pcg::Pcg64Mcg::seed_from_u64(7);
let gamma = 1.5 * RrtStarConfig::gamma_lower_bound(2, 100.0);
let mut planner = RrtStar::new(problem, RrtStarConfig::new(gamma, 1.0)).expect("valid problem");
planner.run(2000, &mut rng);

let path = planner.best_path().expect("free space has a path");
assert!(path.cost < 12.0);

§Planners

shortcut() and shortcut_random post-process any Path.

Not yet implemented: ABIT*, EIT*, multi-level KPIECE, and the SE(3) and compound state spaces.

Repository: https://github.com/sunsided/sampling-planning

Re-exports§

pub use rand_core;

Modules§

informed
Batch-informed planners: BIT* and AIT*.
kinodynamic
Kinodynamic planners: SST, SST* and KPIECE.
roadmaps
Roadmap and batch planners: PRM, PRM*, lazy PRM, SPARS, SPARS2, FMT* and BFMT*.
trees
Tree-expanding planners: RRT, RRT* (optionally informed), RRT# and RRT-Connect.

Structs§

Dubins
The Dubins car: SE(2) poses (Se2State) of a vehicle that drives only forward, at unit speed, with a minimum turning radius.
DubinsPath
A Dubins path: a word and its three non-negative segment lengths.
Euclidean
The Euclidean space R^N with states [f64; N] and straight-line interpolation.
GoalRegion
Every state within tolerance of center is a goal.
KdTree
A k-d tree over [f64; N] states for the Euclidean metric.
LinearScan
Checks every stored state on each query: O(n) per query, no preprocessing.
Path
A solution path.
Problem
Everything a planner needs to know about the world.
ProlateHyperspheroid
The prolate hyperspheroid {x : |x - a| + |x - b| <= max_cost} in R^N: every state that can lie on a path from a to b of Euclidean length at most max_cost.
ReedsShepp
The Reeds-Shepp car: SE(2) poses (Se2State) of a vehicle that drives forward or backward at unit speed with a minimum turning radius.
ReedsSheppPath
A Reeds-Shepp path: up to five segments with signed lengths; negative lengths drive in reverse.
Se2
SE(2) with the metric |p_1 - p_2| + rotation_weight * |angle(theta_1, theta_2)|.
Se2State
A planar pose: position (x, y) and heading theta in radians.
Segment
One segment of a Dubins or Reeds-Shepp path.
So2
The space of planar orientations: angles in radians, identified modulo 2 pi.
StraightLine
Moves along the geodesic toward the target, at most max_step far.
UniformAngle
Samples orientations uniformly from [-pi, pi).
UniformBox
Samples uniformly from the axis-aligned box [lower, upper) in R^N.
UniformSe2
Samples poses uniformly: positions from an axis-aligned box, headings from [-pi, pi).

Enums§

DubinsWord
The six Dubins words: L and R are arcs of the turning radius, S is a straight line.
SegmentKind
The motion of one path segment.
Validity
The outcome of a validity check.

Constants§

INFORMED_BOX_ATTEMPTS
The most hyperspheroid samples UniformBox’s direct informed sampling draws before it gives up because they keep falling outside the box.

Traits§

NearestNeighbors
Stores planner nodes by id and answers proximity queries under a StateSpace metric.
RemovableNeighbors
A NearestNeighbors structure that can also forget nodes.
Sampler
Draws states for a planner.
StateSpace
A continuous configuration space with a metric and a geodesic interpolation.
Steering
Extends a state toward a target state.
ValidityChecker
Checks states and motions of a StateSpace.

Functions§

angle_difference
The signed shortest rotation from from to to, in [-pi, pi).
discretized_motion
Checks a motion by checking interpolated states at most resolution apart.
shortcut
Greedy vertex shortcutting: from each kept state, jumps to the furthest later state that a direct, valid motion of length at most max_edge reaches.
shortcut_random
Randomized shortcutting: attempts times, picks two random points along the path and replaces the piece between them by a direct motion if that is valid, at most max_edge long and strictly cheaper.
unit_f64
Draws a uniform f64 in [0, 1) from one next_u64 call.
wrap_angle
Wraps an angle in radians into [-pi, pi).