11 #ifndef CONTROLLERPIDCONTROLLER_H 12 #define CONTROLLERPIDCONTROLLER_H 18 #include <base/Time.hpp> 21 bool zeroCrossing(
double currValue,
double prevValue,
double refValue = 0);
79 PIDSettings():Ts(0),K(0),Ti(0),Td(0),N(0),B(1),Tt(-1),YMin(0),YMax(0){};
95 return !(*
this == other);
159 YMin == other.
YMin &&
164 return !(*
this == other);
167 void setIdealCoefficients(
269 void setIdealCoefficients (
double _Ts,
285 double saturate (
double _val );
292 double update (
double _measuredValue,
double _referenceValue,
double time = 0.0 );
298 void printCoefficients();
302 void disableIntegral();
305 void enableIntegral();
308 void enableIntegral(
double _Ti);
315 void disableDerivative();
318 void enableDerivative();
321 void enableDerivative(
double _Td);
327 void disableDerivativeFiltering();
330 void enableDerivativeFiltering();
333 void enableDerivativeFiltering(
double _N);
369 double prevReferenceValue;
372 double Bi, Ad, Bd, Ao;
374 double P, I, D, rawCommand, saturatedCommand;
381 bool bDerivativeFiltering;
397 void computeCoefficients();
401 void autoEnableModes();
410 double _stepRef = 1.0,
411 double _inputAmplitude = 0.1,
412 double _testTimeSec = 10.0);
414 void setCoefficients(
double _Ts,
415 double _stepRef = 1.0,
416 double _inputAmplitude = 0.1,
417 double _testTimeSec = 10.0);
419 double update(
double _measuredValue);
421 void getTunedP(
double &_Kp);
422 void getTunedPI(
double &_Kp,
double &_Ti);
423 void getTunedPID(
double &_Kp,
double &_Ti,
double &_Td);
430 double inputAmplitude;
432 double outputTimePeriodSec;
433 double outputAmplitude;
441 bool firstZeroCrossing;
444 double deltaOutputTime;
446 double maxAmplitude, minAmplitude;
465 double _riseTimeFractionReference = 1.0,
466 double _settlingTimeFractionReference = 0.05);
468 void setCoefficients(
double _Ts,
469 double _riseTimeFractionReference = 1.0,
470 double _settlingTimeFractionReference = 0.05);
474 void update(
double _actualOutput,
477 void getProperties(
double &_riseTimeSec,
478 double &_settlingTimeSec,
479 double &_percentOvershoot,
480 double &_steadyStateError);
482 void printProperties();
488 double settlingTimeSec;
489 double percentOvershoot;
490 double steadyStateError;
491 double steadyStateErrorTimeSec;
493 std::vector<double> maxAmplitudes;
496 double riseTimeFractionReference;
497 double settlingTimeFractionReference;
503 bool riseTimeDetected;
504 bool firstZeroCrossing;
PID Implementation in C++.
Definition: PID.hpp:231
double Kp
Proportional gain.
Definition: PID.hpp:111
bool operator!=(const ParallelPIDSettings &other) const
Definition: PID.hpp:163
double Ki
Integral gain.
Definition: PID.hpp:114
double N
Derivative term.
Definition: PID.hpp:124
PIDStepResponseProperties()
Definition: PID.hpp:463
double K
Proportional gain.
Definition: PID.hpp:42
bool initialized
Definition: PID.hpp:181
double saturatedOutput
Definition: PID.hpp:186
double YMax
Maximum output value.
Definition: PID.hpp:145
double YMax
Maximum output value.
Definition: PID.hpp:76
Definition: InputShaper.hpp:22
double reference
Definition: PID.hpp:184
base::Time time
Definition: PID.hpp:179
double Ti
Integral time constant, 0 to disable it.
Definition: PID.hpp:45
bool isIntegralEnabled() const
Returns whether integral part is enabled.
Definition: PID.hpp:311
ParallelPIDSettings()
Constructor.
Definition: PID.hpp:148
double N
Derivative term.
Definition: PID.hpp:55
double rawOutput
Definition: PID.hpp:185
double B
Setpoint weighing term.
Definition: PID.hpp:131
double YMin
Minimum output value.
Definition: PID.hpp:143
Structure to hold the PID parameters for 'IDEAL' type PID.
Definition: PID.hpp:36
double Ts
Sampling time in seconds.
Definition: PID.hpp:108
double Ts
Sampling time in seconds.
Definition: PID.hpp:39
double B
Setpoint weighing term.
Definition: PID.hpp:62
double Td
Derivative time constant, 0 to disable it.
Definition: PID.hpp:48
bool isDerivativeEnabled() const
Returns whether derivative part is enabled.
Definition: PID.hpp:324
double P
Definition: PID.hpp:182
bool operator==(const PIDSettings &other) const
Definition: PID.hpp:81
double YMin
Minimum output value.
Definition: PID.hpp:74
bool negativeZeroCrossing(double currValue, double prevValue, double refValue=0)
Detects negative zero crossing.
Definition: PID.cpp:24
double Tt
Anti-integrator-windup.
Definition: PID.hpp:70
PID auto tuning using Relay Feedback.
Definition: PID.hpp:405
double Kd
Derivative gain.
Definition: PID.hpp:117
PIDSettings()
Constructor.
Definition: PID.hpp:79
DerivativeMode
Definition: PID.hpp:195
bool zeroCrossing(double currValue, double prevValue, double refValue=0)
Detects zero crossing.
Definition: PID.cpp:7
bool operator==(const ParallelPIDSettings &other) const
Definition: PID.hpp:150
bool operator!=(const PIDSettings &other) const
Definition: PID.hpp:94
Structure to hold the PID parameters for 'PARALLEL' type PID.
Definition: PID.hpp:105
void setParallelCoefficients(double _Kp=0, double _Ki=0, double _Kd=0)
Definition: PID.cpp:31
double input
Definition: PID.hpp:183
bool isDerivativeFilteringEnabled() const
Returns whether derivative filtering part is enabled.
Definition: PID.hpp:336
bool positiveZeroCrossing(double currValue, double prevValue, double refValue=0)
Detects positive zero crossing.
Definition: PID.cpp:16
double Tt
Anti-integrator-windup.
Definition: PID.hpp:139