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:
- a
StateSpacewith a metric and interpolation, for exampleEuclidean,So2,Se2, or the car-likeDubinsandReedsShepp; - a
Samplerthat draws states, for exampleUniformBox; - a
ValidityCheckerfor states and motions, which answers with a three-valuedValidity. Planners accept onlyValidity::Valid;Validity::Unknownis rejected likeValidity::Invalid; - a
Steeringfunction, for exampleStraightLine; - a start state and a
GoalRegion.
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
trees:Rrt,RrtStar(radius or k-nearest, optionally informed),RrtSharpand the bidirectionalRrtConnect, all over aProblem.roadmaps: the multi-queryPrm(PRM, PRM*, lazy PRM) and the sparse roadmap spannersSparsandSpars2, and the batch plannersFmtStarandBfmtStar. They need no steering function.informed: the batch-informedBitStarandAitStar.kinodynamic:Sst(SST and SST*) andKpieceover aPropagatorthat forward-simulates controls.
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. - Dubins
Path - 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. - Goal
Region - Every state within
toleranceofcenteris a goal. - KdTree
- A k-d tree over
[f64; N]states for theEuclideanmetric. - Linear
Scan - 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.
- Prolate
Hyperspheroid - The prolate hyperspheroid
{x : |x - a| + |x - b| <= max_cost}in R^N: every state that can lie on a path fromatobof Euclidean length at mostmax_cost. - Reeds
Shepp - The Reeds-Shepp car: SE(2) poses (
Se2State) of a vehicle that drives forward or backward at unit speed with a minimum turning radius. - Reeds
Shepp Path - 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 headingthetain radians. - Segment
- One segment of a Dubins or Reeds-Shepp path.
- So2
- The space of planar orientations: angles in radians, identified modulo
2 pi. - Straight
Line - Moves along the geodesic toward the target, at most
max_stepfar. - Uniform
Angle - Samples orientations uniformly from
[-pi, pi). - Uniform
Box - Samples uniformly from the axis-aligned box
[lower, upper)in R^N. - Uniform
Se2 - Samples poses uniformly: positions from an axis-aligned box, headings from
[-pi, pi).
Enums§
- Dubins
Word - The six Dubins words: L and R are arcs of the turning radius, S is a straight line.
- Segment
Kind - 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§
- Nearest
Neighbors - Stores planner nodes by id and answers proximity queries under a
StateSpacemetric. - Removable
Neighbors - A
NearestNeighborsstructure that can also forget nodes. - Sampler
- Draws states for a planner.
- State
Space - A continuous configuration space with a metric and a geodesic interpolation.
- Steering
- Extends a state toward a target state.
- Validity
Checker - Checks states and motions of a
StateSpace.
Functions§
- angle_
difference - The signed shortest rotation from
fromtoto, in[-pi, pi). - discretized_
motion - Checks a motion by checking interpolated states at most
resolutionapart. - shortcut
- Greedy vertex shortcutting: from each kept state, jumps to the furthest later state that a
direct, valid motion of length at most
max_edgereaches. - shortcut_
random - Randomized shortcutting:
attemptstimes, picks two random points along the path and replaces the piece between them by a direct motion if that is valid, at mostmax_edgelong and strictly cheaper. - unit_
f64 - Draws a uniform
f64in[0, 1)from onenext_u64call. - wrap_
angle - Wraps an angle in radians into
[-pi, pi).