Example 5 : Simulating a single PID-controller
In this example, a step disturbance influences a linear subprocess that is controlled by a PID-controller toward a constant setpoint of y=50
, like depicted in the below figure:
SubProcessSimulator.CoSimulateProcessAndPID
co-simulates a single PID-controller/processes combination such as this.
UnitParameters modelParameters = new UnitParameters
{
TimeConstant_s = 10,
LinearGains = new double[] { 1, 2 },
TimeDelay_s = 0,
Bias = 5
};
UnitModel processModel
= new UnitModel(modelParameters, "SubProcess1");
var pidParameters = new PidParameters()
{
Kp = 0.5,
Ti_s = 20
};
var pidModel = new PidModel(pidParameters, "PID1");
var sim = new PlantSimulator(
new List<ISimulatableModel> { processModel, pidModel });
sim.ConnectModels(processModel, pidModel);
sim.ConnectModels(pidModel, processModel, (int)INDEX.FIRST);
// create synthetic input data (normally you would get this data from the real-world)
double timeBase_s = 1;
int N = 500;
var inputData = new TimeSeriesDataSet();
inputData.Add(sim.AddExternalSignal(pidModel, SignalType.Setpoint_Yset),
TimeSeriesCreator.Constant(50, N));
inputData.Add(sim.AddExternalSignal(processModel, SignalType.External_U, (int)INDEX.SECOND),
TimeSeriesCreator.Step(N / 2, N, 0, 1));
inputData.CreateTimestamps(timeBase_s,N);
// simulate model over the
var isOk = sim.Simulate(inputData, out var simData);
// plot result
Shared.EnablePlots();
Plot.FromList(new List<double[]> {
simData.GetValues(processModel.GetID(),SignalType.Output_Y),
inputData.GetValues(processModel.GetID(),SignalType.External_U,(int)INDEX.SECOND),
simData.GetValues(pidModel.GetID(),SignalType.PID_U)
},
new List<string> { "y1=y_sim", "y2=u_external", "y3=u_pid" },
timeBase_s, "ex5_results");
Shared.DisablePlots();
The resulting dynamic simulation:
Note that the PID-controller is able to bring the subprocess back to the setpoint despite the disturbance.
The initial fast response of the proportional term Kp
is seen in the plot of u_pid
, followed by the gradual
influence of the integral term Ti_s
, as is expected.
Note
SubProcessSimulator
ensures that the PID/model combination starts in steady-state, so there is no bump
or transient in the
start of the dataset.
Note
Normally in industrial settings, PID-controllers are scaled, scaling information can be included by the inputting a PIDscaling
to the
PIDModelParameters
object on initialization.
Note
CoSimulateProcessAndPID
is only intended for simple single-input/single-output pid/model systems. For more general simulation, use ProcessSimulator
class.