diff --git a/Dynamic/Identification/ClosedLoopUnitIdentifier.cs b/Dynamic/Identification/ClosedLoopUnitIdentifier.cs index 2dad165..4b1c6d8 100644 --- a/Dynamic/Identification/ClosedLoopUnitIdentifier.cs +++ b/Dynamic/Identification/ClosedLoopUnitIdentifier.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Diagnostics; using System.Globalization; using System.Linq; using System.Net; @@ -125,6 +126,14 @@ public static (UnitModel, double[]) Identify(UnitDataSet dataSet, PidParameters if (doConsoleDebugOut) Console.WriteLine("Step1: " + unitModel_step1.GetModelParameters().LinearGains.ElementAt(pidInputIdx).ToString("F3", CultureInfo.InvariantCulture)); + // var KPest = EstimateDisturbanceLF(dataSetRun1, unitModel_step1, pidInputIdx, pidParams); + // if (doConsoleDebugOut) + // Console.WriteLine("experimental: " + KPest); + + + + + // run1: ident (attempt to identify any other inputs) if (isMISO) { @@ -473,6 +482,51 @@ public static (UnitModel, double[]) Identify(UnitDataSet dataSet, PidParameters } + private static double EstimateDisturbanceLF(UnitDataSet dataSet, UnitModel unitModel, int pidInputIdx, PidParameters pidParams) + { + var vec = new Vec(dataSet.BadDataID); + + var umInternal = (UnitModel)unitModel.Clone(); + var d_HF = vec.Subtract(dataSet.Y_meas, dataSet.Y_setpoint); + var unitParams = umInternal.GetModelParameters(); + + var dList = new List(); + var nameList = new List(); + dList.Add(d_HF); + nameList.Add("y1=dHF"); + + var dHF_energy = vec.Mean(d_HF).Value; + for (double Kp = 0.5; Kp < 5.6; Kp += 0.5) + { + unitParams.LinearGains = new double[] { Kp }; + umInternal.SetModelParameters(unitParams); + (var isOk, var y_proc) = PlantSimulator.SimulateSingle(dataSet, umInternal, false); + var d_LF = vec.Multiply(vec.Subtract(y_proc, y_proc[0]), -1); + var d_est1 = vec.Add(d_HF, d_LF); + var d_est2 = vec.Subtract(dataSet.Y_meas, y_proc); + dList.Add(d_est2); + nameList.Add("y1=destKp"+Kp.ToString("F2",CultureInfo.InvariantCulture)); + var dLF_energy = vec.Mean(d_LF).Value; + + + + Debug.WriteLine("Kp="+Kp.ToString("F2", CultureInfo.InvariantCulture) + "dLFenergy:"+ dLF_energy.ToString("F2", CultureInfo.InvariantCulture) + + "dHFenergy" +dHF_energy.ToString("F2", CultureInfo.InvariantCulture)) ; + + // if the energy of t + + } + + Shared.EnablePlots(); + Plot.FromList(dList, nameList,dataSet.GetTimeBase(), "exp_Kp"); + Shared.DisablePlots(); + + + + + return 0; + } + /// /// tries N=numberOfGlobalSearchIterations process gains of the unitModel in the range[minPidProcessGain,maxPidProcessGain], using a closed-loop simulation /// that includes the PID-model with paramters pidParams that acts on input pidInputIdx of the unit model.