m1_ctrl/lib.rs
1//use dosio::{ios, DOSIOSError, Dos, IOTags, IOVec, IO};
2pub mod actuators;
3pub mod cg_controller;
4pub mod hp_dynamics;
5pub mod hp_load_cells;
6pub mod local_controller;
7
8/*
9pub struct MacroController<'a> {
10 hardpoints_load_cells: hp_load_cells::Controller<'a>,
11 hardpoints_dynamics: hp_dynamics::Controller<'a>,
12 actuators_force_loops: actuators::M1ForceLoops<'a>,
13}
14
15impl<'a> IOTags for MacroController<'a> {
16 fn outputs_tags(&self) -> Vec<IO<()>> {
17 let mut tags = self.actuators_force_loops.outputs_tags();
18 tags.push(ios!(HPFcmd));
19 tags
20 }
21
22 fn inputs_tags(&self) -> Vec<IO<()>> {
23 ios!(M1RBMcmd, M1S1BMcmd, M1S2BMcmd, M1S3BMcmd, M1S4BMcmd, M1S5BMcmd, M1S6BMcmd, M1S7BMcmd)
24 }
25}
26impl<'a> Iterator for MacroController<'a> {
27 type Item = ();
28
29 fn next(&mut self) -> Option<Self::Item> {
30 self.hardpoints_load_cells
31 .step()
32 .ok()
33 .and(self.hardpoints_dynamics.step().ok())
34 .and(self.actuators_force_loops.step().ok())
35 .and(Some(()))
36 }
37}
38impl<'a> Dos for MacroController<'a> {
39 type Input = Vec<f64>;
40 type Output = Vec<f64>;
41
42 fn outputs(&mut self) -> Option<Vec<IO<Self::Output>>> {
43 Some(
44 Some(
45 self.hardpoints_load_cells
46 .outputs()
47 .into_iter()
48 .chain(self.hardpoints_dynamics.outputs().into_iter())
49 .flatten()
50 .collect::<Vec<IO<Vec<f64>>>>(),
51 )
52 .into_iter()
53 .chain(self.actuators_force_loops.outputs().into_iter())
54 .flatten()
55 .collect(),
56 )
57 }
58
59 fn inputs(
60 &mut self,
61 data: Option<Vec<IO<Self::Input>>>,
62 ) -> Result<&mut Self, dosio::DOSIOSError> {
63 if let Some(mut data) = data {
64 self.hardpoints_load_cells
65 .inputs(<Vec<IO<Vec<f64>>> as IOVec>::pop_these(
66 &mut data,
67 ios!(OSSHardpointD, M1HPCmd),
68 ))?;
69 self.hardpoints_dynamics
70 .inputs(<Vec<IO<Vec<f64>>> as IOVec>::pop_these(
71 &mut data,
72 vec![ios!(M1RBMcmd)],
73 ))?;
74 self.actuators_force_loops.inputs(Some(data))?;
75 Ok(self)
76 } else {
77 Err(DOSIOSError::Inputs(
78 "Empty inputs passed to M1 macro controller".into(),
79 ))
80 }
81 }
82}
83*/