gmt_m1_ctrl_hardpoints_dynamics/
lib.rs

1//! # M1 hardpoints controller
2//!
3//! The control system implements the transfer function that models
4//! the hardpoints dynamic behavior.
5//!
6//! This is imported from a Simulink model converted into C code.
7
8#![allow(non_upper_case_globals)]
9#![allow(non_camel_case_types)]
10#![allow(non_snake_case)]
11#![allow(improper_ctypes)]
12
13include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
14
15include!(concat!(env!("OUT_DIR"), "/controller.rs"));
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20    use matio_rs::MatFile;
21    #[test]
22    fn step() {
23        let mat = MatFile::load("../simulink-models/hp_dyn_step_test.mat").unwrap();
24        let hp_dyn_step_t: Vec<f64> = mat.var("hp_dyn_step_t").unwrap();
25        let hp_dyn_step_y: Vec<f64> = mat.var("hp_dyn_step_y").unwrap();
26
27        let mut ctrl = HardpointsDynamics::new();
28        ctrl.inputs.In1.iter_mut().for_each(|x| *x = 1f64);
29        let mut y = vec![];
30        for _ in &hp_dyn_step_t {
31            ctrl.step();
32            y.extend_from_slice(ctrl.outputs.Out1.as_slice());
33        }
34
35        // dbg!(&y[y.len() - 6..]);
36
37        let y_err = (y
38            .chunks(6)
39            .take(6 * 5)
40            .zip(&hp_dyn_step_y)
41            .map(|(y, y0)| y.iter().map(|y| *y - *y0).map(|x| x * x).sum::<f64>())
42            .sum::<f64>()
43            / y.len() as f64)
44            .sqrt();
45        dbg!(y_err);
46    }
47}