rust_robotics_core/
traits.rs1use crate::error::RoboticsError;
4use crate::types::*;
5
6pub trait PathPlanner {
8 fn plan(&self, start: Point2D, goal: Point2D) -> Result<Path2D, RoboticsError>;
10}
11
12pub trait GridPathPlanner {
14 fn plan(&self, start: GridNode, goal: GridNode) -> Result<Path2D, RoboticsError>;
16
17 fn set_obstacles(&mut self, obstacles: &Obstacles);
19}
20
21pub trait SamplingBasedPlanner: PathPlanner {
23 fn get_tree(&self) -> &[(Point2D, Option<usize>)];
25
26 fn set_max_iterations(&mut self, max_iter: usize);
28}
29
30pub trait StateEstimator {
32 type State;
34 type Measurement;
36 type Control;
38
39 fn predict(&mut self, control: &Self::Control, dt: f64);
41
42 fn update(&mut self, measurement: &Self::Measurement);
44
45 fn get_state(&self) -> &Self::State;
47
48 fn get_covariance(&self) -> Option<&nalgebra::DMatrix<f64>> {
50 None
51 }
52}
53
54pub trait Estimator2D {
56 fn predict(&mut self, control: &ControlInput, dt: f64);
58
59 fn update(&mut self, measurement: Point2D);
61
62 fn get_state(&self) -> State2D;
64}
65
66pub trait PathTracker {
68 fn compute_control(&mut self, current_state: &State2D, path: &Path2D) -> ControlInput;
70
71 fn is_goal_reached(&self, current_state: &State2D, goal: Point2D) -> bool;
73}
74
75pub trait TrajectoryTracker {
77 type TrajectoryPoint;
79
80 fn compute_control(&mut self, current_state: &State2D, time: f64) -> ControlInput;
82}
83
84pub trait MotionModel {
86 type State;
88 type Control;
90
91 fn propagate(&self, state: &Self::State, control: &Self::Control, dt: f64) -> Self::State;
93
94 fn jacobian_state(
96 &self,
97 state: &Self::State,
98 control: &Self::Control,
99 dt: f64,
100 ) -> nalgebra::DMatrix<f64>;
101}
102
103pub trait ObservationModel {
105 type State;
107 type Measurement;
109
110 fn predict(&self, state: &Self::State) -> Self::Measurement;
112
113 fn jacobian(&self, state: &Self::State) -> nalgebra::DMatrix<f64>;
115}
116
117pub trait Controller {
119 type State;
121 type Reference;
123 type Output;
125
126 fn compute(&mut self, state: &Self::State, reference: &Self::Reference) -> Self::Output;
128
129 fn reset(&mut self);
131}
132
133#[cfg(test)]
134mod tests {
135 use super::*;
136
137 struct DummyPlanner;
139
140 impl PathPlanner for DummyPlanner {
141 fn plan(&self, _start: Point2D, _goal: Point2D) -> Result<Path2D, RoboticsError> {
142 Ok(Path2D::new())
143 }
144 }
145
146 #[test]
147 fn test_path_planner_trait() {
148 let planner = DummyPlanner;
149 let result = planner.plan(Point2D::origin(), Point2D::new(1.0, 1.0));
150 assert!(result.is_ok());
151 }
152}