Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pid.h File Reference

Several forms of PID controllers. More...

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PID_f
 Simple PID structure floating point. More...
 
struct  PID_df
 Distcrete time PID structure. More...
 
struct  PI_D_df
 Distcrete time PI-D structure. More...
 

Functions

static void init_pid_f (struct PID_f *pid, float Kp, float Kd, float Ki, float max_sum)
 
static float update_pid_f (struct PID_f *pid, float value, float dt)
 Update PID with a new value and return new command. More...
 
static float get_pid_f (struct PID_f *pid)
 Get current value of the PID command. More...
 
static void reset_pid_f (struct PID_f *pid)
 Reset PID struture, gains left unchanged. More...
 
static void set_gains_pid_f (struct PID_f *pid, float Kp, float Kd, float Ki)
 Set gains of the PID struct. More...
 
static void set_integral_pid_f (struct PID_f *pid, float value)
 Set integral part, can be used to reset. More...
 
static void init_pid_df (struct PID_df *pid, float Kp, float Kd, float Ki, float Ts)
 Init PID struct. More...
 
static float update_pid_df (struct PID_df *pid, float value)
 Update PID with a new value and return new command. More...
 
static float get_pid_df (struct PID_df *pid)
 Get current value of the PID command. More...
 
static void reset_pid_df (struct PID_df *pid)
 Reset PID struture, gains left unchanged. More...
 
static void set_gains_pid_df (struct PID_df *pid, float Kp, float Kd, float Ki, float Ts)
 Set gains of the PID struct. More...
 
static void init_pi_d_df (struct PI_D_df *pid, float Kp, float Kd, float Ki, float Ts)
 Init PI-D struct. More...
 
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. More...
 
static float get_pi_d_df (struct PI_D_df *pid)
 Get current value of the PI-D command. More...
 
static void reset_pi_d_df (struct PI_D_df *pid)
 Reset PI-D struture, gains left unchanged. More...
 
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. More...
 

Detailed Description

Several forms of PID controllers.

Definition in file pid.h.


Data Structure Documentation

struct PID_f

Simple PID structure floating point.

u_k = Kp * e_k + Kd * (e_k - e_k-1) / dt + Ki * (sum (e_k * dt))

with: u = outputs e = inputs Kp = proportional gain Kd = derivative gain Ki = integral gain dt = time since last input

Definition at line 42 of file pid.h.

Data Fields
float e[2] input
float g[3] controller gains (Kp, Kd, Ki)
float max_sum windup protection, max of Ki * sum(e_k * dt)
float sum integral of input
float u output
struct PID_df

Distcrete time PID structure.

floating point, fixed frequency.

u_k = u_k-1 + a * e_k + b * e_k-1 + c * e_k-2

with: u = outputs e = inputs a = Kp + Ki Ts/2 + Kd/Ts b = -Kp + Ki Ts/2 - 2 Kd/Ts c = Kd/Ts Kp = proportional gain Kd = derivative gain Ki = integral gain Ts = sampling frequency

Definition at line 160 of file pid.h.

Data Fields
float e[3] input
float g[3] controller gains
float u[2] output
struct PI_D_df

Distcrete time PI-D structure.

derivative term is directly provided as input as it may be available directly from a sensor or estimated separately. floating point, fixed frequency.

u_k = u_k-1 + a * e_k + b * e_k-1 + Kd * d_k

with: u = outputs e = inputs d = derivative of input a = Kp + Ki Ts/2 b = -Kp + Ki Ts/2 Kp = proportional gain Kd = derivative gain Ki = integral gain Ts = sampling frequency

Definition at line 259 of file pid.h.

Data Fields
float e[2] input
float g[3] controller gains
float u[2] output

Function Documentation

static float get_pi_d_df ( struct PI_D_df pid)
inlinestatic

Get current value of the PI-D command.

Parameters
pidpointer to PI-D structure
Returns
current value of PI-D command

Definition at line 305 of file pid.h.

References PI_D_df::u.

static float get_pid_df ( struct PID_df pid)
inlinestatic

Get current value of the PID command.

Parameters
pidpointer to PID structure
Returns
current value of PID command

Definition at line 206 of file pid.h.

References PID_df::u.

static float get_pid_f ( struct PID_f pid)
inlinestatic

Get current value of the PID command.

Parameters
pidpointer to PID structure
Returns
current value of PID command

Definition at line 89 of file pid.h.

References PID_f::u.

static void init_pi_d_df ( struct PI_D_df pid,
float  Kp,
float  Kd,
float  Ki,
float  Ts 
)
inlinestatic

Init PI-D struct.

Parameters
pidpointer to PID structure
Kpproportional gain
Kdderivative gain
Kiintegral gain
Tssampling time

Definition at line 273 of file pid.h.

static void init_pid_df ( struct PID_df pid,
float  Kp,
float  Kd,
float  Ki,
float  Ts 
)
inlinestatic

Init PID struct.

Parameters
pidpointer to PID structure
Kpproportional gain
Kdderivative gain
Kiintegral gain
Tssampling time

Definition at line 174 of file pid.h.

static void init_pid_f ( struct PID_f pid,
float  Kp,
float  Kd,
float  Ki,
float  max_sum 
)
inlinestatic

Definition at line 50 of file pid.h.

Referenced by shift_tracking_init().

+ Here is the caller graph for this function:

static void reset_pi_d_df ( struct PI_D_df pid)
inlinestatic

Reset PI-D struture, gains left unchanged.

Parameters
pidpointer to PI-D structure

Definition at line 314 of file pid.h.

References PI_D_df::e, and PI_D_df::u.

static void reset_pid_df ( struct PID_df pid)
inlinestatic

Reset PID struture, gains left unchanged.

Parameters
pidpointer to PID structure

Definition at line 215 of file pid.h.

References PID_df::e, and PID_df::u.

static void reset_pid_f ( struct PID_f pid)
inlinestatic

Reset PID struture, gains left unchanged.

Parameters
pidpointer to PID structure

Definition at line 98 of file pid.h.

References PID_f::e, PID_f::sum, and PID_f::u.

Referenced by shift_tracking_reset().

+ Here is the caller graph for this function:

static void set_gains_pi_d_df ( struct PI_D_df pid,
float  Kp,
float  Kd,
float  Ki,
float  Ts 
)
inlinestatic

Set gains PI-D struct.

Parameters
pidpointer to PID structure
Kpproportional gain
Kdderivative gain
Kiintegral gain
Tssampling time

Definition at line 330 of file pid.h.

References PI_D_df::g.

static void set_gains_pid_df ( struct PID_df pid,
float  Kp,
float  Kd,
float  Ki,
float  Ts 
)
inlinestatic

Set gains of the PID struct.

Parameters
pidpointer to PID structure
Kpproportional gain
Kdderivative gain
Kiintegral gain
Tssampling time

Definition at line 232 of file pid.h.

References PID_df::g.

static void set_gains_pid_f ( struct PID_f pid,
float  Kp,
float  Kd,
float  Ki 
)
inlinestatic

Set gains of the PID struct.

Parameters
pidpointer to PID structure
Kpproportional gain
Kdderivative gain
Kiintegral gain

Definition at line 113 of file pid.h.

References PID_f::g.

Referenced by shift_tracking_update_gains().

+ Here is the caller graph for this function:

static void set_integral_pid_f ( struct PID_f pid,
float  value 
)
inlinestatic

Set integral part, can be used to reset.

The new sum of errors is calculated from current gains and bounds.

Parameters
pidpointer to PID structure
valueintegral part of the PID control, 0. will reset it

Definition at line 126 of file pid.h.

References PID_f::g, PID_f::max_sum, and PID_f::sum.

static float update_pi_d_df ( struct PI_D_df pid,
float  value,
float  deriv 
)
inlinestatic

Update PI-D with a new value and return new command.

Parameters
pidpointer to PI-D structure
valuenew input value of the PI-D
derivnew input derivative
Returns
new output command

Definition at line 291 of file pid.h.

References PI_D_df::e, PI_D_df::g, and PI_D_df::u.

static float update_pid_df ( struct PID_df pid,
float  value 
)
inlinestatic

Update PID with a new value and return new command.

Parameters
pidpointer to PID structure
valuenew input value of the PID
Returns
new output command

Definition at line 191 of file pid.h.

References PID_df::e, PID_df::g, and PID_df::u.

static float update_pid_f ( struct PID_f pid,
float  value,
float  dt 
)
inlinestatic

Update PID with a new value and return new command.

Parameters
pidpointer to PID structure
valuenew input value of the PID
dttime since last input (in seconds)
Returns
new output command

Definition at line 68 of file pid.h.

References PID_f::e, PID_f::g, PID_f::max_sum, PID_f::sum, and PID_f::u.

Referenced by shift_tracking_run().

+ Here is the caller graph for this function: