Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions examples/collision_avoid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use ncollide::ncollide_geometry::query::Proximity;

use rand::distributions::{IndependentSample, Range};

use rrt::Trajectory;

struct CollisionProblem {
obstacle: Cuboid<na::Vector3<f32>>,
Expand Down Expand Up @@ -99,10 +100,10 @@ fn main() {

cs.set_local_transformation(poss);
cg.set_local_transformation(posg);
let mut path = vec![];
let mut path = Trajectory{waypoints: vec![]};
let mut index = 0;
while window.render() {
if index == path.len() {
if index == path.waypoints.len() {
path = rrt::dual_rrt_connect(
&start,
&goal,
Expand All @@ -111,10 +112,10 @@ fn main() {
0.05,
1000,
).unwrap();
rrt::smooth_path(&mut path, |x: &[f64]| p.is_feasible(x), 0.05, 100);
rrt::smooth_path(&mut path.waypoints, |x: &[f64]| p.is_feasible(x), 0.05, 100);
index = 0;
}
let point = &path[index % path.len()];
let point = &path.waypoints[index % path.waypoints.len()];
let pos = Isometry3::new(
Vector3::new(point[0] as f32, point[1] as f32, point[2] as f32),
na::zero(),
Expand Down
22 changes: 13 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
//! 0.2,
//! 1000)
//! .unwrap();
//! println!("{:?}", result);
//! assert!(result.len() >= 4);
//! println!("{:?}", result.waypoints);
//! assert!(result.waypoints.len() >= 4);
//! }
//! ```
extern crate kdtree;
Expand All @@ -52,6 +52,10 @@ use kdtree::distance::squared_euclidean;
use std::mem;
use rand::distributions::{IndependentSample, Range};

pub struct Trajectory {
pub waypoints: Vec<Vec<f64>>,
}

pub enum ExtendStatus {
Reached(usize),
Advanced(usize),
Expand Down Expand Up @@ -180,7 +184,7 @@ pub fn dual_rrt_connect<FF, FR>(
random_sample: FR,
extend_length: f64,
num_max_try: usize,
) -> Result<Vec<Vec<f64>>, String>
) -> Result<Trajectory, String>
where
FF: FnMut(&[f64]) -> bool,
FR: Fn() -> Vec<f64>,
Expand Down Expand Up @@ -209,7 +213,7 @@ where
if tree_b.name == "start" {
a_all.reverse();
}
return Ok(a_all);
return Ok(Trajectory{waypoints: a_all});
}
}
}
Expand Down Expand Up @@ -288,14 +292,14 @@ fn it_works() {
0.2,
1000,
).unwrap();
println!("{:?}", result);
assert!(result.len() >= 4);
println!("{:?}", result.waypoints);
assert!(result.waypoints.len() >= 4);
smooth_path(
&mut result,
&mut result.waypoints,
|p: &[f64]| !(p[0].abs() < 1.0 && p[1].abs() < 1.0),
0.2,
100,
);
println!("{:?}", result);
assert!(result.len() >= 3);
println!("{:?}", result.waypoints);
assert!(result.waypoints.len() >= 3);
}