Basic_Frame_TypeC_2023_Omni
|
Implementation of all control PID systems. More...
#include "pid.h"
#include "uarm_lib.hpp"
#include "uarm_math.hpp"
Functions | |
void | pid_param_init (PID_t *pid, int32_t max_out, float max_i_out, float max_err, float kp, float ki, float kd) |
Initializes a PID_t structure with provided parameters. | |
float | pid_calculate (PID_t *pid, float cur_val, float target_val, float dt) |
Computes a single PID iteration for one time-step. | |
float | pid_incremental_calculate (PID_t *pid, float cur_val, float target_val) |
Calculates incremental PID output for one time-step. | |
float | pid_single_loop_control (float target_val, PID_t *pid, float cur_val, float dt) |
Calculates iteration of single-loop PID controller. | |
float | pid_dual_loop_control (float f_tar_val, PID_t *f_pid, PID_t *s_pid, float f_cur_val, float s_cur_val, float dt) |
Calculate an iteration of dual-loop cascade PID controller. | |
void | pid2_init (PID2_t &pid, float k_p, float k_i, float k_d, float beta, float yeta, float min_out, float max_out) |
Initializes a PID2_t controller. | |
void | pid2_set_limits (PID2_t &pid, float new_min_out, float new_max_out) |
Sets new output limits for PID2_t controller. | |
float | pid2_calculate (PID2_t &pid, float sp, float pv, float dt) |
Calculates PID2 output for one time-step. | |
float | pid2_single_loop_control (PID2_t &pid, float sp, float pv, float dt) |
Caculate an iteration of a single-loop PID2 controller. | |
float | pid2_dual_loop_control (PID2_t &f_pid, PID2_t &s_pid, float sp, float f_pv, float s_pv, float f_dt, float s_dt) |
Calculates an iteration of a dual-loop PID2 controller. | |
float | pid2_triple_loop_control (PID2_t &outer_pid, PID2_t &middle_pid, PID2_t &inner_pid, float sp, float outer_pv, float middle_pv, float inner_pv, float outer_dt, float middle_dt, float inner_dt) |
Calculates an iteration for a triple-loop PID2 controller. | |
void | prescaled_pid2_init (Prescaled_PID2_t *prescaled, uint32_t prescalar, float k_p, float k_i, float k_d, float beta, float yeta, float min_out, float max_out) |
Initializes a Prescaled_PID2_t structure with provided parameters. | |
void | prescaled_pid2_single_loop_control (Prescaled_PID2_t *prescaled, float sp, float pv, float dt) |
Calculate an iteration for prescaled single-loop PID2 controller. |
Implementation of all control PID systems.
All implementations for control systems that utilizes PID as the primary controller are included in this file. This includes single and cascade control loops as well as different implementations of PID with their own solutions to problems known about PID controllers in real systems (e.g. integator windup, derivative kick, etc.).
float pid2_calculate | ( | PID2_t & | pid, |
float | sp, | ||
float | pv, | ||
float | dt ) |
Calculates PID2 output for one time-step.
[in,out] | pid | Reference to PID2_t struct. |
[in] | sp | Setpoint value. |
[in] | pv | Plant value. |
[in] | dt | Time step. Must be positive. |
float pid2_dual_loop_control | ( | PID2_t & | f_pid, |
PID2_t & | s_pid, | ||
float | sp, | ||
float | f_pv, | ||
float | s_pv, | ||
float | f_dt, | ||
float | s_dt ) |
Calculates an iteration of a dual-loop PID2 controller.
[in,out] | f_pid | Reference to outer loop PID2_t struct. |
[in,out] | s_pid | Reference to inner loop PID2_t struct. |
[in] | sp | Setpoint value for outer loop. |
[in] | f_pv | Plant value for outer loop. |
[in] | s_pv | Plant value for inner loop. |
[in] | f_dt | Time step for outer loop. |
[in] | s_dt | Time step for inner loop. |
void pid2_init | ( | PID2_t & | pid, |
float | k_p, | ||
float | k_i, | ||
float | k_d, | ||
float | beta, | ||
float | yeta, | ||
float | min_out, | ||
float | max_out ) |
Initializes a PID2_t controller.
[in,out] | pid | Reference to PID2_t controller struct to initialize. |
[in] | k_p | Proportional gain. |
[in] | k_i | Integral gain. |
[in] | k_d | Derivative gain. |
[in] | beta | Proportional error scaling factor. |
[in] | yeta | Derivative error scaling factor. |
beta
and yeta
are parameters for setpoint weighting, which is primarily used for negating effects of derivative kick. [in] | min_out | Minimum output value. |
[in] | max_out | Maximum output value. Must be greater or equal to min_out. |
void pid2_set_limits | ( | PID2_t & | pid, |
float | new_min_out, | ||
float | new_max_out ) |
Sets new output limits for PID2_t controller.
[in,out] | pid | Reference to PID2_t controller struct. |
[in] | new_min_out | New minimum output value. |
[in] | new_max_out | New maximum output value. Must be greater or equal to new_min_out. |
new_min_out
and new_max_out
. float pid2_single_loop_control | ( | PID2_t & | pid, |
float | sp, | ||
float | pv, | ||
float | dt ) |
Caculate an iteration of a single-loop PID2 controller.
[in,out] | pid | Reference to PID2_t controller struct. |
[in] | sp | Setpoint value. |
[in] | pv | Plant value. |
[in] | dt | Time step. |
float pid2_triple_loop_control | ( | PID2_t & | outer_pid, |
PID2_t & | middle_pid, | ||
PID2_t & | inner_pid, | ||
float | sp, | ||
float | outer_pv, | ||
float | middle_pv, | ||
float | inner_pv, | ||
float | outer_dt, | ||
float | middle_dt, | ||
float | inner_dt ) |
Calculates an iteration for a triple-loop PID2 controller.
[in,out] | outer_pid | Reference to outer loop PID2_t struct. |
[in,out] | middle_pid | Reference to middle loop PID2_t struct. |
[in,out] | inner_pid | Reference to inner loop PID2_t struct. |
[in] | sp | Setpoint value for outer loop. |
[in] | outer_pv | Plant value for outer loop. |
[in] | middle_pv | Plant value for middle loop. |
[in] | inner_pv | Plant value for inner loop. |
[in] | outer_dt | Time step for outer loop. |
[in] | middle_dt | Time step for middle loop. |
[in] | inner_dt | Time step for inner loop. |
float pid_calculate | ( | PID_t * | pid, |
float | cur_val, | ||
float | target_val, | ||
float | dt ) |
Computes a single PID iteration for one time-step.
[in,out] | pid | Pointer to PID_t struct. |
[in] | cur_val | Plant value. |
[in] | target_val | Target value. |
[in] | dt | Time step (seconds). |
dt
parameter is ignored and the time-step is always assumed to be 1.0. max_err
, the output is zero and PID iteration calculations are skipped. float pid_dual_loop_control | ( | float | f_tar_val, |
PID_t * | f_pid, | ||
PID_t * | s_pid, | ||
float | f_cur_val, | ||
float | s_cur_val, | ||
float | dt ) |
Calculate an iteration of dual-loop cascade PID controller.
[in] | f_tar_val | Outer loop target value. |
[in,out] | f_pid | Pointer to outer loop PID_t controller struct. |
[in,out] | s_pid | Pointer to inner loop PID_t controller struct. |
[in] | f_cur_val | Outer loop current value. |
[in] | s_cur_val | Inner loop current value. |
[in] | dt | Time step for both loops. |
float pid_incremental_calculate | ( | PID_t * | pid, |
float | cur_val, | ||
float | target_val ) |
Calculates incremental PID output for one time-step.
[in,out] | pid | Pointer to PID_t controller struct. |
[in] | cur_val | Plant value. |
[in] | target_val | Target value. |
max_err
, the output is zero and PID iteration is skipped. void pid_param_init | ( | PID_t * | pid, |
int32_t | max_out, | ||
float | max_i_out, | ||
float | max_err, | ||
float | kp, | ||
float | ki, | ||
float | kd ) |
Initializes a PID_t structure with provided parameters.
[out] | pid | Pointer to PID_t struct to initialize. |
[in] | max_out | Maximum output magnitude. Must be non-negative. |
[in] | max_i_out | Maximum integral output magnitude. Must be non-negative. |
[in] | max_err | Maximum error value. Must be non-negative. Errors greater than this will skip a PID iteration. |
[in] | kp | Proportional gain. |
[in] | ki | Integral gain. |
[in] | kd | Derivative gain. |
float pid_single_loop_control | ( | float | target_val, |
PID_t * | pid, | ||
float | cur_val, | ||
float | dt ) |
Calculates iteration of single-loop PID controller.
[in] | target_val | Target value. |
[in,out] | pid | Pointer to PID_t controller struct. |
[in] | cur_val | Plant value. |
[in] | dt | Time step. |
void prescaled_pid2_init | ( | Prescaled_PID2_t * | prescaled, |
uint32_t | prescalar, | ||
float | k_p, | ||
float | k_i, | ||
float | k_d, | ||
float | beta, | ||
float | yeta, | ||
float | min_out, | ||
float | max_out ) |
Initializes a Prescaled_PID2_t structure with provided parameters.
prescaled | Pointer to Prescaled_PID2_t struct to initialize. |
prescalar | Number of calls before PID2 calculation is performed. |
k_p | Proportional gain. |
k_i | Integral gain. |
k_d | Derivative gain. |
beta | Proportional error scaling factor. |
yeta | Derivative error scaling factor. |
beta
and yeta
are parameters for setpoint weighting, which is primarily used for negating effects of derivative kick. min_out | Minimum output value. |
max_out | Maximum output value. |
void prescaled_pid2_single_loop_control | ( | Prescaled_PID2_t * | prescaled, |
float | sp, | ||
float | pv, | ||
float | dt ) |
Calculate an iteration for prescaled single-loop PID2 controller.
prescaled | Pointer to Prescaled_PID2_t struct. |
sp | Setpoint value. |
pv | Plant (process) value. |
dt | Time step. |