There is a code: http://www.codeproject.com/Articles/49548/Industrial-NET-PID-Controllers .

To access the parameters, use delegates:

namespace PIDLibrary { public delegate double GetDouble(); public delegate void SetDouble(double value); } 

The initial values ​​of the parameters are passed through the constructor:

  public PID(double pG, double iG, double dG, double pMax, double pMin, double oMax, double oMin, GetDouble pvFunc, GetDouble spFunc, SetDouble outFunc) 

What is necessary to pass in the arguments of the constructor in place of the question marks?

 PID pid = new PID(double, double, double, double..., ?, ?, ?); 
  • And where is C ++ in your question? - VladD
  • @VladD, already fixed. - ߊߚߤߘ
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

You must have implemented functions that match delegate signatures, or lambda functions.

The first option . Your code for creating a PID object is called in a method of a certain class, add to this class methods to get / write values:

 private double GetPV() { /* возвращаете некое число типа double */ // return ...; } private double GetSP() { /* возвращаете некое число типа double */ // return ...; } private void WriteOV(double value) { /* используете здесь значение value */ } 

And substitute them into the PID constructor:

 PID pid = new PID(..., GetPV, GetSP, WriteOV); 

The second option . It is necessary to create lambda functions with suitable signatures:

 GetDouble pvFunc = () => /* возвращаете некое число типа double */; GetDouble spFunc = () => /* возвращаете некое число типа double */; SetDouble outFunc = value => { /* используете значение value */ }; PID pid = new PID(..., pvFunc, spFunc, outFunc); 

Which option is more convenient to use depends on the context.