### Initialize Source: https://github.com/dlloydev/quickpid/blob/master/README.md Performs necessary setup to ensure a smooth transition from manual to automatic control mode, preventing sudden changes in output. ```APIDOC ## Initialize ### Description Performs necessary setup to ensure a smooth transition from manual to automatic control mode, preventing sudden changes in output. ### Method void Initialize(); ``` -------------------------------- ### Initialize PID Controller Source: https://github.com/dlloydev/quickpid/blob/master/README.md Performs necessary setup for a smooth transition from manual to automatic control mode. Call this function when changing the controller's mode to ensure bumpless operation. ```c++ void QuickPID::Initialize(); ``` -------------------------------- ### Get P, I, and D Terms Source: https://github.com/dlloydev/quickpid/wiki/Change Log Retrieve the proportional, integral, and derivative components of the PID calculation. These functions are useful for debugging and understanding the PID's internal state. ```c++ float GetPeTerm(); // proportional on error component of output float GetPmTerm(); // proportional on measurement component of output float GetIterm(); // integral component of output float GetDterm(); // derivative component of output ``` -------------------------------- ### Get Ultimate Gain and Period Source: https://github.com/dlloydev/quickpid/wiki/Change Log Display the ultimate gain (Ku) and ultimate period (Tu) of the process. These values are often used in PID tuning methods like Ziegler-Nichols. ```c++ float GetKu(); // display ultimate gain float GetTu(); // display ultimate period (time constant) ``` -------------------------------- ### Get Dead Time Source: https://github.com/dlloydev/quickpid/wiki/Change Log Display the dead time of the process. Dead time is a crucial parameter for tuning controllers in systems with inherent delays. ```c++ float GetTd(); // display dead time ``` -------------------------------- ### QuickPID Constructor with Full Options Source: https://github.com/dlloydev/quickpid/blob/master/README.md Initializes the QuickPID controller with all available parameters, including input, output, setpoint pointers, PID gains, proportional and derivative modes, anti-windup mode, and controller action. Use this when you need to specify all control parameters upfront. ```c++ QuickPID::QuickPID(float* Input, float* Output, float* Setpoint, float Kp, float Ki, float Kd, pMode pMode = pMode::pOnError, dMode dMode = dMode::dOnMeas, iAwMode iAwMode = iAwMode::iAwCondition, Action action = Action::direct) ``` -------------------------------- ### QuickPID Constructor Source: https://github.com/dlloydev/quickpid/blob/master/README.md Initializes a new instance of the QuickPID controller. It takes pointers to input, output, and setpoint variables, along with PID gains and various mode configurations for proportional, derivative, and anti-windup behavior, as well as controller action. ```APIDOC ## QuickPID Constructor ### Description Initializes a new instance of the QuickPID controller. It takes pointers to input, output, and setpoint variables, along with PID gains and various mode configurations for proportional, derivative, and anti-windup behavior, as well as controller action. ### Parameters - **Input** (float*) - Pointer to the variable holding the input value. - **Output** (float*) - Pointer to the variable holding the output value. - **Setpoint** (float*) - Pointer to the variable holding the setpoint value. - **Kp** (float) - PID proportional gain. - **Ki** (float) - PID integral gain. - **Kd** (float) - PID derivative gain. - **pMode** (pMode) - Proportional mode: `pOnError` (default), `pOnMeas`, `pOnErrorMeas`. - **dMode** (dMode) - Derivative mode: `dOnError`, `dOnMeas` (default). - **iAwMode** (iAwMode) - Integral anti-windup mode: `iAwCondition` (default), `iAwClamp`, `iAwOff`. - **action** (Action) - Controller action: `direct` (default), `reverse`. ``` ```APIDOC ## QuickPID Constructor (Simplified Kp, Ki, Kd) ### Description Initializes a new instance of the QuickPID controller using default proportional mode (`pOnError`) and specifying PID gains and controller action. ### Parameters - **Input** (float*) - Pointer to the variable holding the input value. - **Output** (float*) - Pointer to the variable holding the output value. - **Setpoint** (float*) - Pointer to the variable holding the setpoint value. - **Kp** (float) - PID proportional gain. - **Ki** (float) - PID integral gain. - **Kd** (float) - PID derivative gain. - **action** (Action) - Controller action: `direct` (default), `reverse`. ``` ```APIDOC ## QuickPID Constructor (Default Gains) ### Description Initializes a new instance of the QuickPID controller with default PID gains (Kp, Ki, Kd set to zero). These gains must be set later using the `SetTunings` function. Default modes for proportional, derivative, and anti-windup are used. ### Parameters - **Input** (float*) - Pointer to the variable holding the input value. - **Output** (float*) - Pointer to the variable holding the output value. - **Setpoint** (float*) - Pointer to the variable holding the setpoint value. ``` -------------------------------- ### QuickPID Constructor with Default Parameters Source: https://github.com/dlloydev/quickpid/blob/master/README.md Initializes the QuickPID controller with only input, output, and setpoint pointers. PID gains (Kp, Ki, Kd) are initialized to zero and must be set later using the SetTunings function. This constructor is useful for deferred parameter configuration. ```c++ QuickPID::QuickPID(float *Input, float *Output, float *Setpoint) ``` -------------------------------- ### Initialize QuickPID for Reverse Acting Controller Source: https://github.com/dlloydev/quickpid/wiki/AutoTune Filter Examples Initialize the QuickPID controller specifying the REVERSE acting mode. This is used to simulate a reverse acting controller. ```c++ QuickPID myQuickPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, POn, DOn, QuickPID::REVERSE); ``` -------------------------------- ### QuickPID Constructor with Default Proportional Mode Source: https://github.com/dlloydev/quickpid/blob/master/README.md Initializes the QuickPID controller with PID gains and controller action, defaulting to Proportional on Error mode. This is a convenient overload when the default proportional mode is suitable. ```c++ QuickPID::QuickPID(float* Input, float* Output, float* Setpoint, float Kp, float Ki, float Kd, Action action) ``` -------------------------------- ### sTune Autotuner Source: https://github.com/dlloydev/quickpid/blob/master/README.md Information about the sTune autotuner, a fast library for on-the-fly PID tunings. ```APIDOC ## sTune Autotuner ### Description A very fast autotuner capable of on-the-fly tunings and more. ### Links - Arduino Library: [![ arduino-library-badge](https://www.ardu-badge.com/badge/sTune.svg?)](https://www.ardu-badge.com/sTune) - PlatformIO Registry: [![PlatformIO Registry](https://badges.registry.platformio.org/packages/dlloydev/library/sTune.svg)](https://registry.platformio.org/packages/libraries/dlloydev/sTune) ``` -------------------------------- ### PID Parameter Calculation Source: https://github.com/dlloydev/quickpid/wiki/AutoTune Calculates Kp, Ki, and Kd based on the selected tuning rule. Handles the AMIGO_PID rule separately due to its unique formula. ```c++ if (tuningRule == 6) { //AMIGO_PID (td < readPeriod) ? td = readPeriod : td = td; kp = (0.2 + 0.45 * (Tu / td)) / Ku; float Ti = (((0.4 * td) + (0.8 * Tu)) / (td + (0.1 * Tu)) * td); float Td = (0.5 * td * Tu) / ((0.3 * td) + Tu); ki = kp / Ti; kd = Td * kp; } else { //other rules kp = Rule[tuningRule][ckp] / 1000.0 * Ku; ki = Rule[tuningRule][cki] / 1000.0 * Ku / Tu; kd = Rule[tuningRule][ckd] / 1000.0 * Ku * Tu; } ``` -------------------------------- ### Registering an IDF Component Source: https://github.com/dlloydev/quickpid/blob/master/CMakeLists.txt Use this macro to define a component's source and include paths, and to declare its dependencies on other IDF components. ```cmake idf_component_register( SRC_DIRS "src" INCLUDE_DIRS "src" REQUIRES arduino PRIV_REQUIRES driver soc ) ``` -------------------------------- ### Tuning Rule Lookup Table Source: https://github.com/dlloydev/quickpid/wiki/AutoTune Stores pre-calculated tuning rule values multiplied by 1000 for integer representation. Includes column indices for Kp, Ki, and Kd. ```c++ const int Rule[10][3] = { //ckp, cki, ckd x 1000 { 450, 540, 0 }, // ZIEGLER_NICHOLS_PI { 600, 1176, 75 }, // ZIEGLER_NICHOLS_PID { 313, 142, 0 }, // TYREUS_LUYBEN_PI { 454, 206, 72 }, // TYREUS_LUYBEN_PID { 303, 1212, 0 }, // CIANCONE_MARLIN_PI { 303, 1333, 37 }, // CIANCONE_MARLIN_PID { 0, 0, 0 }, // AMIGO_PID { 700, 1750, 105 }, // PESSEN_INTEGRAL_PID { 333, 667, 111 }, // SOME_OVERSHOOT_PID { 200, 400, 67 }, // NO_OVERSHOOT_PID }; const byte ckp = 0, cki = 1, ckd = 2; // c = column ``` -------------------------------- ### Simulate Reverse Acting Controller Input Source: https://github.com/dlloydev/quickpid/wiki/AutoTune Filter Examples Read and invert the input value to simulate a reverse acting controller. This is done after initializing the controller in REVERSE mode. ```c++ Input = (InputMax - myQuickPID.analogReadFast(inputPin)); // simulate reverse acting controller ``` -------------------------------- ### Calculate Ultimate Gain (Ku) Source: https://github.com/dlloydev/quickpid/wiki/AutoTune Calculates the ultimate gain (Ku) of a system, accounting for peak values and hysteresis. This is used in PID auto-tuning. ```C++ Ku = (float)(4 * outputStep * 2) / (float)(3.14159 * sqrt (sq (peakHigh - peakLow) - sq (hysteresis))); ``` -------------------------------- ### Compute Source: https://github.com/dlloydev/quickpid/blob/master/README.md Executes the PID algorithm to calculate a new output value. This function should be called regularly in the main loop. It returns true when a new output has been calculated based on the sample time, otherwise it returns false. ```APIDOC ## Compute ### Description Executes the PID algorithm to calculate a new output value. This function should be called regularly in the main loop. It returns true when a new output has been calculated based on the sample time, otherwise it returns false. ### Method bool Compute(); ``` -------------------------------- ### Set PID State Source: https://github.com/dlloydev/quickpid/blob/master/README.md Configure the PID controller's internal state, including mode, output limits, tuning parameters, controller direction, sample time, and anti-windup behavior. ```c++ void SetMode(Control mode); // Set PID mode to manual, automatic or timer void SetOutputLimits(float Min, float Max); // Set and clamps the output to (0-255 by default) void SetTunings(float Kp, float Ki, float Kd, // set pid tunings and all computational modes pMode pMode, dMode dMode, iAwMode iAwMode); void SetTunings(float Kp, float Ki, float Kd); // only set pid tunings, other pid modes are unchanged void SetControllerDirection(Action Action); // Set controller action to direct (default) or reverse void SetSampleTimeUs(uint32_t NewSampleTimeUs); // Set PID compute sample time, default = 100000 µs void SetProportionalMode(pMode pMode); // Set pTerm based on error (default), measurement, or both void SetDerivativeMode(dMode dMode); // Set the dTerm, based error or measurement (default). void SetAntiWindupMode(iAwMode iAwMode); // Set iTerm anti-windup to iAwCondition, iAwClamp or iAwOff void SetOutputSum(float sum); // sets the output summation value ``` -------------------------------- ### PID Query Functions Source: https://github.com/dlloydev/quickpid/blob/master/README.md These C++ functions allow you to retrieve the current internal state of the PID controller, including gains, output components, mode, direction, and various computational modes. ```APIDOC ## PID Query Functions ### Description Functions to query the internal state of the PID controller. ### Functions - `float GetKp()`: Get the proportional gain. - `float GetKi()`: Get the integral gain. - `float GetKd()`: Get the derivative gain. - `float GetPterm()`: Get the proportional component of the output. - `float GetIterm()`: Get the integral component of the output. - `float GetDterm()`: Get the derivative component of the output. - `uint8_t GetMode()`: Get the current PID mode (0: manual, 1: automatic, 2: timer). - `uint8_t GetDirection()`: Get the controller direction (0: direct, 1: reverse). - `uint8_t GetPmode()`: Get the proportional mode (0: pOnError, 1: pOnMeas, 2: pOnErrorMeas). - `uint8_t GetDmode()`: Get the derivative mode (0: dOnError, 1: dOnMeas). - `uint8_t GetAwMode()`: Get the anti-windup mode (0: iAwCondition, 1: iAwClamp, 2: iAwOff). ``` -------------------------------- ### Compute PID Output Source: https://github.com/dlloydev/quickpid/blob/master/README.md Executes the PID algorithm to calculate a new output value. This function should be called regularly within the main loop. It returns true only when a new output has been computed based on the sample time, otherwise it returns false. ```c++ bool QuickPID::Compute(); ``` -------------------------------- ### PID Set Functions Source: https://github.com/dlloydev/quickpid/blob/master/README.md These C++ functions allow you to modify the internal state and behavior of the PID controller, including setting gains, output limits, tunings, controller direction, sample time, and various computational modes. ```APIDOC ## PID Set Functions ### Description Functions to set the internal state and behavior of the PID controller. ### Functions - `void SetMode(Control mode)`: Set PID mode to manual, automatic, or timer. - `void SetOutputLimits(float Min, float Max)`: Set and clamp the output to the specified minimum and maximum values. - `void SetTunings(float Kp, float Ki, float Kd, pMode pMode, dMode dMode, iAwMode iAwMode)`: Set PID tunings and all computational modes. - `void SetTunings(float Kp, float Ki, float Kd)`: Set only PID tunings; other PID modes remain unchanged. - `void SetControllerDirection(Action Action)`: Set controller action to direct or reverse. - `void SetSampleTimeUs(uint32_t NewSampleTimeUs)`: Set the PID compute sample time in microseconds. - `void SetProportionalMode(pMode pMode)`: Set the proportional mode based on error, measurement, or both. - `void SetDerivativeMode(dMode dMode)`: Set the derivative mode based on error or measurement. - `void SetAntiWindupMode(iAwMode iAwMode)`: Set the integral term anti-windup mode. - `void SetOutputSum(float sum)`: Set the output summation value. ``` -------------------------------- ### Calculate Ultimate Period (Tu) Source: https://github.com/dlloydev/quickpid/wiki/AutoTune Calculates the ultimate period (Tu) of a system using microsecond timing. This is used in PID auto-tuning. ```C++ Tu = (float)(t3 - t2) / 1000000.0; ``` -------------------------------- ### Query PID State Source: https://github.com/dlloydev/quickpid/blob/master/README.md Retrieve the current internal state of the PID controller, including gains, output components, mode, direction, and various computational modes. ```c++ float GetKp(); // proportional gain float GetKi(); // integral gain float GetKd(); // derivative gain float GetPterm(); // proportional component of output float GetIterm(); // integral component of output float GetDterm(); // derivative component of output uint8_t GetMode(); // manual (0), automatic (1) or timer (2) uint8_t GetDirection(); // direct (0), reverse (1) uint8_t GetPmode(); // pOnError (0), pOnMeas (1), pOnErrorMeas (2) uint8_t GetDmode(); // dOnError (0), dOnMeas (1) uint8_t GetAwMode(); // iAwCondition (0, iAwClamp (1), iAwOff (2) ``` -------------------------------- ### Reset Source: https://github.com/dlloydev/quickpid/blob/master/README.md Clears the internal terms of the PID controller, including proportional, integral, and derivative terms, as well as the output summation. This is useful for resetting the controller's state. ```APIDOC ## Reset ### Description Clears the internal terms of the PID controller, including proportional, integral, and derivative terms, as well as the output summation. This is useful for resetting the controller's state. ### Method void Reset(); ``` -------------------------------- ### Reset PID Controller State Source: https://github.com/dlloydev/quickpid/blob/master/README.md Clears the internal state variables of the PID controller, including the proportional term (pTerm), integral term (iTerm), derivative term (dTerm), and the integral output sum (outputSum). Use this to reset the controller's accumulated values. ```c++ void QuickPID::Reset(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.