16PidController::PidController(
double kp,
double ki,
double kd,
double sampleTime,
double yMin,
double yMax,
double setpoint,
double yStart,
double deltaMax)
20 m_sampleTime(sampleTime),
125 SEMF_INFO(
"set max delta to: %f", delta);
148 double e = m_setpoint - currentValue;
150 double y = m_yLast1 + m_q0 * e + m_q1 * m_eLast1 + m_q2 * m_eLast2;
155 SEMF_INFO(
"y (%f) set to max (%f)", y, m_yMax);
160 SEMF_INFO(
"y (%f) set to min (%f)", y, m_yMin);
165 if ((y - m_yLast1) > m_deltaMax)
167 SEMF_INFO(
"limit delta (%f) to max delta (%f)", y - m_yLast1, m_deltaMax);
168 y = m_yLast1 + m_deltaMax;
170 else if ((m_yLast1 - y) > m_deltaMax)
172 SEMF_INFO(
"limit delta (%f) to max delta (%f)", m_yLast1 - y, m_deltaMax);
173 y = m_yLast1 - m_deltaMax;
179 SEMF_INFO(
"current value: %f, y: %f", currentValue, y);
183void PidController::calculateQ0()
185 m_q0 = m_kp + m_ki * m_sampleTime + (m_kd / m_sampleTime);
189void PidController::calculateQ1()
191 m_q1 = -m_kp - 2 * m_kd / m_sampleTime;
195void PidController::calculateQ2()
197 m_q2 = m_kd / m_sampleTime;
PidController(double kp, double ki, double kd, double sampleTime, double yMin, double yMax, double setpoint=0, double yStart=0, double deltaMax=DBL_MAX)
Constructor.
double maxOuput() const
Returns the maximum value which the output is allowed to have.
void setKd(double kd)
Set the gain of the derivative.
void setSetpoint(double setpoint)
Set the controller set point.
void reset(double yStart=0)
Resets the past sampled values which will be used for the calculation of the integral and derivative.
void setKp(double kp)
Set the proportional gain.
void setMinOutput(double min)
Set the minimum possible output.
virtual double calculate(double currentValue)
Calculates the output value dependent to the actual value. This method must be called cyclically at t...
void setKi(double ki)
Set the gain of the integral.
double ki() const
Get the gain of the integral.
void setSampleTime(double sampleTime)
Set the sample time of the controller.
double kp() const
Returns the proportional gain.
void setMaxDelta(double delta)
Set the max delta of the output between two samples.
void setMaxOutput(double max)
Limits the maximum value of the output.
double setpoint() const
Returns the current set point.
double kd() const
Returns the gain of the derivative.
double maxDelta() const
Returns Set the max delta of the output between two samples.
double sampleTime() const
Returns the current configured sample time.
double minOutput() const
Returns the minimum possible output.