//public Func<CascadePIDModel, PIDConstant> UpdatePIDFunc //{ // get; // set; //} //private void Standardize(int k) //{ // this.K = k; // CascadePIDModel item = this[K]; // PIDCollection c = new PIDCollection(this.InPIDConstants, item.Interval); // c.Maximum = this.Maximum; // c.E = i => c[i].Err; // PIDModel inItem = new PIDModel(item.InSV, item.InPV, item.Interval); // c.Add(inItem); // inItem = c.Last(); // item.InP = inItem.P; // item.InI = inItem.I; // item.InD = inItem.D; // item.InDD = inItem.DD; // item.InVariation = inItem.Variation; // this.InCumulativeErr = c.CumulativeErr; // PIDCollection cOut = new PIDCollection(this.OutPIDConstants, item.Interval); // cOut.Maximum = this.Maximum; // cOut.E = i => c[i].Err; // PIDModel outItem = new PIDModel(item.OutSV, item.OutPV, item.Interval); // cOut.Add(outItem); // outItem = cOut.Last(); // item.P = outItem.P; // item.I = outItem.I; // item.D = outItem.D; // item.DD = outItem.DD; // item.Variation = outItem.Variation; // this.OutCumulativeErr = cOut.CumulativeErr; // this[K] = item; //} private void Standardize(int k) { this.K = k; CascadePIDModel item = this[K]; //输入部分 cIn = this.InitCollection(cIn, item, this.InPIDConstants, this.Maximum, ControllerType.Cascade, PIDAction.Input); PIDModel inItem = cIn.Last(); item.InP = inItem.P; item.InI = inItem.I; item.InD = inItem.D; item.InDD = inItem.DD; item.InDPV = inItem.DPV; item.InDDPV = inItem.DDPV; item.InVariation = inItem.Variation; this.InCumulativeErr = cIn.CumulativeErr; //输出部分 cOut = this.InitCollection(cOut, item, this.OutPIDConstants, this.Maximum, ControllerType.Cascade, PIDAction.Output); PIDModel outItem = cOut.Last(); item.P = outItem.P; item.I = outItem.I; item.D = outItem.D; item.DD = outItem.DD; item.OutDPV = outItem.DPV; item.OutDDPV = outItem.DDPV; item.Variation = outItem.Variation; this.OutCumulativeErr = cOut.CumulativeErr; this.InPIDConstants = cIn.PIDConstants; this.OutPIDConstants = cOut.PIDConstants; this[K] = item; }
private void Standardize(int k) { this.K = k; MultiCascadeModel item = this[K]; //输入部分 cIn = this.InitCollection(this.cIn, item, this.InPIDConstants, this.Maximum, ControllerType.MultiCascade, PIDAction.Input); PIDModel inItem = cIn.Last(); item.InP = inItem.P; item.InI = inItem.I; item.InD = inItem.D; item.InDD = inItem.DD; item.InDPV = inItem.DPV; item.InDDPV = inItem.DDPV; item.InVariation = inItem.Variation; //附加部分 if (this.AuxiliaryConstants != null) { for (int i = 0; i < this.AuxiliaryConstants.Count; i++) { PIDConstant ct = this.AuxiliaryConstants[i]; PIDCollection ac = this.cAcs[i]; PIDModel cam = item.AuxiliaryModels[i];//取附加PID模型 ac = this.InitCollection(ac, cam, ct, this.Maximum, ControllerType.Single, PIDAction.None); cam = ac.Last(); item.AuxiliaryModels[i] = cam; this.cAcs[i] = ac; } } //输出部分 cOut = this.InitCollection(this.cOut, item, this.OutPIDConstants, this.Maximum, ControllerType.MultiCascade, PIDAction.Output); PIDModel outItem = cOut.Last(); item.P = outItem.P; item.I = outItem.I; item.D = outItem.D; item.DD = outItem.DD; item.OutDPV = outItem.DPV; item.OutDDPV = outItem.DDPV; item.Variation = outItem.Variation; this.OutCumulativeErr = cOut.CumulativeErr; this.InPIDConstants = cIn.PIDConstants; this.OutPIDConstants = cOut.PIDConstants; this[K] = item; }
void TestSingle() { PIDConstant pidc = new PIDConstant(1, 1, 1); PIDCollection c = new PIDCollection(pidc); c.Maximum = 5; c.E = i => c[i].Err; PIDModel m1 = new PIDModel(50, 70); PIDModel m2 = new PIDModel(50, 60); PIDModel m3 = new PIDModel(50, 53); PIDModel m4 = new PIDModel(50, 49); PIDModel m5 = new PIDModel(50, 51); PIDModel m6 = new PIDModel(50, 48); PIDModel m7 = new PIDModel(50, 52); PIDModel m8 = new PIDModel(50, 51); PIDModel m9 = new PIDModel(50, 46); PIDModel m10 = new PIDModel(50, 52); PIDModel m11 = new PIDModel(50, 50.2); PIDModel m12 = new PIDModel(50, 49); PIDModel m13 = new PIDModel(50, 50.5); PIDModel m14 = new PIDModel(50, 49.2); c.Add(m1); c.Add(m2); c.Add(m3); c.Add(m4); c.Add(m5); c.Add(m6); c.Add(m7); c.Add(m8); c.Add(m9); c.Add(m10); c.Add(m11); c.Add(m12); c.Add(m13); c.Add(m14); //var v = from t in c // select t.Variation; //double s = v.Sum(); //c.Standardize(); }
private void Standardize(int k) { this.K = k; FurnaceModel item = this[K]; double inceaseVal = this.GetIncreaseValue(); item.InSV = item.InSV + inceaseVal; //输入部分 cIn = this.InitCollection(cIn, item, this.InPIDConstants, this.Maximum, ControllerType.Cascade, PIDAction.Input); PIDModel inItem = cIn.Last(); item.InP = inItem.P; item.InI = inItem.I; item.InD = inItem.D; item.InDD = inItem.DD; item.InDPV = inItem.DPV; item.InDDPV = inItem.DDPV; item.InVariation = inItem.Variation; this.InCumulativeErr = cIn.CumulativeErr; //输出部分 cOut = this.InitCollection(cOut, item, this.OutPIDConstants, this.Maximum, ControllerType.Cascade, PIDAction.Output); PIDModel outItem = cOut.Last(); item.P = outItem.P; item.I = outItem.I; item.D = outItem.D; item.DD = outItem.DD; item.OutDPV = outItem.DPV; item.OutDDPV = outItem.DDPV; item.Variation = outItem.Variation; this.OutCumulativeErr = cOut.CumulativeErr; this.InPIDConstants = cIn.PIDConstants; this.OutPIDConstants = cOut.PIDConstants; this[K] = item; this.FurnaceManage.LastUpdateTime = DateTime.Now; this.FurnaceManage.UpdateIndex++; }
private void Standardize(int k) { this.K = k; RadioModel item = this[K]; if (this.StrategySwitch) { bool pcheck = IsCheck(this.serialIndex, this.UpdateFrequency); //该轮是否进行检测 bool doStrategy = false; //UpdateFrequency为1时,不启用策略 if (this.UpdateFrequency == 1) { doStrategy = false; } else if (this.StrategyPeriod == StrategyPeriod.Rest) { //当前为休息周期,且进行检测 if (pcheck) { this.InitStrategy(); //满足条件,启用策略 if (this.StrategyEnable) { this.StrategyPeriod = StrategyPeriod.Running;//转换状态为运行 doStrategy = true; } //不满足条件,不启用策略,且保持休息周期状态 else { doStrategy = false; } } //当前为休息周期,且不进行检测 else { doStrategy = false; } } else if (this.StrategyPeriod == StrategyPeriod.Running) { //当前为运行周期,且进行检测 if (pcheck) { //紧邻运行周期的下一周期进行休息 this.StrategyPeriod = StrategyPeriod.Rest; this.StrategyObject = null; doStrategy = false; } //当前为运行周期,且不进行检测 else { doStrategy = true; } } if (pcheck) { //执行策略 if (doStrategy) { if (this.StrategyObject != null) { if (this.StrategyObject.Index < this.StrategyObject.ComputeCount) { item.SV = (this.StrategyObject.BasicValue + this.StrategyObject.Diff * (this.StrategyObject.Index + 1) / this.StrategyObject.ComputeCount) * item.UniFactor; } this.StrategyObject.GoNext(); } } else { item.SV = item.RPV * item.ScaleFactor * item.UniFactor; } } //不执行检测 else { if (this.K > 0) { item.SV = this[K - 1].SV; } else { item.SV = 0; } } } else { item.SV = item.RPV * item.ScaleFactor * item.UniFactor; } c = this.InitCollection(c, item, this.PIDConstants, this.Maximum, ControllerType.Radio, PIDAction.None); PIDModel nItem = c.Last(); item.P = nItem.P; item.I = nItem.I; item.D = nItem.D; item.DD = nItem.DD; item.DPV = nItem.DPV; item.DDPV = nItem.DDPV; item.Variation = nItem.Variation; this.CumulativeErr = c.CumulativeErr; this.PIDConstants = c.PIDConstants; this[K] = item; }
public PIDCollection InitCollection(PIDCollection c, PIDModel item, PIDConstant pidc, int maximum, ControllerType ct = ControllerType.Single, PIDAction action = PIDAction.None, double cumulativeErrRange = 0) { if (c == null) { c = new PIDCollection(pidc, item.Interval); } else { c.PIDConstants = pidc; c.Interval = item.Interval; } c.CumulativeErrRange = cumulativeErrRange; c.Maximum = maximum; c.E = i => c[i].Err; switch (ct) { case ControllerType.Single: PIDModel m = new PIDModel(item.SV, item.PV, item.Interval); c.Add(m); break; case ControllerType.Cascade: CascadePIDModel cm = item as CascadePIDModel; PIDModel m2 = null; if (action == PIDAction.Input) { m2 = new PIDModel(cm.InSV, cm.InPV, cm.Interval); } else if (action == PIDAction.Output) { m2 = new PIDModel(cm.OutSV, cm.OutPV, cm.Minimum, cm.Maximum, cm.Interval); } c.Add(m2); break; case ControllerType.MultiCascade: MultiCascadeModel mcm = item as MultiCascadeModel; PIDModel m3 = null; if (action == PIDAction.Input) { m3 = new PIDModel(mcm.InSV, mcm.InPV, mcm.Interval); } else if (action == PIDAction.Output) { m3 = new PIDModel(mcm.OutSV, mcm.OutPV, mcm.Minimum, mcm.Maximum, mcm.Interval); } c.Add(m3); break; case ControllerType.Feed: FeedModel fm = item as FeedModel; PIDModel m4 = null; if (action == PIDAction.Input) { m4 = new PIDModel(fm.InSV, fm.InPV, fm.Interval); } else if (action == PIDAction.Output) { m4 = new PIDModel(fm.OutSV + fm.CorrectionValue, fm.OutPV, fm.Minimum, fm.Maximum, fm.Interval); } c.Add(m4); break; case ControllerType.Radio: RadioModel rm = item as RadioModel; PIDModel m5 = new PIDModel(rm.SV + rm.CorrectionValue, rm.PV, rm.Interval); c.Add(m5); break; case ControllerType.ComplexRadio: ComplexRadioModel crm = item as ComplexRadioModel; PIDModel m6 = null; if (action == PIDAction.Input) { m6 = new PIDModel(crm.InSV, crm.InPV, crm.Interval); } else if (action == PIDAction.Output) { m6 = new PIDModel(crm.OutSV + crm.CorrectionValue, crm.OutPV, crm.Minimum, crm.Maximum, crm.Interval); } c.Add(m6); break; case ControllerType.Furnace: FurnaceModel fum = item as FurnaceModel; PIDModel m7 = null; if (action == PIDAction.Input) { m7 = new PIDModel(fum.InSV, fum.InPV, fum.Interval); } else if (action == PIDAction.Output) { m7 = new PIDModel(fum.OutSV, fum.OutPV, fum.Minimum, fum.Maximum, fum.Interval); } c.Add(m7); break; } return(c); }
private void Standardize(int k) { this.K = k; FeedModel item = this[K]; //输入部分 cIn = this.InitCollection(cIn, item, this.InPIDConstants, this.Maximum, ControllerType.Feed, PIDAction.Input, this.CumulativeErrRange); PIDModel inItem = cIn.Last(); item.InP = inItem.P; item.InI = inItem.I; item.InD = inItem.D; item.InDD = inItem.DD; item.InDPV = inItem.DPV; item.InDDPV = inItem.DDPV; item.InVariation = inItem.Variation; this.InCumulativeErr = cIn.CumulativeErr; //开关启动 if (this.StrategySwitch) { bool pcheck = IsCheck(this.serialIndex, this.UpdateFrequency); //该轮是否进行检测 bool doStrategy = false; //UpdateFrequency为1时,不启用策略 if (this.UpdateFrequency == 1) { doStrategy = false; } else if (this.StrategyPeriod == StrategyPeriod.Rest) { //当前为休息周期,且进行检测 if (pcheck) { this.InitStrategy(); //满足条件,启用策略 if (this.StrategyEnable) { this.StrategyPeriod = StrategyPeriod.Running;//转换状态为运行 doStrategy = true; } //不满足条件,不启用策略,且保持休息周期状态 else { doStrategy = false; } } //当前为休息周期,且不进行检测 else { doStrategy = false; } } else if (this.StrategyPeriod == StrategyPeriod.Running) { //当前为运行周期,且进行检测 if (pcheck) { //紧邻运行周期的下一周期进行休息 this.StrategyPeriod = StrategyPeriod.Rest; this.StrategyObject = null; doStrategy = false; } //当前为运行周期,且不进行检测 else { doStrategy = true; } } //执行检测 if (pcheck) { //执行策略 if (doStrategy) { if (this.StrategyObject != null) { if (this.StrategyObject.Index < this.StrategyObject.ComputeCount) { item.OutSV = cIn.CumulativeVariation + (this.StrategyObject.BasicValue + this.StrategyObject.Diff * (this.StrategyObject.Index + 1) / this.StrategyObject.ComputeCount) * item.UniFactor; } this.StrategyObject.GoNext(); } } else { item.OutSV = cIn.CumulativeVariation + item.DynamicPV * item.UniFactor; } } //不执行检测 else { if (this.K > 0) { item.OutSV = this[K - 1].OutSV; } else { item.OutSV = 0; } } } //开关未启动 else { item.OutSV = cIn.CumulativeVariation + item.DynamicPV * item.UniFactor; } //输出部分 cOut = this.InitCollection(cOut, item, this.OutPIDConstants, this.Maximum, ControllerType.Feed, PIDAction.Output); PIDModel outItem = cOut.Last(); item.P = outItem.P; item.I = outItem.I; item.D = outItem.D; item.DD = outItem.DD; item.OutDPV = outItem.DPV; item.OutDDPV = outItem.DDPV; item.Variation = outItem.Variation; this.OutCumulativeErr = cOut.CumulativeErr; this.InPIDConstants = cIn.PIDConstants; this.OutPIDConstants = cOut.PIDConstants; this[K] = item; }
private void Standardize(int k) { this.K = k; ComplexRadioModel item = this[K]; //输入部分 cIn = this.InitCollection(cIn, item, this.InPIDConstants, this.Maximum, ControllerType.ComplexRadio, PIDAction.Input, this.CumulativeErrRanges[0]); PIDModel inItem = cIn.Last(); item.InP = inItem.P; item.InI = inItem.I; item.InD = inItem.D; item.InDD = inItem.DD; item.InDPV = inItem.DPV; item.InDDPV = inItem.DDPV; item.InVariation = inItem.Variation; this.InCumulativeErr = cIn.CumulativeErr; //附加部分 if (this.AuxiliaryConstants != null) { for (int i = 0; i < this.AuxiliaryConstants.Count; i++) { PIDConstant ct = this.AuxiliaryConstants[i]; PIDCollection ac = this.cAcs[i]; PIDModel cam = item.AuxiliaryModels[i];//取附加PID模型 ac = this.InitCollection(ac, cam, ct, this.Maximum, ControllerType.Single, PIDAction.None, this.CumulativeErrRanges[i + 1]); cam = ac.Last(); item.AuxiliaryModels[i] = cam; this.cAcs[i] = ac; } } double axVals = 0;//附加输入回路计算变化量 if (item.AuxiliaryModels != null && item.AuxiliaryModels.Count > 0) { axVals = item.AuxiliaryModels.Sum(m => m.Variation); } //开关启动 if (this.StrategySwitch) { bool pcheck = IsCheck(this.serialIndex, this.UpdateFrequency); //该轮是否进行检测 bool doStrategy = false; //UpdateFrequency为1时,不启用策略 if (this.UpdateFrequency == 1) { doStrategy = false; } else if (this.StrategyPeriod == StrategyPeriod.Rest) { //当前为休息周期,且进行检测 if (pcheck) { this.InitStrategy(); //满足条件,启用策略 if (this.StrategyEnable) { this.StrategyPeriod = StrategyPeriod.Running;//转换状态为运行 doStrategy = true; } //不满足条件,不启用策略,且保持休息周期状态 else { doStrategy = false; } } //当前为休息周期,且不进行检测 else { doStrategy = false; } } else if (this.StrategyPeriod == StrategyPeriod.Running) { //当前为运行周期,且进行检测 if (pcheck) { //紧邻运行周期的下一周期进行休息 this.StrategyPeriod = StrategyPeriod.Rest; this.StrategyObject = null; doStrategy = false; } //当前为运行周期,且不进行检测 else { doStrategy = true; } } //执行检测 if (pcheck) { //执行策略 if (doStrategy) { if (this.StrategyObject != null) { if (this.StrategyObject.Index < this.StrategyObject.ComputeCount) { item.OutSV = cIn.CumulativeVariation + axVals + (this.StrategyObject.BasicValue + this.StrategyObject.Diff * (this.StrategyObject.Index + 1) / this.StrategyObject.ComputeCount) * item.UniFactor; } this.StrategyObject.GoNext(); } } else { item.OutSV = cIn.CumulativeVariation + axVals + item.RPV * item.ScaleFactor * item.UniFactor; } } //不执行检测 else { if (this.K > 0) { item.OutSV = this[K - 1].OutSV; } else { item.OutSV = 0; } } } //开关未启动 else { item.OutSV = cIn.CumulativeVariation + axVals + item.RPV * item.ScaleFactor * item.UniFactor; } //输出部分 cOut = this.InitCollection(cOut, item, this.OutPIDConstants, this.Maximum, ControllerType.ComplexRadio, PIDAction.Output); PIDModel outItem = cOut.Last(); item.P = outItem.P; item.I = outItem.I; item.D = outItem.D; item.DD = outItem.DD; item.OutDPV = outItem.DPV; item.OutDDPV = outItem.DDPV; item.Variation = outItem.Variation; this.OutCumulativeErr = cOut.CumulativeErr; this.InPIDConstants = cIn.PIDConstants; this.OutPIDConstants = cOut.PIDConstants; this[K] = item; }