Skip to main content

Kpiece

Struct Kpiece 

Source
pub struct Kpiece<Sp, Sa, C, P, Pr, const K: usize>
where Sp: StateSpace, P: Propagator<Sp>,
{ /* private fields */ }
Expand description

KPIECE: grows a tree of motions by forward propagation, guided by a grid over a projection of the state space (Sucan and Kavraki 2008, 2012).

Each motion’s end state falls into a grid cell. Cells with all 2K axis neighbors are interior, the others exterior, the frontier of exploration. Each iteration:

graph LR
    Select["select cell: exterior with prob. max(bias, share)"] --> Motion["pick motion, newest preferred"]
    Motion --> Propagate["random control, random steps, stop at first invalid step"]
    Propagate -->|long enough| Split["split at cell changes, add pieces"]
    Propagate --> Score["scale cell score by good or bad factor"]

Cells are ranked by importance score / ((neighbors + 1) coverage selections); a new cell starts with score (1 + ln i) / (1e-3 + goal distance). Within a cell, motions are picked from a half-normal distribution centered on the newest one. This follows OMPL’s control::KPIECE1 with a single grid level, which also expands from the end state of the chosen motion rather than a random state along it. With probability goal_bias one of the close_samples motions closest to the goal is expanded instead.

KPIECE is probabilistically complete but not asymptotically optimal: Kpiece::solve stops at the first motion that reaches the goal region. It needs no state sampler; the problem’s sampler is not used.

§Examples

use rand_core::{Rng, SeedableRng};
use sampling_planning::{
    Euclidean, GoalRegion, UniformBox, Validity, ValidityChecker, unit_f64,
    kinodynamic::{KinodynamicProblem, Kpiece, KpieceConfig, Propagator},
};

/// 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
    }
}

/// A point that moves with a velocity of at most 1 per axis.
struct Velocity;

impl Propagator<Euclidean<2>> for Velocity {
    type Control = [f64; 2];

    fn control_dimension(&self) -> usize {
        2
    }

    fn sample_control<R: Rng + ?Sized>(&mut self, rng: &mut R) -> [f64; 2] {
        [2.0 * unit_f64(rng) - 1.0, 2.0 * unit_f64(rng) - 1.0]
    }

    fn propagate(&self, _: &Euclidean<2>, from: &[f64; 2], u: &[f64; 2], dt: f64) -> [f64; 2] {
        [from[0] + u[0] * dt, from[1] + u[1] * dt]
    }
}

let problem = KinodynamicProblem {
    space: Euclidean::<2>,
    sampler: UniformBox::new([0.0, 0.0], [10.0, 10.0]),
    checker: Free,
    propagator: Velocity,
    start: [1.0, 1.0],
    goal: GoalRegion::new([9.0, 9.0], 0.5),
};

// The identity projection with half-unit cells.
let projection = |state: &[f64; 2]| *state;
let config = KpieceConfig::new([0.5, 0.5], 0.1, 10);
let mut kpiece = Kpiece::new(problem, projection, config).expect("valid");

let trajectory = kpiece
    .solve(20_000, &mut rand_pcg::Pcg64Mcg::seed_from_u64(1))
    .expect("free space");
assert_eq!(trajectory.controls.len() + 1, trajectory.states.len());

Implementations§

Source§

impl<Sp, Sa, C, P, Pr, const K: usize> Kpiece<Sp, Sa, C, P, Pr, K>
where Sp: StateSpace, C: ValidityChecker<Sp>, P: Propagator<Sp>, Pr: Projection<Sp::State, K>,

Source

pub fn new( problem: KinodynamicProblem<Sp, Sa, C, P>, projection: Pr, config: KpieceConfig<K>, ) -> Result<Self, Error>

Creates a planner whose tree holds only the start.

§Errors
Source

pub fn solve<R: Rng + ?Sized>( &mut self, max_iterations: usize, rng: &mut R, ) -> Option<Trajectory<Sp::State, P::Control>>

Runs iterations until a motion reaches the goal region or max_iterations have run, and returns the solution, if any.

Source

pub fn step<R: Rng + ?Sized>(&mut self, rng: &mut R) -> bool

Runs one iteration. Returns whether motions were added.

Source

pub fn best_trajectory(&self) -> Option<Trajectory<Sp::State, P::Control>>

The first trajectory found into the goal region, or None if none was found yet.

Source

pub fn motion_count(&self) -> usize

The number of motions in the tree, including the start.

Source

pub fn cell_count(&self) -> usize

The number of instantiated grid cells.

Trait Implementations§

Source§

impl<Sp, Sa: Clone, C: Clone, P, Pr: Clone, const K: usize> Clone for Kpiece<Sp, Sa, C, P, Pr, K>
where Sp: StateSpace + Clone, P: Propagator<Sp> + Clone, Sp::State: Clone, P::Control: 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, P, Pr, const K: usize> Forget for Kpiece<Sp, Sa, C, P, Pr, K>

§

impl<Sp, Sa, C, P, Pr, const K: usize> Freeze for Kpiece<Sp, Sa, C, P, Pr, K>
where KinodynamicProblem<Sp, Sa, C, P>: Freeze, Pr: Freeze, KpieceConfig<K>: Freeze, Vec<Motion<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>>: Freeze, Grid<K>: Freeze,

§

impl<Sp, Sa, C, P, Pr, const K: usize> Move for Kpiece<Sp, Sa, C, P, Pr, K>

§

impl<Sp, Sa, C, P, Pr, const K: usize> RefUnwindSafe for Kpiece<Sp, Sa, C, P, Pr, K>

§

impl<Sp, Sa, C, P, Pr, const K: usize> Send for Kpiece<Sp, Sa, C, P, Pr, K>
where Pr: Send, KinodynamicProblem<Sp, Sa, C, P>: Send, KpieceConfig<K>: Send, Vec<Motion<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>>: Send, Grid<K>: Send,

§

impl<Sp, Sa, C, P, Pr, const K: usize> Sync for Kpiece<Sp, Sa, C, P, Pr, K>
where Pr: Sync, KinodynamicProblem<Sp, Sa, C, P>: Sync, KpieceConfig<K>: Sync, Vec<Motion<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>>: Sync, Grid<K>: Sync,

§

impl<Sp, Sa, C, P, Pr, const K: usize> Unpin for Kpiece<Sp, Sa, C, P, Pr, K>
where Pr: Unpin, KinodynamicProblem<Sp, Sa, C, P>: Unpin, KpieceConfig<K>: Unpin, Vec<Motion<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>>: Unpin, Grid<K>: Unpin,

§

impl<Sp, Sa, C, P, Pr, const K: usize> UnsafeUnpin for Kpiece<Sp, Sa, C, P, Pr, K>
where KinodynamicProblem<Sp, Sa, C, P>: UnsafeUnpin, Pr: UnsafeUnpin, KpieceConfig<K>: UnsafeUnpin, Vec<Motion<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>>: UnsafeUnpin, Grid<K>: UnsafeUnpin,

§

impl<Sp, Sa, C, P, Pr, const K: usize> UnwindSafe for Kpiece<Sp, Sa, C, P, Pr, K>
where KinodynamicProblem<Sp, Sa, C, P>: UnwindSafe, Pr: UnwindSafe, KpieceConfig<K>: UnwindSafe, Vec<Motion<<Sp as StateSpace>::State, <P as Propagator<Sp>>::Control>>: UnwindSafe, Grid<K>: 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.