pub struct RrtConnect<Sp: StateSpace, Sa, C, St, N = LinearScan<<Sp as StateSpace>::State>> { /* private fields */ }Expand description
RRT-Connect: grows one tree from the start and one from the goal center, and after every extension of one tree greedily steers the other tree toward the new node until it either reaches it or hits an obstacle.
Finds feasible paths much faster than Rrt in open spaces with narrow
passages near the endpoints, but, like RRT, does not improve them; run
shortcut on the result.
The goal tree is rooted at GoalRegion::center, so the
returned path ends there. Its edges are traveled toward the root, so they are checked in that
direction: a new goal-tree state gets ValidityChecker::check_state and then
ValidityChecker::check_motion from itself to its parent.
The trees meet when a steered state is at distance zero from the target state, so
Steering::steer must return the target itself when it can reach it, as
StraightLine does.
§Examples
use rand_core::SeedableRng;
use sampling_planning::{
Euclidean, GoalRegion, Problem, StraightLine, UniformBox, Validity, ValidityChecker,
trees::RrtConnect,
};
/// 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 planner = RrtConnect::new(problem).expect("valid start and goal");
let path = planner.solve(1000, &mut rand_pcg::Pcg64Mcg::seed_from_u64(1));
assert_eq!(path.expect("free space").states.last(), Some(&[9.0, 9.0]));Implementations§
Source§impl<Sp, Sa, C, St> RrtConnect<Sp, Sa, C, St>
impl<Sp, Sa, C, St> RrtConnect<Sp, Sa, C, St>
Sourcepub fn new(problem: Problem<Sp, Sa, C, St>) -> Result<Self, Error>
pub fn new(problem: Problem<Sp, Sa, C, St>) -> Result<Self, Error>
Creates a planner with LinearScan nearest-neighbor indices.
§Errors
Error::InvalidStartif the start state is not valid.Error::InvalidGoalif the goal center is not valid.
Source§impl<Sp, Sa, C, St, N> RrtConnect<Sp, Sa, C, St, N>where
Sp: StateSpace,
Sa: Sampler<Sp::State>,
C: ValidityChecker<Sp>,
St: Steering<Sp>,
N: NearestNeighbors<Sp> + Clone,
impl<Sp, Sa, C, St, N> RrtConnect<Sp, Sa, C, St, N>where
Sp: StateSpace,
Sa: Sampler<Sp::State>,
C: ValidityChecker<Sp>,
St: Steering<Sp>,
N: NearestNeighbors<Sp> + Clone,
Sourcepub fn with_nearest_neighbors(
problem: Problem<Sp, Sa, C, St>,
nn: N,
) -> Result<Self, Error>
pub fn with_nearest_neighbors( problem: Problem<Sp, Sa, C, St>, nn: N, ) -> Result<Self, Error>
Creates a planner; each tree gets a clone of the given empty nearest-neighbor index.
§Errors
Error::InvalidStartif the start state is not valid.Error::InvalidGoalif the goal center is not valid.
Sourcepub fn step<R: Rng + ?Sized>(&mut self, rng: &mut R) -> bool
pub fn step<R: Rng + ?Sized>(&mut self, rng: &mut R) -> bool
Runs one iteration: extends the active tree toward a sample, then connects the other tree toward the new node. Returns whether a solution exists afterward.
Sourcepub fn solve<R: Rng + ?Sized>(
&mut self,
max_iterations: usize,
rng: &mut R,
) -> Option<Path<Sp::State>>
pub fn solve<R: Rng + ?Sized>( &mut self, max_iterations: usize, rng: &mut R, ) -> Option<Path<Sp::State>>
Runs until a solution is found or max_iterations iterations have run.
Returns the solution, or None if none was found within the budget.
Sourcepub const fn path(&self) -> Option<&Path<Sp::State>>
pub const fn path(&self) -> Option<&Path<Sp::State>>
The solution, or None if the trees have not met yet.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
The number of nodes in both trees, including both roots.