mount_ctrl_sampling8000_damping0005/controller/
mod.rs1pub mod ze30;
2
3pub enum Controller<'a> {
4 Ze30(ze30::Controller<'a>),
5 Default(ze30::Controller<'a>),
6}
7
8#[derive(Debug, thiserror::Error)]
9pub enum ControlError {
10 #[error("Expected zenith angle 30 found {0}")]
11 ZenithAngle(i32),
12}
13
14type Result<T> = std::result::Result<T, ControlError>;
15
16impl<'a> Controller<'a> {
17 pub fn new() -> Self {
19 Controller::Default(ze30::Controller::new())
20 }
21 pub fn at_zenith_angle(ze: i32) -> Result<Self> {
25 match ze {
26 ze if ze == 30 => Ok(Self::Ze30(ze30::Controller::new())),
27 _ => Err(ControlError::ZenithAngle(ze)),
28 }
29 }
30 pub fn at_elevation(el: i32) -> Result<Self> {
34 Self::at_zenith_angle(90 - el)
35 }
36 pub fn mount_fb(&mut self) -> Option<&mut [f64; 14]> {
37 match self {
38 Controller::Ze30(controller) => {
39 if let ze30::U::MountFB(val) = &mut controller.mount_fb {
40 Some(val)
41 } else {
42 None
43 }
44 }
45
46 Controller::Default(controller) => {
47 if let ze30::U::MountFB(val) = &mut controller.mount_fb {
48 Some(val)
49 } else {
50 None
51 }
52 }
53 }
54 }
55 pub fn mount_sp(&mut self) -> Option<&mut [f64; 3]> {
56 match self {
57 Controller::Ze30(controller) => {
58 if let ze30::U::MountSP(val) = &mut controller.mount_sp {
59 Some(val)
60 } else {
61 None
62 }
63 }
64
65 Controller::Default(controller) => {
66 if let ze30::U::MountSP(val) = &mut controller.mount_sp {
67 Some(val)
68 } else {
69 None
70 }
71 }
72 }
73 }
74 pub fn mount_cmd(&mut self) -> Option<&[f64; 3]> {
75 match self {
76 Controller::Ze30(controller) => {
77 let ze30::Y::Mountcmd(val) = &controller.mount_cmd;
78 Some(val)
79 }
80
81 Controller::Default(controller) => {
82 let ze30::Y::Mountcmd(val) = &controller.mount_cmd;
83 Some(val)
84 }
85 }
86 }
87}
88
89impl<'a> Iterator for Controller<'a> {
90 type Item = ();
91
92 fn next(&mut self) -> Option<Self::Item> {
93 match self {
94 Controller::Ze30(control) => control.next(),
95 Controller::Default(control) => control.next(),
96 }
97 }
98}