sampling_planning/trees.rs
1//! Tree-expanding planners: RRT, RRT* (optionally informed), RRT# and RRT-Connect.
2//!
3//! Both planners are incremental. [`Rrt::step`] and [`RrtStar::step`] do one iteration,
4//! `run` does many, and `best_path` returns the current best solution. One iteration:
5//!
6//! ```mermaid
7//! graph LR
8//! Sample["sample (goal-biased)"] --> Nearest
9//! Nearest --> Steer
10//! Steer --> Check["check motion"]
11//! Check -->|valid| Add["add node"]
12//! Check -->|invalid or unknown| Sample
13//! Add -->|RRT*| Rewire["choose parent, rewire"]
14//! ```
15
16mod growth;
17mod rrt;
18mod rrt_connect;
19mod rrt_sharp;
20mod rrt_star;
21mod targets;
22mod tree;
23
24use core::fmt;
25
26pub use rrt::{Rrt, RrtConfig};
27pub use rrt_connect::RrtConnect;
28pub use rrt_sharp::RrtSharp;
29pub use rrt_star::{INFORMED_ATTEMPTS, RrtStar, RrtStarConfig};
30
31use crate::Validity;
32
33/// Why a tree planner could not be created.
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub enum Error {
36 /// The start state did not check as [`Validity::Valid`]; carries the actual result.
37 InvalidStart(Validity),
38 /// The goal center did not check as [`Validity::Valid`] for a planner that roots a tree
39 /// there; carries the actual result.
40 InvalidGoal(Validity),
41 /// The goal bias is not in `[0, 1]`.
42 GoalBiasOutOfRange,
43 /// The RRT* radius constant `gamma` is not positive and finite.
44 InvalidGamma,
45 /// The RRT* radius cap is not positive.
46 InvalidMaxRadius,
47}
48
49impl fmt::Display for Error {
50 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51 match self {
52 Self::InvalidStart(validity) => write!(f, "start state is not valid ({validity:?})"),
53 Self::InvalidGoal(validity) => write!(f, "goal center is not valid ({validity:?})"),
54 Self::GoalBiasOutOfRange => f.write_str("goal bias must be in [0, 1]"),
55 Self::InvalidGamma => f.write_str("gamma must be positive and finite"),
56 Self::InvalidMaxRadius => f.write_str("max radius must be positive"),
57 }
58 }
59}
60
61impl core::error::Error for Error {}