@@ -75,29 +75,58 @@ namespace qlibs {
75
75
static const uint32_t UNDEFINED;
76
76
protected:
77
77
/* ! @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*/
93
92
static bool isValidValue ( const real_t x ) noexcept ;
94
93
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
+ }
98
124
bool step ( const real_t u,
99
125
const real_t y,
100
126
const real_t dt ) noexcept ;
127
+ /* ! @endcond */
128
+ public:
129
+ pidAutoTuning () = default ;
101
130
pidGains getEstimates ( void ) const noexcept ;
102
131
};
103
132
@@ -107,7 +136,6 @@ namespace qlibs {
107
136
*/
108
137
class pidController : public pidGains , public nState , private nonCopyable {
109
138
private:
110
- // real_t Kc, Ki, Kd;
111
139
real_t b, c, sat_Min, sat_Max, epsilon, kw, kt, D, u1, beta, uSat;
112
140
real_t dt{ 1 .0_re };
113
141
real_t m, mInput ;
@@ -226,11 +254,19 @@ namespace qlibs {
226
254
227
255
/* *
228
256
* @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 ]
230
258
* @return @c true on success, otherwise return @c false.
231
259
*/
232
260
bool setDerivativeFilter ( const real_t Beta ) noexcept ;
233
261
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
+
234
270
/* *
235
271
* @brief Change the controller operational mode.
236
272
* In pidMode::PID_AUTOMATIC, the computed output of the PID controller
0 commit comments