arci/clients/
dummy_move_base.rs1use std::sync::Mutex;
2
3use crate::{
4 error::Error,
5 traits::{BaseVelocity, MoveBase},
6};
7
8#[derive(Debug, Default)]
10pub struct DummyMoveBase {
11 pub current_velocity: Mutex<BaseVelocity>,
12}
13
14impl DummyMoveBase {
15 pub fn new() -> Self {
17 Self {
18 current_velocity: Mutex::new(BaseVelocity::default()),
19 }
20 }
21}
22
23impl MoveBase for DummyMoveBase {
24 fn send_velocity(&self, velocity: &BaseVelocity) -> Result<(), Error> {
25 *self.current_velocity.lock().unwrap() = *velocity;
26 Ok(())
27 }
28
29 fn current_velocity(&self) -> Result<BaseVelocity, Error> {
30 Ok(self.current_velocity.lock().unwrap().to_owned())
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use assert_approx_eq::assert_approx_eq;
37
38 use super::*;
39 #[test]
40 fn test_set_get() {
41 let base = DummyMoveBase::new();
42 let vel = base.current_velocity().unwrap();
43 assert_approx_eq!(vel.x, 0.0);
44 assert_approx_eq!(vel.y, 0.0);
45 assert_approx_eq!(vel.theta, 0.0);
46 base.send_velocity(&BaseVelocity::new(0.1, 0.2, -3.0))
47 .unwrap();
48 let vel2 = base.current_velocity().unwrap();
49 assert_approx_eq!(vel2.x, 0.1);
50 assert_approx_eq!(vel2.y, 0.2);
51 assert_approx_eq!(vel2.theta, -3.0);
52 }
53}