44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#ifndef PID_H
|
|
#define PID_H
|
|
|
|
|
|
#include "time_utils.h"
|
|
#include "foc_utils.h"
|
|
|
|
/**
|
|
* PID controller class
|
|
*/
|
|
class PIDController
|
|
{
|
|
public:
|
|
/**
|
|
*
|
|
* @param P - Proportional gain
|
|
* @param I - Integral gain
|
|
* @param D - Derivative gain
|
|
* @param ramp - Maximum speed of change of the output value
|
|
* @param limit - Maximum output value
|
|
*/
|
|
PIDController(float P, float I, float D, float ramp, float limit);
|
|
~PIDController() = default;
|
|
|
|
float operator() (float error);
|
|
|
|
float P; //!< Proportional gain
|
|
float I; //!< Integral gain
|
|
float D; //!< Derivative gain
|
|
float output_ramp; //!< Maximum speed of change of the output value
|
|
float limit; //!< Maximum output value
|
|
|
|
float error_prev; //!< last tracking error value
|
|
|
|
protected:
|
|
//float error_prev; //!< last tracking error value
|
|
float output_prev; //!< last pid output value
|
|
float integral_prev; //!< last integral component value
|
|
unsigned long timestamp_prev; //!< Last execution timestamp
|
|
};
|
|
|
|
#endif // PID_H
|
|
|
|
//Lyf对此进行了修改,将error_prev从protected移至public,便于清楚积分影响
|