@@ -158,38 +158,55 @@ float NPFG::adaptPeriod(const float ground_speed, const float airspeed, const fl
158
158
const float wind_factor = windFactor (airspeed, wind_speed);
159
159
160
160
if (en_period_lb_) {
161
- // lower bound the period for stability w.r.t. roll time constant and current flight condition
162
- const float period_lb = periodLB (air_turn_rate, wind_factor, feas_on_track);
163
- period = math::max (period_lb * PERIOD_SAFETY_FACTOR, period);
161
+ // lower bound for period not considering path curvature
162
+ const float period_lb_zero_curvature = periodLB (0 .0f , wind_factor, feas_on_track) * PERIOD_SAFETY_FACTOR;
163
+
164
+ // lower bound for period *considering path curvature
165
+ float period_lb = periodLB (air_turn_rate, wind_factor, feas_on_track) * PERIOD_SAFETY_FACTOR;
166
+
167
+ // recalculate the time constant and track error bound considering the zero
168
+ // curvature, lower-bounded period and subsequently recalculate the normalized
169
+ // track error
170
+ const float time_const = timeConst (period_lb_zero_curvature, damping_);
171
+ const float track_error_bound = trackErrorBound (ground_speed, time_const);
172
+ const float normalized_track_error = normalizedTrackError (track_error, track_error_bound);
173
+
174
+ // calculate nominal track proximity with lower bounded time constant
175
+ // (only a numerical solution can find corresponding track proximity
176
+ // and adapted gains simultaneously)
177
+ const float look_ahead_ang = lookAheadAngle (normalized_track_error);
178
+ const float track_proximity = trackProximity (look_ahead_ang);
179
+
180
+ // ramp in curvature dependent lower bound
181
+ period_lb = (ramp_in_adapted_period_) ? period_lb * track_proximity + (1 .0f - track_proximity) *
182
+ period_lb_zero_curvature :
183
+ period_lb;
184
+
185
+ // lower bounded period
186
+ period = math::max (period_lb, period);
164
187
165
188
// only allow upper bounding ONLY if lower bounding is enabled (is otherwise
166
- // dangerous to allow period decrements without stability checks)
167
- const float period_ub = periodUB (air_turn_rate, wind_factor, feas_on_track);
168
-
169
- if (en_period_ub_ && PX4_ISFINITE (period_ub) && period > period_ub) {
170
- // NOTE: if the roll time constant is not accurately known, reducing
171
- // the period here can destabilize the system!
172
- // enable this feature at your own risk!
173
-
174
- // upper bound the period (for track keeping stability), prefer lower bound if violated
175
- const float period_adapted = math::max (period_lb * PERIOD_SAFETY_FACTOR, period_ub);
176
-
177
- // recalculate time constant and track error bound for lower-bounded
178
- // period for normalized track error calculation
179
- const float time_const = timeConst (period, damping_);
180
- const float track_error_bound = trackErrorBound (ground_speed, time_const);
181
- const float normalized_track_error = normalizedTrackError (track_error, track_error_bound);
182
-
183
- // calculate nominal track proximity with lower bounded time constant
184
- // (only a numerical solution can find corresponding track proximity
185
- // and adapted gains simultaneously)
186
- const float look_ahead_ang = lookAheadAngle (normalized_track_error);
187
- const float track_proximity = trackProximity (look_ahead_ang);
188
-
189
- // transition from the nominal period to the adapted period as we get
190
- // closer to the track
191
- period = (ramp_in_adapted_period_) ? period_adapted * track_proximity + (1 .0f - track_proximity) * period :
192
- period_adapted;
189
+ // dangerous to allow period decrements without stability checks).
190
+ // NOTE: if the roll time constant is not accurately known, lower-bound
191
+ // checks may be too optimistic and reducing the period can still destabilize
192
+ // the system! enable this feature at your own risk.
193
+ if (en_period_ub_) {
194
+
195
+ const float period_ub = periodUB (air_turn_rate, wind_factor, feas_on_track);
196
+
197
+ if (en_period_ub_ && PX4_ISFINITE (period_ub) && period > period_ub) {
198
+ // NOTE: if the roll time constant is not accurately known, reducing
199
+ // the period here can destabilize the system!
200
+ // enable this feature at your own risk!
201
+
202
+ // upper bound the period (for track keeping stability), prefer lower bound if violated
203
+ const float period_adapted = math::max (period_lb, period_ub);
204
+
205
+ // transition from the nominal period to the adapted period as we get
206
+ // closer to the track
207
+ period = (ramp_in_adapted_period_) ? period_adapted * track_proximity + (1 .0f - track_proximity) * period :
208
+ period_adapted;
209
+ }
193
210
}
194
211
}
195
212
0 commit comments