mount_ctrl/
lib.rs

1#![allow(unused_imports)]
2
3#[cfg(feature = "s1000d002")]
4pub use sampling1000_damping002::{controller, drives};
5#[cfg(feature = "s8000d0005")]
6pub use sampling8000_damping0005::{controller, drives};
7
8pub trait DriveController {
9    fn mount_cmd(&mut self) -> Option<&mut [f64; 3]>;
10    fn mount_pos(&mut self) -> Option<&mut [f64; 14]>;
11    fn mount_t(&self) -> Option<&[f64; 20]>;
12}
13
14impl<'a> DriveController for drives::Controller<'a> {
15    fn mount_cmd(&mut self) -> Option<&mut [f64; 3]> {
16        if let drives::U::Mountcmd(val) = &mut self.mount_cmd {
17            Some(val)
18        } else {
19            None
20        }
21    }
22
23    fn mount_pos(&mut self) -> Option<&mut [f64; 14]> {
24        if let drives::U::Mountpos(val) = &mut self.mount_pos {
25            Some(val)
26        } else {
27            None
28        }
29    }
30
31    fn mount_t(&self) -> Option<&[f64; 20]> {
32        let drives::Y::MountT(val) = &self.mount_t;
33        Some(val)
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40    #[test]
41    fn controller() {
42        let mut ctrlr = controller::Controller::new();
43        assert_eq!(ctrlr.mount_fb(), Some(&mut [0f64; 14]));
44        assert_eq!(ctrlr.mount_sp(), Some(&mut [0f64; 3]));
45        assert_eq!(ctrlr.mount_cmd(), Some(&[0f64; 3]));
46    }
47    #[test]
48    fn driver() {
49        let mut drvr = drives::Controller::new();
50        assert_eq!(drvr.mount_cmd(), Some(&mut [0f64; 3]));
51        assert_eq!(drvr.mount_pos(), Some(&mut [0f64; 14]));
52        assert_eq!(drvr.mount_t(), Some(&[0f64; 20]));
53    }
54}