44 lines
799 B
C
44 lines
799 B
C
#ifndef PID_CONTROLLER_H
|
|
#define PID_CONTROLLER_H
|
|
|
|
typedef struct {
|
|
|
|
/* Controller gains */
|
|
float Kp;
|
|
float Ki;
|
|
float Kd;
|
|
|
|
/* 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;
|
|
|
|
/* pid coefficient offset for start pid */
|
|
float offset;
|
|
|
|
/* Controller "memory" */
|
|
float integrator;
|
|
float prevError; /* Required for integrator */
|
|
float proportional;
|
|
float differentiator;
|
|
float prevMeasurement; /* Required for differentiator */
|
|
|
|
/* Controller output */
|
|
float out;
|
|
|
|
} PIDController;
|
|
|
|
void PIDController_Init(PIDController *pid);
|
|
float PIDController_Update(PIDController *pid, float setpoint, float measurement);
|
|
|
|
#endif
|