26 set_param(dt_, Kp_, Ki_, Kd_, I_max_, u_max_, d_filter_, fc_);
41 lpf.set_param(fc, dt);
47 update_gain(op_cond_);
54 I = I + Ki * e_k * dt;
64 D = Kd * (e_k - e_k_1) / dt;
99 op_cond_arr = op_cond_arr_;
109 if (op_cond_ <= op_cond_arr[0])
115 else if (op_cond_ >= op_cond_arr[len_arr - 1])
117 Kp = Kp_arr[len_arr - 1];
118 Ki = Ki_arr[len_arr - 1];
119 Kd = Kd_arr[len_arr - 1];
123 uint16_t index_i = 0;
125 for (uint16_t i = 0; i < len_arr; i++)
127 if (op_cond_ > op_cond_arr[i])
137 Kp = interpolate(op_cond_, op_cond_arr[index_i], Kp_arr[index_i], op_cond_arr[index_i + 1], Kp_arr[index_i + 1]);
138 Ki = interpolate(op_cond_, op_cond_arr[index_i], Ki_arr[index_i], op_cond_arr[index_i + 1], Ki_arr[index_i + 1]);
139 Kd = interpolate(op_cond_, op_cond_arr[index_i], Kd_arr[index_i], op_cond_arr[index_i + 1], Kd_arr[index_i + 1]);
147 lpf.set_param(fc, dt);
183 d_filter = d_filter_;
190 lpf.set_param(fc, dt);
286 return y1 + (x - x1) * (y2 - y1) / (x2 - x1);
void set_ff(T u_ff_)
Sets the feed-forward control input.
void set_fc(T fc_)
Sets the derivative filter cutoff frequency.
void set_Ki(T Ki_)
Sets the integral gain.
T get_ff()
Gets the feed-forward control input.
void reset()
Resets the PID controller state.
void set_gain_lookup_table(T *op_cond_arr_, T *Kp_arr_, T *Ki_arr_, T *Kd_arr_, uint16_t len_arr_)
Configures the gain-scheduling lookup tables.
T get_P()
Gets the proportional contribution.
PID_GS()
Constructs a gain-scheduled PID controller.
T get_u()
Gets the controller output.
void update_gain(T op_cond_)
Updates the PID gains according to the operating condition.
T interpolate(T x, T x1, T y1, T x2, T y2)
Linearly interpolates a value between two lookup-table points.
T get_I_max()
Gets the maximum integral contribution.
T get_e_k_1()
Gets the previous control error.
void set_d_filter(bool d_filter_)
Enables or disables derivative filtering.
bool get_d_filter()
Gets the derivative filter enable state.
void set_param(T dt_, T Kp_, T Ki_, T Kd_, T I_max_, T u_max_, bool d_filter_=false, T fc_=10.0)
Sets the PID controller parameters.
T get_D()
Gets the derivative contribution.
T get_u_max()
Gets the maximum controller output.
T update(T x_0, T x, T u_ff_=0.0, T op_cond_=0.0)
Computes the gain-scheduled PID control output.
void set_Kd(T Kd_)
Sets the derivative gain.
T get_Kp()
Gets the proportional gain.
T get_Ki()
Gets the integral gain.
void set_u_max(T u_max_)
Sets the maximum controller output.
T get_dt()
Gets the controller sampling time.
void set_I_max(T I_max_)
Sets the maximum integral contribution.
void set_dt(T dt_)
Sets the controller sampling time.
void set_Kp(T Kp_)
Sets the proportional gain.
void merge(T u_k_1_)
Merges an external controller output into the PID state.
T get_fc()
Gets the derivative filter cutoff frequency.
T get_Kd()
Gets the derivative gain.
T get_I()
Gets the integral contribution.
void init(T dt_, T Kp_, T Ki_, T Kd_, T I_max_, T u_max_, bool d_filter_=false, T fc_=10.0)
Initializes the PID controller.
PID controller with gain scheduling.
constexpr T saturate(T x, T x_min, T x_max)
Saturates a value within a specified range.