path_planning/obstacles/
mod.rs1mod params;
5
6pub mod obstacles_2d_f32;
8pub mod obstacles_2d_f64;
10pub mod obstacles_3d_f32;
12pub mod obstacles_3d_f64;
14
15use nalgebra::storage::Storage;
18use nalgebra::{Const, Vector};
19use serde::{Deserialize, Serialize};
20
21use crate::cspace::CSpace;
22use crate::params::FromParams;
23use crate::trajectories::FullTrajectory;
24
25pub type ObstacleId = usize;
27
28#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
30pub enum Behavior {
31 Static,
32 Appearing,
33}
34
35impl Default for Behavior {
36 fn default() -> Behavior {
37 Behavior::Static
38 }
39}
40
41pub trait ObstacleSpace<X, CS, const N: usize>:
43 FromParams + Clone + Obstacle<X, CS, N>
44where
45 CS: CSpace<X, N>,
46{
47 type Obs: AppearingObstacle<X, CS, N>;
49
50 fn empty() -> Self;
52
53 fn new(obstacles: Vec<Self::Obs>) -> Self {
55 let mut new_ = Self::empty();
56 new_.add_obstacles(obstacles.into_iter().enumerate());
57 new_
58 }
59
60 fn add_obstacle(&mut self, id: ObstacleId, obstacle: Self::Obs) {
64 self.add_obstacles(vec![(id, obstacle)])
65 }
66
67 fn add_obstacles<I>(&mut self, obstacles: I)
71 where
72 I: IntoIterator<Item = (ObstacleId, Self::Obs)>;
73
74 fn get_obstacle(&self, id: ObstacleId) -> Option<&Self::Obs> {
76 self.get_obstacles(&[id; 1]).into_iter().next()
77 }
78
79 fn get_obstacles(&self, obstacles: &[ObstacleId]) -> Vec<&Self::Obs>;
83
84 fn get_obstacles_as_obstacle_space(&self, obstacles: &[ObstacleId]) -> Self {
86 Self::new(self.get_obstacles(obstacles).into_iter().cloned().collect())
87 }
88
89 fn get_sensed_obstacles(&self) -> Vec<(ObstacleId, &Self::Obs)>;
91
92 fn get_not_sensed_obstacles(&self) -> Vec<(ObstacleId, &Self::Obs)>;
94
95 fn get_all_obstacle_ids(&self) -> Vec<ObstacleId>;
97
98 fn get_all_obstacles(&self) -> Vec<(ObstacleId, &Self::Obs)> {
100 self
101 .get_all_obstacle_ids()
102 .into_iter()
103 .filter_map(|obs_id| self.get_obstacle(obs_id).map(|obs| (obs_id, obs)))
104 .collect()
105 }
106
107 fn remove_obstacle(&mut self, id: ObstacleId) {
109 self.remove_obstacles(&[id; 1])
110 }
111
112 fn remove_obstacles(&mut self, obstacles: &[ObstacleId]);
114
115 fn count(&self) -> usize;
117
118 fn check_sensors<S>(
122 &mut self,
123 pose: &Vector<X, Const<N>, S>,
124 radius: X,
125 ) -> Vec<ObstacleId>
126 where
127 S: Storage<X, Const<N>>;
128}
129
130pub trait Obstacle<X, CS, const N: usize>: FromParams + Clone
132where
133 CS: CSpace<X, N>,
134{
135 fn trajectory_free<FT, S1, S2>(&self, t: &FT) -> bool
137 where
138 FT: FullTrajectory<X, CS::Traj, S1, S2, N>,
139 S1: Storage<X, Const<N>>,
140 S2: Storage<X, Const<N>>;
141
142 fn is_free<S>(&self, x: &Vector<X, Const<N>, S>) -> bool
144 where
145 S: Storage<X, Const<N>>;
146}
147
148pub trait AppearingObstacle<X, CS, const N: usize>: Obstacle<X, CS, N>
150where
151 CS: CSpace<X, N>,
152{
153 fn can_sense<S>(&self, pose: &Vector<X, Const<N>, S>, radius: X) -> bool
155 where
156 S: Storage<X, Const<N>>;
157}