Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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;
        }
        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;
        }