Skip to main content

sampling_planning/
roadmaps.rs

1//! Roadmap and batch planners: PRM, PRM*, lazy PRM, SPARS, SPARS2, FMT* and BFMT*.
2//!
3//! These planners do not grow a tree from the start. [`Prm`] builds a graph once and answers
4//! many queries on it; FMT* marches a tree through a batch of samples drawn up front, BFMT*
5//! marches two, from the start and from the goal.
6//! Neither needs a [`Steering`](crate::Steering) function: edges are direct motions along
7//! [`StateSpace::interpolate`](crate::StateSpace::interpolate).
8//!
9//! ```mermaid
10//! graph LR
11//!     Grow["grow: sample, check state"] --> Connect["connect to neighbors"]
12//!     Connect --> Grow
13//!     Connect --> Query["query: attach start and goal"]
14//!     Query --> Dijkstra
15//!     Dijkstra -->|lazy: invalid edge| Query
16//! ```
17
18mod bfmt_star;
19mod fmt_star;
20mod march;
21mod prm;
22mod spars;
23mod spars2;
24mod sparse;
25
26use core::fmt;
27
28pub use bfmt_star::{BfmtStar, BfmtStarConfig, Termination};
29pub use fmt_star::{FmtStar, FmtStarConfig};
30pub use prm::{Connection, Prm, PrmConfig};
31pub use spars::{Spars, SparsConfig};
32pub use spars2::{NEAR_ATTEMPTS, Spars2, Spars2Config};
33pub use sparse::GuardKind;
34
35use crate::Validity;
36
37/// Why a roadmap planner could not be created or queried.
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39pub enum Error {
40    /// The query start did not check as [`Validity::Valid`]; carries the actual result.
41    InvalidStart(Validity),
42    /// The goal center did not check as [`Validity::Valid`] for a planner that roots a tree
43    /// there; carries the actual result.
44    InvalidGoal(Validity),
45    /// A connection radius, radius constant or k-nearest constant is not positive and finite,
46    /// or a fixed neighbor count is zero.
47    InvalidRadius,
48}
49
50impl fmt::Display for Error {
51    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52        match self {
53            Self::InvalidStart(validity) => write!(f, "start state is not valid ({validity:?})"),
54            Self::InvalidGoal(validity) => write!(f, "goal center is not valid ({validity:?})"),
55            Self::InvalidRadius => f.write_str(
56                "connection radius and constants must be positive and finite, k at least one",
57            ),
58        }
59    }
60}
61
62impl core::error::Error for Error {}