1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
use dosio::{
io::{jar, Tags},
DOSIOSError, Dos, IOTags, IO,
};
use simulink_rs::*;
import_simulink!(Mount_Drv_PDR2021, U : (Mount_cmd,3,Mount_pos,14), Y : (Mount_F,20));
build_inputs!(
MountCmd,
3,
0,
OssAzDrive,
14,
0,
OssElDrive,
14,
6,
OssGirDrive,
14,
10
);
build_outputs!(
OssAzDrive,
20,
12,
0,
OssElDrive,
20,
4,
12,
OssGirDrive,
20,
4,
16
);
build_controller!(Mount_Drv_PDR2021,
U : (Mount_cmd -> (MountCmd,cmd) ,
Mount_pos -> (OssAzDrive,oss_az_drive_d),
Mount_pos -> (OssElDrive,oss_el_drive_d),
Mount_pos -> (OssGirDrive,oss_gir_drive_d)),
Y : (Mount_F -> (OssAzDrive,oss_az_drive_f),
Mount_F -> (OssElDrive,oss_el_drive_f),
Mount_F -> (OssGirDrive,oss_gir_drive_f))
);
impl<'a> IOTags for Controller<'a> {
fn outputs_tags(&self) -> Vec<Tags> {
vec![
jar::OSSAzDriveTorque::io(),
jar::OSSElDriveTorque::io(),
jar::OSSRotDriveTorque::io(),
]
}
fn inputs_tags(&self) -> Vec<Tags> {
vec![
jar::MountCmd::io(),
jar::OSSAzEncoderAngle::io(),
jar::OSSElEncoderAngle::io(),
jar::OSSRotEncoderAngle::io(),
]
}
}
impl<'a> Dos for Controller<'a> {
type Input = Vec<f64>;
type Output = Vec<f64>;
fn inputs(&mut self, data: Option<Vec<IO<Self::Input>>>) -> Result<&mut Self, DOSIOSError> {
match data {
Some(data) => {
if data.into_iter().fold(4, |mut a, io| {
match io {
IO::MountCmd { data: Some(values) } => {
for (k, v) in values.into_iter().enumerate() {
self.cmd[k] = v;
}
a -= 1;
}
IO::OSSAzEncoderAngle { data: Some(values) } => {
for (k, v) in values.into_iter().enumerate() {
self.oss_az_drive_d[k] = v;
}
a -= 1;
}
IO::OSSElEncoderAngle { data: Some(values) } => {
for (k, v) in values.into_iter().enumerate() {
self.oss_el_drive_d[k] = v;
}
a -= 1;
}
IO::OSSRotEncoderAngle { data: Some(values) } => {
for (k, v) in values.into_iter().enumerate() {
self.oss_gir_drive_d[k] = v;
}
a -= 1;
}
_ => (),
}
if a == 0 {
return a;
}
a
}) == 0
{
Ok(self)
} else {
Err(DOSIOSError::Inputs("Either mount drive controller MountCmd, OSSAzEncoderAngle, OSSElEncoderAngle or OSSRotEncoderAngle not found".into()))
}
}
None => Err(DOSIOSError::Inputs(
"None data passed to mount drive".into(),
)),
}
}
fn outputs(&mut self) -> Option<Vec<IO<Self::Output>>> {
Some(vec![
IO::OSSAzDriveTorque {
data: Some(Vec::<f64>::from(&self.oss_az_drive_f)),
},
IO::OSSElDriveTorque {
data: Some(Vec::<f64>::from(&self.oss_el_drive_f)),
},
IO::OSSRotDriveTorque {
data: Some(Vec::<f64>::from(&self.oss_gir_drive_f)),
},
])
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn pdr_mount_drive_zeros() {
let mut mnt_drives = Controller::new();
for _ in 0..5 {
let u = vec![
jar::MountCmd::io_with(vec![0f64; 3]),
jar::OSSAzEncoderAngle::io_with(vec![0f64; 6]),
jar::OSSElEncoderAngle::io_with(vec![0f64; 4]),
jar::OSSRotEncoderAngle::io_with(vec![0f64; 4]),
];
let y = mnt_drives.in_step_out(Some(u)).unwrap();
println!("PDR MOUNT DRIVE ZEROS TEST: {:#?}", y);
}
}
#[test]
fn pdr_mount_drive_ones() {
let mut mnt_drives = Controller::new();
for _ in 0..5 {
let u = vec![
jar::MountCmd::io_with(vec![1f64; 3]),
jar::OSSAzEncoderAngle::io_with(vec![1f64; 6]),
jar::OSSElEncoderAngle::io_with(vec![1f64; 4]),
jar::OSSRotEncoderAngle::io_with(vec![1f64; 4]),
];
let y = mnt_drives.in_step_out(Some(u)).unwrap();
println!("PDR MOUNT DRIVE ONES TEST: {:#?}", y);
}
}
}