Skip to content

Commit

Permalink
- experimenting CLUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Steinar Elgsæter committed Dec 12, 2024
1 parent b81d968 commit 4b579aa
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Dynamic/Identification/ClosedLoopUnitIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<double[]>();
var nameList = new List<string>();
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;
}

/// <summary>
/// tries <c>N=numberOfGlobalSearchIterations</c> process gains of the <c>unitModel</c> in the range[minPidProcessGain,maxPidProcessGain], using a closed-loop simulation
/// that includes the PID-model with paramters pidParams that acts on input <c>pidInputIdx</c> of the unit model.
Expand Down

0 comments on commit 4b579aa

Please sign in to comment.