From 5b0b316bc04596ecbbe85e77c88adcb062ef8f03 Mon Sep 17 00:00:00 2001 From: wocute Date: Sun, 24 Oct 2021 12:11:07 +0000 Subject: [PATCH] =?UTF-8?q?add=20PID=5FAutoTune=5Fv0.h.=20//=E6=88=91?= =?UTF-8?q?=E5=9C=A8=E8=BF=99=E9=87=8C=E6=89=BE=E5=88=B0=E4=BA=86=20******?= =?UTF-8?q?***************************************************************?= =?UTF-8?q?*****?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PID_AutoTune_v0.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 PID_AutoTune_v0.h diff --git a/PID_AutoTune_v0.h b/PID_AutoTune_v0.h new file mode 100644 index 0000000..8520d0a --- /dev/null +++ b/PID_AutoTune_v0.h @@ -0,0 +1,58 @@ + +//https://codebender.cc/library/PID_AutoTune_v0#PID_AutoTune_v0.h + +#ifndef PID_AutoTune_v0 +#define PID_AutoTune_v0 +#define LIBRARY_VERSION 0.0.1 + +class PID_ATune +{ + + + public: + //commonly used functions ************************************************************************** + PID_ATune(double*, double*); // * Constructor. links the Autotune to a given PID + int Runtime(); // * Similar to the PID Compue function, returns non 0 when done + void Cancel(); // * Stops the AutoTune + + void SetOutputStep(double); // * how far above and below the starting value will the output step? + double GetOutputStep(); // + + void SetControlType(int); // * Determies if the tuning parameters returned will be PI (D=0) + int GetControlType(); // or PID. (0=PI, 1=PID) + + void SetLookbackSec(int); // * how far back are we looking to identify peaks + int GetLookbackSec(); // + + void SetNoiseBand(double); // * the autotune will ignore signal chatter smaller than this value + double GetNoiseBand(); // this should be acurately set + + double GetKp(); // * once autotune is complete, these functions contain the + double GetKi(); // computed tuning parameters. + double GetKd(); // + + private: + void FinishUp(); + bool isMax, isMin; + double *input, *output; + double setpoint; + double noiseBand; + int controlType; + bool running; + unsigned long peak1, peak2, lastTime; + int sampleTime; + int nLookBack; + int peakType; + double lastInputs[101]; + double peaks[10]; + int peakCount; + bool justchanged; + bool justevaled; + double absMax, absMin; + double oStep; + double outputStart; + double Ku, Pu; + +}; +#endif + -- Gitee