PID Controller for the CUWIN

Applications, examples, and sample programs using products from Comfile Technology

PID Controller for the CUWIN

Postby Mike » Tue Feb 14, 2012 10:32 pm

screenshot.jpg
PID Controller Screenshot
screenshot.jpg (37.95 KiB) Viewed 2675 times

This sample program illustrates an implementation of a PID controller for the CUWIN 5000/6000 series. The attached Visual Studio solution is a .Net Compact Framework 3.5 solution, but if you want to use it on the CUWIN 3000/4000 series, just copy the files into a .Net Compact Framework 2.0 solution. No modification should be needed.

There are two projects in this solution. PIDControllerSample is the test project that contains the UI code, and PIDControl is the project that contains the PID controller functionality.

Creating a PID Controller
To create a new PIDController, you must pass a delegate for reading the process value (PV) and another delegate for writing the controller output (CO).
Code: Select all
_pidController = new PIDController(ReadInput, WriteOutput);

private double ReadInput()
{
    //Return process value
}

private void WriteOutput(double value)
{
    //send controller output
}

The set point can be set using the PIDController.SetPoint property.
Code: Select all
_pidController.SetPoint = 0.0d;


PIDController operates on a timer, so once you call PIDController.Start() it will periodically call ReadInput and WriteOutput. By default PIDController uses System.Threading.Timer and its frequency can be set using the PIDController.DeltaTimeInSeconds property. But you can also pass it your own timer by implementing the IPIDTimer interface. The PIDControllerSample project includes an implementation of IPIDTimer that wraps the System.Windows.Forms.Timer.

Tuning the PIDController
There are two classes in the PIDControl project that can be used for tuning the PIDController. PIDController.IdealTuner is for tuning according to the Ideal form (Kp, Ki, Kd) and PIDController.StandardTuner is for Tuning according to the Standard form (Kp, Ti, Td).
Code: Select all
_idealTuner = new PIDController.IdealTuner(_pidController);
_idealTuner.Kp = 0.0d;
_idealTuner.Ki = 0.0d;
_idealTuner.Kd = 0.0d;

_standardTuner = new PIDController.StandardTuner(_pidController);
_standardTuner.Kp = 0.0d;
_standardTuner.Ti = 0.0d;
_standardTuner.Td = 0.0d;

Additional Features
Because a valve cannot be more off than all the way off, and cannot be more on that all the way on, you can constrain the output using PIDController.OutputMinimum and PIDController.OutputMaximum.
Code: Select all
_pidController.OutputMinimum = -1000.0d;
_pidController.OutputMaximum = 1000.0d;

To mitigate Derivative Kick, PIDController's derivative term can be based on PV (Deriviative on Measurement) or on the error (Derivative On Error). Set the PIDContoller.DerivativeOn property accordingly.
Code: Select all
_pidController.DerivativeOn == DerivativeOn.Error;
_pidController.DerivativeOn == DerivativeOn.Measurement;
Attachments
PIDControllerSample.zip
Visual Studio 2008 Solution (C#)
(210.63 KiB) Downloaded 782 times
Mike
Mike
SuperDuperDuper
 
Posts: 551
Joined: Thu Mar 17, 2011 3:54 pm
Location: Seoul, South Korea

Return to Applications and Examples

Who is online

Users browsing this forum: No registered users and 3 guests

cron