Skip to main content

RrtConnect

Struct RrtConnect 

Source
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>
where Sp: StateSpace, Sa: Sampler<Sp::State>, C: ValidityChecker<Sp>, St: Steering<Sp>,

Source

pub fn new(problem: Problem<Sp, Sa, C, St>) -> Result<Self, Error>

Creates a planner with LinearScan nearest-neighbor indices.

§Errors
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,

Source

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
Source

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.

Source

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.

Source

pub const fn path(&self) -> Option<&Path<Sp::State>>

The solution, or None if the trees have not met yet.

Source

pub fn node_count(&self) -> usize

The number of nodes in both trees, including both roots.

Trait Implementations§

Source§

impl<Sp: Clone + StateSpace, Sa: Clone, C: Clone, St: Clone, N: Clone> Clone for RrtConnect<Sp, Sa, C, St, N>
where Sp::State: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<Sp, Sa, C, St, N> Forget for RrtConnect<Sp, Sa, C, St, N>

§

impl<Sp, Sa, C, St, N> Freeze for RrtConnect<Sp, Sa, C, St, N>
where Problem<Sp, Sa, C, St>: Freeze, Half<<Sp as StateSpace>::State, N>: Freeze, Option<Path<<Sp as StateSpace>::State>>: Freeze,

§

impl<Sp, Sa, C, St, N> Move for RrtConnect<Sp, Sa, C, St, N>

§

impl<Sp, Sa, C, St, N> RefUnwindSafe for RrtConnect<Sp, Sa, C, St, N>
where Problem<Sp, Sa, C, St>: RefUnwindSafe, Half<<Sp as StateSpace>::State, N>: RefUnwindSafe, Option<Path<<Sp as StateSpace>::State>>: RefUnwindSafe,

§

impl<Sp, Sa, C, St, N> Send for RrtConnect<Sp, Sa, C, St, N>
where Problem<Sp, Sa, C, St>: Send, Half<<Sp as StateSpace>::State, N>: Send, Option<Path<<Sp as StateSpace>::State>>: Send,

§

impl<Sp, Sa, C, St, N> Sync for RrtConnect<Sp, Sa, C, St, N>
where Problem<Sp, Sa, C, St>: Sync, Half<<Sp as StateSpace>::State, N>: Sync, Option<Path<<Sp as StateSpace>::State>>: Sync,

§

impl<Sp, Sa, C, St, N> Unpin for RrtConnect<Sp, Sa, C, St, N>
where Problem<Sp, Sa, C, St>: Unpin, Half<<Sp as StateSpace>::State, N>: Unpin, Option<Path<<Sp as StateSpace>::State>>: Unpin,

§

impl<Sp, Sa, C, St, N> UnsafeUnpin for RrtConnect<Sp, Sa, C, St, N>
where Problem<Sp, Sa, C, St>: UnsafeUnpin, Half<<Sp as StateSpace>::State, N>: UnsafeUnpin, Option<Path<<Sp as StateSpace>::State>>: UnsafeUnpin,

§

impl<Sp, Sa, C, St, N> UnwindSafe for RrtConnect<Sp, Sa, C, St, N>
where Problem<Sp, Sa, C, St>: UnwindSafe, Half<<Sp as StateSpace>::State, N>: UnwindSafe, Option<Path<<Sp as StateSpace>::State>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.