Update PI controller toward target gain.
- Parameters
-
| targetGain | Desired gain |
| dt | Time step in seconds |
- Returns
- Smoothed gain output
Definition at line 159 of file auto_gain.cpp.hpp.
159 {
160 const float error = targetGain -
mLastGain;
161
162
163
164 const bool largeError = (
mLastGain > 0.1f)
168
169
170 const float pTerm =
mKp * error;
171
172
173
174 const float piTarget = targetGain + pTerm +
mIntegrator;
175
176
177 float alpha = 1.0f;
178 if (tau > 0.0f && dt > 0.0f) {
179 alpha = 1.0f -
fl::exp(-dt / tau);
180 }
181
183
184
185
186 const bool saturated = (unclamped >
mConfig.maxGain) || (unclamped <
mConfig.minGain);
187 if (saturated) {
189 } else {
191 }
192
193 const float maxIntegral = 4.0f *
mConfig.maxGain;
195
196 return unclamped;
197}
float mLastGain
Last smoothed gain output.
float mIntegrator
PI integrator state.
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
enable_if< is_fixed_point< T >::value, T >::type exp(T x) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type abs(T x) FL_NOEXCEPT
References fl::abs(), fl::exp(), fl::max(), mConfig, mGainFollowFastTau, mGainFollowSlowTau, fl::min(), mIntegrator, mKi, mKp, and mLastGain.
Referenced by process().