Skip to main content

stable_flight/guidance/copter/
params.rs

1//! [`CopterGuidanceConfig`]'s params; the names and units are tabled in [`crate::params`].
2
3use super::CopterGuidanceConfig;
4use crate::params::{Param, ParamTable, param};
5
6impl ParamTable for CopterGuidanceConfig {
7    const PARAMS: &'static [Param<Self>] = &[
8        param!("GUID_ALT_P", altitude.gains.p),
9        param!("GUID_ALT_I", altitude.gains.i),
10        param!("GUID_ALT_D", altitude.gains.d),
11        param!("GUID_ALT_IMAX", altitude.max_integral),
12        param!("GUID_ALT_HOVER", altitude.hover_thrust),
13        param!("GUID_LAT_POS_P", lateral.position_p),
14        param!("GUID_LAT_VEL_P", lateral.velocity.p),
15        param!("GUID_LAT_VEL_I", lateral.velocity.i),
16        param!("GUID_LAT_VEL_D", lateral.velocity.d),
17        param!("GUID_LAT_IMAX", lateral.max_integral),
18        param!("GUID_LAT_ACC", lateral.max_accel_mps2),
19        param!("GUID_LAT_BRK", lateral.brake_mps2),
20        param!("GUID_NAV_PERIOD", navigation_period_s),
21        param!(deg "GUID_TILT_MAX", max_tilt_rad),
22        param!("GUID_DESC_MAX", max_descent_mps),
23        param!("GUID_DESC_ACC", descent_accel_mps2),
24        param!("GUID_CLIMB_DEC", climb_decel_mps2),
25        param!("GUID_LAND_SPD", land_speed_mps),
26        param!(deg "GUID_YAW_SLEW", waypoint_yaw_radps),
27        param!(deg "GUID_HDG_RATE", heading_rate_radps),
28        param!("GUID_YAW_MIN_LEG", waypoint_yaw_min_leg_m),
29        param!(deg "GUID_YAW_YLD_ERR", heading_yield_rad),
30        param!("GUID_YAW_YLD_S", heading_yield_s),
31        param!("GUID_WND_HDG_SPD", wind_heading_min_mps),
32        param!("GUID_THR_MIN", thrust.min_thrust),
33        param!("GUID_SINK_LIM", thrust.sink_limit_mps),
34        param!("GUID_SINK_GAIN", thrust.sink_gain),
35        param!("GUID_BOOST_MAX", thrust.max_boost_thrust),
36        param!(deg "GUID_STICK_X", max_stick_angles_rad.x),
37        param!(deg "GUID_STICK_Y", max_stick_angles_rad.y),
38        param!("GUID_WND_BCOEF_X", wind.ballistic_kgpm2.x),
39        param!("GUID_WND_BCOEF_Y", wind.ballistic_kgpm2.y),
40        param!("GUID_WND_MCOEF_X", wind.momentum_per_s.x),
41        param!("GUID_WND_MCOEF_Y", wind.momentum_per_s.y),
42        param!("GUID_WND_F_NSE", wind.force_noise_mps2),
43        param!("GUID_WND_P_NSE", wind.process_noise_mps_per_rt_s),
44    ];
45}
46
47#[cfg(feature = "param-metadata")]
48mod metadata {
49    use super::CopterGuidanceConfig;
50    use crate::commanders::touchdown::DESCENDING_MPS;
51    use crate::params::metadata::{ParamMeta, ParamMetadata};
52
53    const ALTITUDE: ParamMeta = ParamMeta::in_group("Guidance", "Altitude");
54    const LATERAL: ParamMeta = ParamMeta::in_group("Guidance", "Lateral");
55    const NAVIGATION: ParamMeta = ParamMeta::in_group("Guidance", "Navigation");
56    const LIMITS: ParamMeta = ParamMeta::in_group("Guidance", "Limits");
57    const LANDING: ParamMeta = ParamMeta::in_group("Guidance", "Landing");
58    const WIND: ParamMeta = ParamMeta::in_group("Guidance", "Wind");
59    const STICKS: ParamMeta = ParamMeta::in_group("Guidance", "Sticks");
60
61    impl ParamMetadata for CopterGuidanceConfig {
62        const METADATA: &'static [ParamMeta] = &[
63            ALTITUDE.param("GUID_ALT_P", "Altitude loop proportional gain"),
64            ALTITUDE.param("GUID_ALT_I", "Altitude loop integral gain"),
65            ALTITUDE.param("GUID_ALT_D", "Altitude loop derivative gain"),
66            ALTITUDE
67                .param("GUID_ALT_IMAX", "Altitude loop integral limit")
68                .with_units("m*s")
69                .at_least(0.0),
70            ALTITUDE
71                .param("GUID_ALT_HOVER", "Linear thrust that holds a level hover")
72                .above(0.0)
73                .at_most(1.0),
74            LATERAL
75                .param("GUID_LAT_POS_P", "Position error to velocity gain")
76                .with_units("1/s")
77                .at_least(0.0),
78            LATERAL.param("GUID_LAT_VEL_P", "Velocity loop proportional gain"),
79            LATERAL.param("GUID_LAT_VEL_I", "Velocity loop integral gain"),
80            LATERAL.param("GUID_LAT_VEL_D", "Velocity loop derivative gain"),
81            LATERAL
82                .param("GUID_LAT_IMAX", "Velocity loop integral limit, per axis")
83                .with_units("m")
84                .at_least(0.0),
85            LATERAL
86                .param(
87                    "GUID_LAT_ACC",
88                    "Most the velocity target changes per second (0: off)",
89                )
90                .with_units("m/s/s")
91                .at_least(0.0),
92            LATERAL
93                .param(
94                    "GUID_LAT_BRK",
95                    "Braking deceleration toward a waypoint with GUID_LAT_ACC 0 (0: linear)",
96                )
97                .with_units("m/s/s")
98                .at_least(0.0),
99            NAVIGATION
100                .param(
101                    "GUID_NAV_PERIOD",
102                    "Time between lateral position loop runs (0: every tick)",
103                )
104                .with_units("s")
105                .at_least(0.0),
106            LIMITS
107                .param("GUID_TILT_MAX", "Largest tilt waypoint flight requests")
108                .with_units("deg")
109                .above(0.0)
110                .below(90.0),
111            LIMITS
112                .param("GUID_DESC_MAX", "Fastest descent waypoint flight requests")
113                .with_units("m/s")
114                .above(0.0),
115            LIMITS
116                .param(
117                    "GUID_DESC_ACC",
118                    "Acceleration a descent or land starts with, and a waypoint descent stops with",
119                )
120                .with_units("m/s/s")
121                .above(0.0),
122            LIMITS
123                .param(
124                    "GUID_CLIMB_DEC",
125                    "Deceleration a descent or land started while climbing sheds the climb at",
126                )
127                .with_units("m/s/s")
128                .above(0.0),
129            LANDING
130                .param("GUID_LAND_SPD", "Descent rate while landing")
131                .with_units("m/s")
132                .above(DESCENDING_MPS),
133            NAVIGATION
134                .param(
135                    "GUID_YAW_SLEW",
136                    "Rate waypoint flight turns to face along the leg (0: holds heading)",
137                )
138                .with_units("deg/s")
139                .at_least(0.0),
140            NAVIGATION
141                .param(
142                    "GUID_HDG_RATE",
143                    "Rate waypoint flight turns to a waypoint's heading",
144                )
145                .with_units("deg/s")
146                .above(0.0),
147            NAVIGATION
148                .param(
149                    "GUID_YAW_MIN_LEG",
150                    "Shortest waypoint leg the heading turns along",
151                )
152                .with_units("m")
153                .at_least(0.0),
154            NAVIGATION
155                .param(
156                    "GUID_YAW_YLD_ERR",
157                    "Heading error past which a heading not turning is stuck",
158                )
159                .with_units("deg")
160                .at_least(0.0),
161            NAVIGATION
162                .param(
163                    "GUID_YAW_YLD_S",
164                    "Time stuck before waypoint flight yields the heading (0: never)",
165                )
166                .with_units("s")
167                .at_least(0.0),
168            NAVIGATION
169                .param(
170                    "GUID_WND_HDG_SPD",
171                    "Least wind that turns a wingtip into it while holding or landing (0: off)",
172                )
173                .with_units("m/s")
174                .at_least(0.0),
175            LIMITS
176                .param("GUID_THR_MIN", "Least thrust while flying (0: none)")
177                .at_least(0.0)
178                .below(1.0),
179            LIMITS
180                .param(
181                    "GUID_SINK_LIM",
182                    "Sink rate past which piloted flight gets more thrust (0: off)",
183                )
184                .with_units("m/s")
185                .at_least(0.0),
186            LIMITS
187                .param(
188                    "GUID_SINK_GAIN",
189                    "Thrust added per m/s of sink past the limit",
190                )
191                .with_units("s/m")
192                .at_least(0.0),
193            STICKS
194                .param(
195                    "GUID_BOOST_MAX",
196                    "Most thrust the attitude-mode tilt boost gives",
197                )
198                .above(0.0)
199                .at_most(1.0),
200            STICKS
201                .param("GUID_STICK_X", "Roll angle at full stick in attitude mode")
202                .with_units("deg")
203                .at_least(0.0),
204            STICKS
205                .param("GUID_STICK_Y", "Pitch angle at full stick in attitude mode")
206                .with_units("deg")
207                .at_least(0.0),
208            WIND.param(
209                "GUID_WND_BCOEF_X",
210                "Ballistic coefficient along x (belly on a tailsitter) for the wind estimate (0: off)",
211            )
212            .with_units("kg/m/m")
213            .at_least(0.0),
214            WIND.param(
215                "GUID_WND_BCOEF_Y",
216                "Ballistic coefficient along y for the wind estimate (0: off)",
217            )
218            .with_units("kg/m/m")
219            .at_least(0.0),
220            WIND.param(
221                "GUID_WND_MCOEF_X",
222                "Momentum drag along x for the wind estimate (0: off)",
223            )
224            .with_units("1/s")
225            .at_least(0.0),
226            WIND.param(
227                "GUID_WND_MCOEF_Y",
228                "Momentum drag along y for the wind estimate (0: off)",
229            )
230            .with_units("1/s")
231            .at_least(0.0),
232            WIND.param("GUID_WND_F_NSE", "Specific-force noise of the wind estimate")
233                .with_units("m/s/s")
234                .above(0.0),
235            WIND.param("GUID_WND_P_NSE", "How fast the estimated wind may change")
236                .with_units("m/s/s^0.5")
237                .at_least(0.0),
238        ];
239    }
240}