sampling_planning/space.rs
1//! State spaces: the metric and interpolation planners work in.
2
3mod curve;
4mod dubins;
5mod euclidean;
6mod reeds_shepp;
7mod se2;
8mod so2;
9
10pub use curve::{Segment, SegmentKind};
11pub use dubins::{Dubins, DubinsPath, DubinsWord};
12pub use euclidean::Euclidean;
13pub use reeds_shepp::{ReedsShepp, ReedsSheppPath};
14pub use se2::{Se2, Se2State, UniformSe2};
15pub use so2::{So2, UniformAngle, angle_difference, wrap_angle};
16
17/// A continuous configuration space with a metric and a geodesic interpolation.
18///
19/// Planners use [`StateSpace::distance`] both to find neighbors and as the path cost. Bounds
20/// are not part of the space: the [`Sampler`](crate::Sampler) decides where states come from
21/// and the [`ValidityChecker`](crate::ValidityChecker) decides where they may be.
22pub trait StateSpace {
23 /// A configuration. Cloned whenever a planner stores a node.
24 type State: Clone;
25
26 /// The number of degrees of freedom; feeds the RRT*/PRM* connection radius.
27 fn dimension(&self) -> usize;
28
29 /// The distance between two configurations.
30 ///
31 /// The length of the shortest motion from `from` to `to`.
32 ///
33 /// Must be non-negative, zero for equal states and satisfy the triangle inequality. It
34 /// should be symmetric; [`Dubins`] is the exception, because a forward-only car's way back
35 /// is longer. Forward tree planners ([`Rrt`](crate::trees::Rrt),
36 /// [`RrtStar`](crate::trees::RrtStar), [`RrtSharp`](crate::trees::RrtSharp),
37 /// [`Sst`](crate::kinodynamic::Sst)) always measure from a tree node to the target and
38 /// work with asymmetric distances. Planners that need symmetry: [`Prm`](crate::roadmaps::Prm)
39 /// stores one cost per edge for both directions, the goal tree of
40 /// [`RrtConnect`](crate::trees::RrtConnect) measures from the target to its nodes,
41 /// [`Spars2`](crate::roadmaps::Spars2) keeps undirected edges, and
42 /// [`FmtStar`](crate::roadmaps::FmtStar), [`BfmtStar`](crate::roadmaps::BfmtStar),
43 /// [`BitStar`](crate::informed::BitStar) and [`KdTree`](crate::KdTree) assume a metric
44 /// for their neighborhoods and heuristics.
45 fn distance(&self, from: &Self::State, to: &Self::State) -> f64;
46
47 /// The configuration at fraction `t` in `[0, 1]` of the way from `from` to `to`.
48 ///
49 /// `t = 0` yields `from` and `t = 1` yields `to`.
50 fn interpolate(&self, from: &Self::State, to: &Self::State, t: f64) -> Self::State;
51
52 /// Whether states are coordinate vectors, [`StateSpace::distance`] is the Euclidean norm of
53 /// their difference and [`StateSpace::interpolate`] the straight line.
54 ///
55 /// Samplers that exploit Euclidean geometry, such as the direct informed sampling of
56 /// [`UniformBox`](crate::UniformBox), check this before they assume it. The default is
57 /// `false`, which is always safe.
58 fn is_euclidean(&self) -> bool {
59 false
60 }
61}