50 static inline void init_pid_f(
struct PID_f *pid,
float Kp,
float Kd,
float Ki,
float max_sum)
52 *pid = (
struct PID_f) {
70 pid->
e[1] = pid->
e[0];
72 float integral = pid->
g[2] * (pid->
sum + value);
75 }
else if (integral < -pid->max_sum) {
80 pid->
u = pid->
g[0] * pid->
e[0] + pid->
g[1] * (pid->
e[0] - pid->
e[1]) / dt + integral;
128 float integral = value;
129 if (integral < -pid->max_sum) {
131 }
else if (integral > pid->
max_sum) {
134 if (fabsf(pid->
g[2]) < 1e-6) {
137 pid->
sum = integral / pid->
g[2];
179 { Kp + Ki * Ts / 2.f + Kd / Ts,
180 -Kp + Ki * Ts / 2.f - 2.f * Kd / Ts,
193 pid->
e[2] = pid->
e[1];
194 pid->
e[1] = pid->
e[0];
196 pid->
u[1] = pid->
u[0];
197 pid->
u[0] = pid->
u[1] + pid->
g[0] * pid->
e[0] + pid->
g[1] * pid->
e[1] + pid->
g[2] * pid->
e[2];
234 pid->
g[0] = Kp + Ki * Ts / 2.f + Kd / Ts;
235 pid->
g[1] = -Kp + Ki * Ts / 2.f - 2.f * Kd / Ts;
278 { Kp + Ki * Ts / 2.f,
293 pid->
e[1] = pid->
e[0];
295 pid->
u[1] = pid->
u[0];
296 pid->
u[0] = pid->
u[1] + pid->
g[0] * pid->
e[0] + pid->
g[1] * pid->
e[1] + pid->
g[2] * deriv;
332 pid->
g[0] = Kp + Ki * Ts / 2.f;
333 pid->
g[1] = -Kp + Ki * Ts / 2.f;
static void set_gains_pi_d_df(struct PI_D_df *pid, float Kp, float Kd, float Ki, float Ts)
Set gains PI-D struct.
static void init_pi_d_df(struct PI_D_df *pid, float Kp, float Kd, float Ki, float Ts)
Init PI-D struct.
static void init_pid_df(struct PID_df *pid, float Kp, float Kd, float Ki, float Ts)
Init PID struct.
float sum
integral of input
static void reset_pi_d_df(struct PI_D_df *pid)
Reset PI-D struture, gains left unchanged.
float g[3]
controller gains (Kp, Kd, Ki)
static float get_pid_f(struct PID_f *pid)
Get current value of the PID command.
static void set_gains_pid_f(struct PID_f *pid, float Kp, float Kd, float Ki)
Set gains of the PID struct.
static float update_pi_d_df(struct PI_D_df *pid, float value, float deriv)
Update PI-D with a new value and return new command.
static void reset_pid_f(struct PID_f *pid)
Reset PID struture, gains left unchanged.
float g[3]
controller gains
static float get_pid_df(struct PID_df *pid)
Get current value of the PID command.
static float update_pid_f(struct PID_f *pid, float value, float dt)
Update PID with a new value and return new command.
static float get_pi_d_df(struct PI_D_df *pid)
Get current value of the PI-D command.
static void set_integral_pid_f(struct PID_f *pid, float value)
Set integral part, can be used to reset.
static void set_gains_pid_df(struct PID_df *pid, float Kp, float Kd, float Ki, float Ts)
Set gains of the PID struct.
static float update_pid_df(struct PID_df *pid, float value)
Update PID with a new value and return new command.
float g[3]
controller gains
static void reset_pid_df(struct PID_df *pid)
Reset PID struture, gains left unchanged.
static void init_pid_f(struct PID_f *pid, float Kp, float Kd, float Ki, float max_sum)
float max_sum
windup protection, max of Ki * sum(e_k * dt)
Distcrete time PID structure.
Simple PID structure floating point.
Distcrete time PI-D structure.