EasyPID 1.0.1

dotnet add package EasyPID --version 1.0.1                
NuGet\Install-Package EasyPID -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EasyPID" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasyPID --version 1.0.1                
#r "nuget: EasyPID, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EasyPID as a Cake Addin
#addin nuget:?package=EasyPID&version=1.0.1

// Install EasyPID as a Cake Tool
#tool nuget:?package=EasyPID&version=1.0.1                

EasyPID - Easily create and run a PID controller for your device

Summary

Easily create a PID device and receive and output the control signal. You may choose an output range. It is important to note that you need to find the current time value in ticks before finding the Process Variable. This is to prevent your read interval to be faster than what your device can read.

Sample

This sample creates an array of numbers this is our Process Variable or input value. We then use this Process Variable and run it through the easy PID to get our Control Variable (output). We also add a time into the PID to make sure that it is being run at a consistent interval and that our device is reading properly.

First we create a process variable for this example:

 double[] array = new double[200];
            for (int a = 0; a < 200; a++)
            {
                Random random = new Random();
                array[a] = (a + 3) + random.NextDouble();
            }

Then we initiate a new instance of EasyPID controller and input our Ki, Kp, Kd, Setpoint, and OutputSpeed.

Controllers: Manually tune. Read more in the reference at the bottom of the page Kp= Proportional controller

Ki= Integral controller

Kd= Derivative controller

Setpoint = The goal value that you want to set (for example 150 if you want your device to get you to 150F)

OutputSpeed(optional) = This is how fast the controller will read. I recommend using "500" which is 0.5 seconds. You can go faster but it is limited by your processor and the speed of the device output. For this example we will use 1000 for a one second interval.

MinimumValue(optional)= Set the minimum value for the Control Variable. This is set to 0 by default can change to any real number for instance -100,-1,0 etc...

MaximumValue(optional)= Set the maximum value for the Control Variable. This is set to 1 by default can change to any real number for instance 100, 1, 1000 etc...

//create a new instance of EasyPID any assigning an OutputSpeed
            EasyPID easyPID = new EasyPID(.009, 0.05, 0.3, 120, 1000);

Now set the current time and the process variable in a while loop

 long currentTime = DateTime.Now.Ticks;
 double ProcessVariable = array[count];

Then run the device by using the GetControlSignal command

FullExample:


private static void Main(string[] args)
        {
            //Example creates an array of numbers to run the controller against
            // Setup an array of numbers to test the controller with this starts at 0 and increases by 3 plus a random number
            int count = 0;
            double[] array = new double[200];
            for (int a = 0; a < 200; a++)
            {
                Random random = new Random();
                array[a] = (a + 3) + random.NextDouble();
            }
            //create a new instance of EasyPID
            EasyPID easyPID = new EasyPID(.009, 0.05, 0.3, 120, 100);

            while (count < 200)
            {
                //Set timer then get actual value from device
                //You must set currentTime before the actualValue, otherwise your device might not read properly
                long currentTime = DateTime.Now.Ticks;
                double ProcessVariable = array[count];
                double controlVariable = easyPID.GetControlSignal(ProcessVariable, currentTime);
                Console.WriteLine($"Process variable is: {ProcessVariable}, Control Variable is: {controlVariable}");
                ++count;
            }
        }

Note

The code checks to see if your device is reading slower than the interval. You can ignore this exception by using a try, catch method.

Please message me or submit a bug request with issues or recommendations

References

PID Wikipedia Link

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 972 1/23/2021
1.0.0 343 1/23/2021