A Universal Windows Runtime Component that implements a very simple proportional-integral-derivative controller.
-
In Visual Studio select File -> New -> Project
-
Select your language of choice. The PID Controller is a Universal Windows Runtime Component, meaning it is compatable with C++, C#, or JavaScript.
-
Select the "Windows" option under the language you selected and choose "Blank App (Universal Windows)".
-
Clone the PID Controller repository or download the zip file.
-
Right-click on your solution in the Solution Explorer and select Add -> Existing Project
-
Navigate to your local copy of the PID Controller repository and select PidController.csproj
-
Right-click on References in your main project within the solution. Select Add Reference
-
Under the "Projects" tab, select PidController
-
Rebuild your solution by selecting Build -> Rebuild All
For an example of this code being used to control motor RPM see our Closed-Loop Control Demo.
PidController controller = new PidController(float GainProportional, float GainIntegral, float GainDerivative, float OutputMax, float OutputMin);
GainProportional
- The proportional gain in the feedback loopGainIntegral
- The integral gain in the feedback loopGainDerivative
- The derivative gain in the feedback loopOutputMax
- The maximum value theControlVariable
property can returnOutputMin
- The minimum value theControlVariable
property can return
Property | Type | Access | Description |
---|---|---|---|
GainProportional | double |
get/set | The proportional gain in the feedback loop |
GainIntegral | double |
get/set | The integral gain in the feedback loop |
GainDerivative | double |
get/set | The derivative gain in the feedback loop |
OutputMax | double |
get | The maximum value the ControlVariable function can return |
OutputMin | double |
get | The minimum value the ControlVariable function can return |
IntegralTerm | double |
get | Tracks the accumulated error in the control loop |
ProcessVariable | double |
get/set | Current value of the process under control |
ProcessVariableLast | double |
get | Last stored value of the process under control |
SetPoint | double |
get/set | The desired value of the process under control |
Function | Return Type | Description |
---|---|---|
ControlVariable(TimeSpan timeSinceLastUpdate ) |
double |
The control variable that drives the process under control, depending on the amount of time that passed since the last time it was called |
There are lots of resources online for learning how to tune a PID controller. For a quick primer see the Wikipedia entry on manual tuning.
===
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.