52 lines
1.1 KiB
C
52 lines
1.1 KiB
C
#ifndef PID_CONTROLLER_H
|
|
#define PID_CONTROLLER_H
|
|
|
|
#include <stdbool.h>
|
|
|
|
typedef struct {
|
|
|
|
/* Controller gains */
|
|
float Kp;
|
|
float Ki;
|
|
float Kd;
|
|
|
|
/* Default controller gains */
|
|
float KpDefault;
|
|
float KiDefault;
|
|
float KdDefault;
|
|
|
|
/* Derivative low-pass filter time constant */
|
|
float tau;
|
|
|
|
/* Output limits */
|
|
float limMin;
|
|
float limMax;
|
|
|
|
/* Integrator limits */
|
|
float limMinInt;
|
|
float limMaxInt;
|
|
|
|
/* Sample time (in seconds) */
|
|
float T;
|
|
|
|
bool enable;
|
|
|
|
/* Controller "memory" */
|
|
float proportional;
|
|
float integrator;
|
|
float prevError; /* Required for integrator */
|
|
float differentiator;
|
|
float prevMeasurement; /* Required for differentiator */
|
|
|
|
/* Controller output */
|
|
float out;
|
|
|
|
} PidController;
|
|
|
|
void pidControllerInit(PidController *pid, float Kp, float Ki, float Kd, float tau, float limMin, float limMax,
|
|
float limMinInt, float limMaxInt, float T);
|
|
|
|
float pidControllerUpdate(PidController *pid, float setpoint, float measurement);
|
|
|
|
#endif //PID_CONTROLLER_H
|