@@ -75,29 +75,58 @@ namespace qlibs {
7575 static const uint32_t UNDEFINED;
7676 protected:
7777 /* ! @cond */
78- real_t p00{ 1 .0_re };
79- real_t p01{ 0 .0_re };
80- real_t p10{ 0 .0_re };
81- real_t p11{ 1 .0_re }; /* covariance values*/
82- real_t b1{ 0 .1_re };
83- real_t a1{ 0 .9_re }; /* estimation values*/
84- real_t uk{ 0 .0_re };
85- real_t yk{ 0 .0_re }; /* process I/O measurements*/
86- real_t l{ 0 .9898_re }; /* memory factor [ 0.9 < l < 1 ]*/
87- real_t il{ 1 .0_re };
88- real_t k{ 1 .0_re };
89- real_t tao{ 1 .0_re }; /* process metrics*/
90- real_t mu{ 0 .95_re };
91- real_t speed{ 0 .25_re }; /* fine adjustments [ 0 < mu < speed ] [ 0 < speed < 1 ]*/
92- uint32_t it{ UNDEFINED };/* enable time*/
78+ real_t p00{ 1 .0_re }; /* covariance value*/
79+ real_t p01{ 0 .0_re }; /* covariance value*/
80+ real_t p10{ 0 .0_re }; /* covariance value*/
81+ real_t p11{ 1 .0_re }; /* covariance value*/
82+ real_t b1{ 0 .1_re }; /* estimation value*/
83+ real_t a1{ 0 .9_re }; /* estimation value*/
84+ real_t uk{ 0 .0_re }; /* process input*/
85+ real_t yk{ 0 .0_re }; /* process output*/
86+ real_t l{ 0 .9898_re }; /* memory factor [ 0.9 < l < 1 ]*/
87+ real_t k{ 1 .0_re }; /* process static gain*/
88+ real_t tao{ 1 .0_re }; /* process time constant*/
89+ real_t mu{ 0 .95_re }; /* variation attenuation*/
90+ real_t speed{ 0 .25_re }; /* final controller speed*/
91+ uint32_t it{ UNDEFINED }; /* enable time*/
9392 static bool isValidValue ( const real_t x ) noexcept ;
9493 pidType type{ pidType::PID_TYPE_PI };
95- /* ! @endcond */
96- public:
97- pidAutoTuning () = default ;
94+ void initialize ( const pidGains current,
95+ const real_t dt ) noexcept ;
96+ inline void enable ( const uint32_t tEnable ) noexcept
97+ {
98+ it = ( 0UL == tEnable ) ? pidAutoTuning::UNDEFINED : tEnable;
99+ }
100+ inline bool isComplete ( void ) const noexcept
101+ {
102+ return ( ( 0UL == it ) && ( it != pidAutoTuning::UNDEFINED ) );
103+ }
104+ inline void setMemoryFactor ( const real_t lambda ) noexcept
105+ {
106+ l = lambda;
107+ }
108+ inline void setMomentum ( const real_t Mu ) noexcept
109+ {
110+ mu = Mu;
111+ }
112+ inline void setEstimatedControllerSpeed ( const real_t alpha ) noexcept
113+ {
114+ speed = alpha;
115+ }
116+ inline void setEstimatedControllerType ( const pidType t ) noexcept
117+ {
118+ type = t;
119+ }
120+ static inline bool isValidParam ( const real_t p ) noexcept
121+ {
122+ return ( p > 0 .0_re ) && ( p <= 1 .0_re );
123+ }
98124 bool step ( const real_t u,
99125 const real_t y,
100126 const real_t dt ) noexcept ;
127+ /* ! @endcond */
128+ public:
129+ pidAutoTuning () = default ;
101130 pidGains getEstimates ( void ) const noexcept ;
102131 };
103132
@@ -107,7 +136,6 @@ namespace qlibs {
107136 */
108137 class pidController : public pidGains , public nState , private nonCopyable {
109138 private:
110- // real_t Kc, Ki, Kd;
111139 real_t b, c, sat_Min, sat_Max, epsilon, kw, kt, D, u1, beta, uSat;
112140 real_t dt{ 1 .0_re };
113141 real_t m, mInput ;
@@ -226,11 +254,19 @@ namespace qlibs {
226254
227255 /* *
228256 * @brief Set the tuning parameter for the derivative filter.
229- * @param[in] Beta The tuning parameter. [ 0 < Beta < 1 ]
257+ * @param[in] Beta The tuning parameter. [ 0 <= Beta < 1 ]
230258 * @return @c true on success, otherwise return @c false.
231259 */
232260 bool setDerivativeFilter ( const real_t Beta ) noexcept ;
233261
262+ /* *
263+ * @brief Set the time constant for the derivative filter.
264+ * @note
265+ * @param[in] Tf Derivative filter time constant [ Tf >= 0 ]
266+ * @return @c true on success, otherwise return @c false.
267+ */
268+ bool setDerivativeFilterTimeConstant ( const real_t Tf ) noexcept ;
269+
234270 /* *
235271 * @brief Change the controller operational mode.
236272 * In pidMode::PID_AUTOMATIC, the computed output of the PID controller
0 commit comments