Skip to main content

stable_flight/guidance/plane/
params.rs

1//! [`PlaneGuidanceConfig`]'s params; the names and units are tabled in [`crate::params`].
2
3use super::PlaneGuidanceConfig;
4use crate::params::{Param, ParamTable, param};
5
6impl ParamTable for PlaneGuidanceConfig {
7    const PARAMS: &'static [Param<Self>] = &[
8        param!(deg "PGUID_BANK_MAX", max_bank_rad),
9        param!(deg "PGUID_PIT_UP", max_pitch_up_rad),
10        param!(deg "PGUID_PIT_DN", max_pitch_down_rad),
11        param!(deg "PGUID_ACRO_X", max_rate_radps.x),
12        param!(deg "PGUID_ACRO_Y", max_rate_radps.y),
13        param!(deg "PGUID_ACRO_Z", max_rate_radps.z),
14        param!(deg "PGUID_TRIM_PIT", trim_pitch_rad),
15        param!("PGUID_CRUISE", cruise_thrust),
16        param!("PGUID_L1_PERIOD", l1_period_s),
17        param!("PGUID_L1_DAMP", l1_damping),
18        param!("PGUID_LOIT_RAD", loiter_radius_m),
19        param!("PGUID_ALT_P", altitude_p),
20        param!("PGUID_ALT_I", altitude_i),
21        param!("PGUID_ALT_IMAX", altitude_max_integral),
22        param!("PGUID_TCONST", tecs.time_constant_s),
23        param!("PGUID_CLMB_MAX", tecs.max_climb_mps),
24        param!("PGUID_SINK_MIN", tecs.min_sink_mps),
25        param!("PGUID_SINK_MAX", tecs.max_sink_mps),
26        param!("PGUID_THR_DAMP", tecs.thrust_damping),
27        param!("PGUID_INTEG", tecs.integrator_gain),
28        param!("PGUID_PTCH_DAMP", tecs.pitch_damping),
29        param!("PGUID_PTCH_INTEG", tecs.pitch_integrator_gain),
30        param!("PGUID_SPDWEIGHT", tecs.speed_weight),
31        param!("PGUID_RLL2THR", tecs.roll_compensation),
32        param!("PGUID_ASPD_MIN", tecs.min_airspeed_mps),
33        param!("PGUID_ASPD_MAX", tecs.max_airspeed_mps),
34        param!("PGUID_THR_MIN", min_thrust),
35        param!("PGUID_THR_MAX", max_thrust),
36        param!("PGUID_CLMB_THR", climb_thrust_per_rad),
37    ];
38}
39
40#[cfg(feature = "param-metadata")]
41mod metadata {
42    use super::PlaneGuidanceConfig;
43    use crate::params::metadata::{ParamMeta, ParamMetadata};
44
45    const STICKS: ParamMeta = ParamMeta::in_group("Plane Guidance", "Sticks");
46    const CRUISE: ParamMeta = ParamMeta::in_group("Plane Guidance", "Cruise");
47    const NAVIGATION: ParamMeta = ParamMeta::in_group("Plane Guidance", "Navigation");
48    const TECS: ParamMeta = ParamMeta::in_group("Plane Guidance", "Total energy control");
49
50    /// A non-negative gain or limit.
51    const fn at_least_zero(meta: ParamMeta) -> ParamMeta {
52        meta.at_least(0.0)
53    }
54
55    impl ParamMetadata for PlaneGuidanceConfig {
56        const METADATA: &'static [ParamMeta] = &[
57            STICKS
58                .param("PGUID_BANK_MAX", "Bank at full roll stick")
59                .with_units("deg")
60                .at_least(0.0)
61                .at_most(90.0),
62            STICKS
63                .param("PGUID_PIT_UP", "Pitch up at full back stick")
64                .with_units("deg")
65                .at_least(0.0)
66                .at_most(90.0),
67            STICKS
68                .param("PGUID_PIT_DN", "Pitch down at full forward stick")
69                .with_units("deg")
70                .at_least(0.0)
71                .at_most(90.0),
72            STICKS
73                .param("PGUID_ACRO_X", "Roll rate at full stick in rate mode")
74                .with_units("deg/s")
75                .at_least(0.0),
76            STICKS
77                .param("PGUID_ACRO_Y", "Pitch rate at full stick in rate mode")
78                .with_units("deg/s")
79                .at_least(0.0),
80            STICKS
81                .param("PGUID_ACRO_Z", "Yaw rate at full stick in rate mode")
82                .with_units("deg/s")
83                .at_least(0.0),
84            CRUISE
85                .param("PGUID_TRIM_PIT", "Pitch for wings-level cruise")
86                .with_units("deg")
87                .at_least(-90.0)
88                .at_most(90.0),
89            CRUISE
90                .param(
91                    "PGUID_CRUISE",
92                    "Throttle for level cruise at the trim airspeed",
93                )
94                .at_least(0.0)
95                .at_most(1.0),
96            NAVIGATION
97                .param(
98                    "PGUID_L1_PERIOD",
99                    "L1 period: shorter captures the path tighter",
100                )
101                .with_units("s")
102                .above(0.0),
103            NAVIGATION
104                .param("PGUID_L1_DAMP", "L1 damping ratio")
105                .above(0.0),
106            NAVIGATION
107                .param(
108                    "PGUID_LOIT_RAD",
109                    "Loiter radius around a waypoint with no leg",
110                )
111                .with_units("m")
112                .above(0.0),
113            at_least_zero(
114                NAVIGATION
115                    .param(
116                        "PGUID_ALT_P",
117                        "Without airspeed: pitch per meter of altitude error",
118                    )
119                    .with_units("rad/m"),
120            ),
121            at_least_zero(NAVIGATION.param(
122                "PGUID_ALT_I",
123                "Without airspeed: altitude loop integral gain",
124            )),
125            at_least_zero(
126                NAVIGATION
127                    .param(
128                        "PGUID_ALT_IMAX",
129                        "Without airspeed: altitude loop integral limit",
130                    )
131                    .with_units("m*s"),
132            ),
133            TECS.param(
134                "PGUID_TCONST",
135                "Time constant height and airspeed errors close in",
136            )
137            .with_units("s")
138            .above(0.0),
139            TECS.param(
140                "PGUID_CLMB_MAX",
141                "Climb rate at full throttle and trim airspeed",
142            )
143            .with_units("m/s")
144            .above(0.0),
145            TECS.param(
146                "PGUID_SINK_MIN",
147                "Sink rate at least throttle and trim airspeed",
148            )
149            .with_units("m/s")
150            .above(0.0),
151            at_least_zero(
152                TECS.param("PGUID_SINK_MAX", "Most sink rate the height demand asks")
153                    .with_units("m/s"),
154            ),
155            at_least_zero(TECS.param(
156                "PGUID_THR_DAMP",
157                "Throttle damping on the total energy rate",
158            )),
159            at_least_zero(TECS.param("PGUID_INTEG", "Integrator gain of the throttle loop")),
160            at_least_zero(TECS.param(
161                "PGUID_PTCH_DAMP",
162                "Pitch damping on the energy balance rate",
163            )),
164            at_least_zero(TECS.param("PGUID_PTCH_INTEG", "Integrator gain of the pitch loop")),
165            TECS.param(
166                "PGUID_SPDWEIGHT",
167                "Pitch weight on airspeed vs height: 0 height, 1 both, 2 airspeed",
168            )
169            .at_least(0.0)
170            .at_most(2.0),
171            at_least_zero(
172                TECS.param("PGUID_RLL2THR", "Energy rate added for a bank's drag")
173                    .with_units("m^2/s^3"),
174            ),
175            TECS.param(
176                "PGUID_ASPD_MIN",
177                "Least airspeed demanded; underspeed below",
178            )
179            .with_units("m/s")
180            .above(0.0),
181            TECS.param("PGUID_ASPD_MAX", "Most airspeed demanded")
182                .with_units("m/s")
183                .above(0.0),
184            NAVIGATION
185                .param("PGUID_THR_MIN", "Least thrust in waypoint flight")
186                .at_least(0.0)
187                .at_most(1.0),
188            NAVIGATION
189                .param("PGUID_THR_MAX", "Most thrust in waypoint flight")
190                .at_least(0.0)
191                .at_most(1.0),
192            at_least_zero(NAVIGATION.param(
193                "PGUID_CLMB_THR",
194                "Without airspeed: thrust added per radian of climb pitch",
195            )),
196        ];
197    }
198}