gmt_mount_ctrl/
lib.rs

1#![allow(unused_imports)]
2
3#[cfg(feature = "sampling1000-damping002")]
4pub use sampling1000_damping002::{controller, drives};
5#[cfg(feature = "s8000d0005")]
6pub use sampling8000_damping0005::{controller, drives};
7#[cfg(feature = "sampling8000-damping002")]
8pub use sampling8000_damping002::{controller, drives};
9
10pub trait DriveController {
11    fn mount_cmd(&mut self) -> Option<&mut [f64; 3]>;
12    fn mount_pos(&mut self) -> Option<&mut [f64; 14]>;
13    fn mount_t(&self) -> Option<&[f64; 20]>;
14}
15
16impl<'a> DriveController for drives::Controller<'a> {
17    fn mount_cmd(&mut self) -> Option<&mut [f64; 3]> {
18        if let drives::U::Mountcmd(val) = &mut self.mount_cmd {
19            Some(val)
20        } else {
21            None
22        }
23    }
24
25    fn mount_pos(&mut self) -> Option<&mut [f64; 14]> {
26        if let drives::U::Mountpos(val) = &mut self.mount_pos {
27            Some(val)
28        } else {
29            None
30        }
31    }
32
33    fn mount_t(&self) -> Option<&[f64; 20]> {
34        let drives::Y::MountT(val) = &self.mount_t;
35        Some(val)
36    }
37}
38
39pub trait ControllerController {
40    fn mount_fb(&mut self) -> Option<&mut [f64; 14]>;
41    fn mount_sp(&mut self) -> Option<&mut [f64; 3]>;
42    fn mount_cmd(&mut self) -> Option<&[f64; 3]>;
43}
44impl<'a> ControllerController for controller::Controller<'a> {
45    fn mount_fb(&mut self) -> Option<&mut [f64; 14]> {
46        if let controller::U::MountFB(val) = &mut self.mount_fb {
47            Some(val)
48        } else {
49            None
50        }
51    }
52
53    fn mount_sp(&mut self) -> Option<&mut [f64; 3]> {
54        if let controller::U::MountSP(val) = &mut self.mount_sp {
55            Some(val)
56        } else {
57            None
58        }
59    }
60
61    fn mount_cmd(&mut self) -> Option<&[f64; 3]> {
62        let controller::Y::Mountcmd(val) = &self.mount_cmd;
63        Some(val)
64    }
65}
66
67#[cfg(test)]
68mod tests {
69    use super::*;
70    #[test]
71    fn controller() {
72        let mut ctrlr = controller::Controller::new();
73        assert_eq!(ctrlr.mount_fb(), Some(&mut [0f64; 14]));
74        assert_eq!(ctrlr.mount_sp(), Some(&mut [0f64; 3]));
75        assert_eq!(ctrlr.mount_cmd(), Some(&[0f64; 3]));
76    }
77    #[test]
78    fn driver() {
79        let mut drvr = drives::Controller::new();
80        assert_eq!(drvr.mount_cmd(), Some(&mut [0f64; 3]));
81        assert_eq!(drvr.mount_pos(), Some(&mut [0f64; 14]));
82        assert_eq!(drvr.mount_t(), Some(&[0f64; 20]));
83    }
84}