12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MECF.Framework.Common.Algorithm
- {
- public class PdiAlgorithm : Singleton<PdiAlgorithm>
- {
- #region 内部变量
-
-
-
- private double _kp;
-
-
-
- private double _ki;
-
-
-
- private double _kd;
-
-
-
- private double _lastBias;
-
-
-
- private double _integral;
-
-
-
- private double _targetPressure;
-
-
-
- private double _maxBias = 0;
- #endregion
-
-
-
-
-
-
- public short CalculateSpeed(double kp,double ki,double kd,double targetPressure,double pressure,short speed,double targetLimit)
- {
- _kp = kp;
- _ki = ki;
- _kd = kd;
- _targetPressure = targetPressure;
- _maxBias = 0.5 * targetPressure;
- double index = 0;
- double bias=_targetPressure - pressure;
- if(Math.Abs(bias)<=targetLimit)
- {
- return speed;
- }
- _integral += bias;
- if(Math.Abs(bias)>_maxBias)
- {
- index = 0;
- }
- else if(Math.Abs(bias)<0.9*_maxBias)
- {
- index = 1;
- _integral += bias;
- }
- else
- {
- index=(_maxBias-Math.Abs(bias))/(0.9*_maxBias);
- _integral += bias;
- }
- double pressureBias=_kp*bias+index*_ki*_integral+_kd*(bias-_lastBias);
-
- double speedBias =Math.Round(Math.Sqrt(2 * pressureBias),2);
- _lastBias=bias;
- short finalSpeed= (short)Math.Round(speed+pressureBias,0);
- int maxPumpSpeed = SC.GetValue<int>("Prewet.MaxPumpSpeed");
- int minPumpSpeed = SC.GetValue<int>("Prewet.MinPumpSpeed");
- if (finalSpeed >= maxPumpSpeed)
- {
- finalSpeed = (short)maxPumpSpeed;
- }
- else if(finalSpeed<=minPumpSpeed)
- {
- finalSpeed = (short)minPumpSpeed;
- }
- return finalSpeed;
- }
- }
- }
|