29 template <
class FType>
146 std::uint64_t iterationCount{0};
160 template <
class FType>
167 template <
class FType>
174 template <
class FType>
181 template <
class FType>
188 template <
class FType>
195 template <
class FType>
199 std::tie(limitOutLo, limitOutHi) = std::minmax(
min,
max);
202 template <
class FType>
209 template <
class FType>
216 template <
class FType>
220 outRampDelta = delta;
223 template <
class FType>
230 template <
class FType>
234 maxError = std::abs(error);
237 template <
class FType>
244 template <
class FType>
248 targetRadius = std::abs(radius);
251 template <
class FType>
258 template <
class FType>
262 if (!(0 >= lastOutFactor && lastOutFactor < 1))
264 throw std::invalid_argument{
"the interpolation factor has to be in [0, 1)! factor = " +
267 lastOutInterpolation = lastOutFactor;
270 template <
class FType>
274 return lastOutInterpolation;
278 template <
class FType>
285 template <
class FType>
292 template <
class FType>
299 template <
class FType>
303 return iterationCount;
307 template <
class FType>
314 template <
class FType>
318 return update(lastInValue, lastTarget);
321 template <
class FType>
325 return update(inValue, lastTarget);
328 template <
class FType>
336 if (std::abs(error) < targetRadius)
342 error =
sign(error) * (std::abs(error) - targetRadius);
346 error = std::clamp(error, -maxError, +maxError);
353 lastInValue = inValue;
357 const FloatingType dOut = -Kd * (inValue - lastInValue);
358 lastInValue = inValue;
362 if (outRampDelta != 0)
364 out = std::clamp(out, lastOutValue - outRampDelta, lastOutValue + outRampDelta);
366 if (limitOutLo != limitOutHi)
368 out = std::clamp(out, limitOutLo, limitOutHi);
370 if (lastOutInterpolation != 0)
372 out = lastOutValue * lastOutInterpolation + out * (1 - lastOutInterpolation);
PDController(FloatingType p=0, FloatingType d=0)
FloatingType getMaxError() const
FloatingType getHiOutLimit() const
std::uint64_t getIterationCount() const
void setP(FloatingType p)
FloatingType getP() const
FloatingType getLoOutLimit() const
FloatingType getTargetRadius() const
void setLastOutInterpolation(FloatingType lastOutFactor)
FloatingType getOutRampDelta() const
void limitOut(FloatingType out)
set limits for the output value (lo and hi limits are set to the same value)
FloatingType getD() const
FloatingType getLastInValue() const
FloatingType getLastOutValue() const
void setMaxError(FloatingType error)
void setTargetRadius(FloatingType radius)
FloatingType getLastTarget() const
void setOutRampDelta(FloatingType delta)
void reset()
reset phe controller
void setD(FloatingType d)
FloatingType getLastOutInterpolationFactor() const
FloatingType update()
update the controller using the last input and target value
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
const std::string & to_string(const std::string &s)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)