Skip to content

Commit

Permalink
Merge pull request #3609 from SenHuang19/issue2884_PID_autotuning
Browse files Browse the repository at this point in the history
Issue2884 pid autotuning
  • Loading branch information
JayHuLBL authored Dec 15, 2023
2 parents faa2108 + 8f68c8c commit f367eb8
Showing 8 changed files with 68 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -116,7 +116,8 @@ block FirstOrderAMIGO
conProMod(
final yHig=yHig - yRef,
final yLow=yRef + yLow,
final deaBan=deaBan)
final deaBan=deaBan,
final reverseActing=reverseActing)
"Calculates the parameters of a first-order time delayed model"
annotation (Placement(transformation(extent={{40,30},{60,50}})));
Buildings.Controls.OBC.CDL.Logical.Latch inTunPro
@@ -179,8 +180,8 @@ equation
{30,44},{22,44}},color={0,0,127}));
connect(resPro.tOn, conProMod.tOn) annotation (Line(points={{22,48},{32,48},{32,
44},{38,44}},color={0,0,127}));
connect(rel.yErr, conProMod.u) annotation (Line(points={{-18,40},{-12,40},{-12,
60},{34,60},{34,48},{38,48}},color={0,0,127}));
connect(rel.yDiff, conProMod.u) annotation (Line(points={{-18,40},{-12,40},{-12,
60},{34,60},{34,48},{38,48}}, color={0,0,127}));
connect(PIDPar.kp, conProMod.k) annotation (Line(points={{78,46},{62,46}}, color={0,0,127}));
connect(PIDPar.T, conProMod.T) annotation (Line(points={{78,40},{62,40}}, color={0,0,127}));
connect(PIDPar.L, conProMod.L) annotation (Line(points={{78,34},{62,34}}, color={0,0,127}));
Original file line number Diff line number Diff line change
@@ -32,10 +32,9 @@ block Controller
Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput yOn
"Relay switch output, true when control output switches to the higher value"
annotation (Placement(transformation(extent={{100,-80},{140,-40}})));
Buildings.Controls.OBC.CDL.Interfaces.RealOutput yErr
"Control error"
Buildings.Controls.OBC.CDL.Interfaces.RealOutput yDiff "Input difference"
annotation (Placement(transformation(extent={{100,-10},{140,30}}),
iconTransformation(extent={{100,-20},{140,20}})));
iconTransformation(extent={{100,-20},{140,20}})));

protected
Buildings.Controls.OBC.CDL.Reals.Switch swi
@@ -49,24 +48,21 @@ protected
final k=-yLow)
"Lower value for the output"
annotation (Placement(transformation(extent={{-80,20},{-60,40}})));
Buildings.Controls.OBC.CDL.Reals.Subtract conErr
"Control error (set point - measurement)"
annotation (Placement(transformation(extent={{40,0},{60,20}})));
Buildings.Controls.OBC.CDL.Reals.Switch swi1
"Switch between a higher value and a lower value"
annotation (Placement(transformation(extent={{-10,-10},{10,10}},
origin={-50,-60})));
Buildings.Controls.OBC.CDL.Reals.Subtract sub
if reverseActing "Inputs difference"
if reverseActing "Inputs difference for reverse acting"
annotation (Placement(transformation(extent={{0,-50},{20,-30}})));
Buildings.Controls.OBC.CDL.Reals.Hysteresis hys(
final uLow=-deaBa,
final uHigh=deaBa,
final uLow=-deaBan,
final uHigh=deaBan,
final pre_y_start=true)
"Check if the measured value is larger than the reference, by default the relay control is on"
"Check if the input difference exceeds the thresholds, by default the relay control is on"
annotation (Placement(transformation(extent={{40,-60},{60,-40}})));
Buildings.Controls.OBC.CDL.Reals.Subtract sub1
if not reverseActing "Inputs difference"
if not reverseActing "Inputs difference for direct acting"
annotation (Placement(transformation(extent={{0,-80},{20,-60}})));
Buildings.Controls.OBC.CDL.Reals.Greater gre
"Check if the higher value is greater than the lower value"
@@ -85,39 +81,25 @@ equation
connect(higVal.y, swi.u1)
annotation (Line(points={{-58,80},{-20,80},{-20,58},{58,58}},color={0,0,127}));
connect(lowVal.y, swi.u3) annotation (Line(points={{-58,30},{-20,30},{-20,42},
{58,42}},
color={0,0,127}));
connect(conErr.y, yErr) annotation (Line(points={{62,10},{120,10}},
color={0,0,127}));
{58,42}},color={0,0,127}));
connect(swi1.u3, u_s) annotation (Line(points={{-62,-68},{-90,-68},{-90,0},{
-120,0}},
color={0,0,127}));
-120,0}},color={0,0,127}));
connect(trigger, swi1.u2) annotation (Line(points={{-80,-120},{-80,-60},{-62,
-60}},
color={255,0,255}));
-60}},color={255,0,255}));
connect(u_m, swi1.u1) annotation (Line(points={{0,-120},{0,-90},{-70,-90},{
-70,-52},{-62,-52}},
color={0,0,127}));
connect(swi1.y, conErr.u1) annotation (Line(points={{-38,-60},{-20,-60},{-20,
16},{38,16}}, color={0,0,127}));
connect(conErr.u2, u_s) annotation (Line(points={{38,4},{-42,4},{-42,0},{
-120,0}},
color={0,0,127}));
-70,-52},{-62,-52}},color={0,0,127}));
connect(sub1.y, hys.u) annotation (Line(points={{22,-70},{30,-70},{30,-50},{
38,-50}},
color={0,0,127}));
38,-50}},color={0,0,127}));
connect(sub.y, hys.u) annotation (Line(points={{22,-40},{30,-40},{30,-50},{38,
-50}}, color={0,0,127}));
connect(u_s, sub.u1) annotation (Line(points={{-120,0},{-90,0},{-90,-34},{-2,
-34}},
color={0,0,127}));
-34}},color={0,0,127}));
connect(u_s, sub1.u2) annotation (Line(points={{-120,0},{-90,0},{-90,-76},{-2,
-76}}, color={0,0,127}));
connect(swi1.y, sub.u2) annotation (Line(points={{-38,-60},{-20,-60},{-20,-46},
{-2,-46}}, color={0,0,127}));
connect(swi1.y, sub1.u1) annotation (Line(points={{-38,-60},{-20,-60},{-20,
-64},{-2,-64}},
color={0,0,127}));
-64},{-2,-64}},color={0,0,127}));
connect(hys.y, swi.u2) annotation (Line(points={{62,-50},{80,-50},{80,30},{50,
30},{50,50},{58,50}}, color={255,0,255}));
connect(gre.y, assMes.u)
@@ -129,9 +111,12 @@ equation
connect(higVal.y, gre.u1)
annotation (Line(points={{-58,80},{-2,80}}, color={0,0,127}));
connect(hys.y, yOn) annotation (Line(points={{62,-50},{80,-50},{80,-60},{120,
-60}},
color={255,0,255}));
annotation (defaultComponentName = "relCon",
-60}},color={255,0,255}));
connect(yDiff, sub.y) annotation (Line(points={{120,10},{36,10},{36,-40},{22,
-40}}, color={0,0,127}));
connect(sub1.y, yDiff) annotation (Line(points={{22,-70},{36,-70},{36,10},{
120,10}}, color={0,0,127}));
annotation (defaultComponentName = "relCon",
Icon(coordinateSystem(preserveAspectRatio=false), graphics={
Rectangle(
extent={{-100,-100},{100,100}},
@@ -164,38 +149,39 @@ equation
fillPattern=FillPattern.Solid,
fillColor={175,175,175},
textString="Relay"),
Line(points={{-70,24},{-34,24},{-34,58},{38,58},{38,24},{66,24}}, color
={28,108,200})}), Diagram(
Line(points={{-70,24},{-34,24},{-34,58},{38,58},{38,24},{66,24}}, color=
{28,108,200})}), Diagram(
coordinateSystem(preserveAspectRatio=false)),
Documentation(info="<html>
<p>
This block generates a real control output <code>y</code>, a
boolean relay switch output <code>yOn</code>, and the control error
<code>yErr</code>. They are calculated as below:
boolean relay switch output <code>yOn</code>,
and an input difference <code>yDiff</code>.
They are calculated as below:
</p>
<ul>
<li>
if the parameter <code>reverseActing = false</code>
if the parameter <code>reverseActing = true</code>
<ul>
<li>
<code>yErr = u_m - u_s</code>,
<code>yDiff = u_s - u_m</code>,
</li>
</ul>
</li>
<li>
else
<ul>
<li>
<code>yErr = u_s - u_m </code>,
<code>yDiff = u_m - u_s</code>,
</li>
</ul>
</li>
<li>
if <code>yErr &lt; -deaBan</code> and <code>trigger</code> is <code>true</code>,
if <code>yDiff &gt; deaBan</code> and <code>trigger</code> is <code>true</code>,
then <code>y = yHig</code>, <code>yOn = true</code>,
</li>
<li>
else if <code>yErr &gt; deaBan</code> and <code>trigger</code> is <code>true</code>,
else if <code>yDiff &lt; -deaBan</code> and <code>trigger</code> is <code>true</code>,
then <code>y = -yLow</code>,
<code>yOn = false</code>,
</li>
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@ block Gain "Identify the gain of a first order time delayed model"
"Higher value for the output (assuming the reference output is 0)";
parameter Real yLow(min=1E-6) = 0.5
"Lower value for the output (assuming the reference output is 0)";
parameter Boolean reverseActing=true
"Set to true for reverse acting, or false for direct acting control action";
Buildings.Controls.OBC.CDL.Interfaces.RealInput u
"Relay controller output"
annotation (Placement(transformation(extent={{-140,20},{-100,60}}),
@@ -39,7 +41,7 @@ protected
annotation (Placement(transformation(extent={{-10,30},{10,50}})));
Buildings.Controls.OBC.CDL.Reals.Sources.Constant refRelOut(
final k=0) "Reference value of the relay control output"
annotation (Placement(transformation(extent={{-60,10},{-40,30}})));
annotation (Placement(transformation(extent={{-60,-10},{-40,10}})));
Buildings.Controls.OBC.CDL.Reals.Divide divIyIu "Calculate the gain"
annotation (Placement(transformation(extent={{40,-10},{60,10}})));
Buildings.Controls.OBC.CDL.Reals.AddParameter addPar(final p=1E-3)
@@ -53,12 +55,17 @@ protected
final k=-yLow)
"Product of tOff and yLow"
annotation (Placement(transformation(extent={{-80,-90},{-60,-70}})));

Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai1(final k=-1)
if reverseActing
"Negative sign for reverse acting"
annotation (Placement(transformation(extent={{-60,70},{-40,90}})));
Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter gai2(final k=1)
if not reverseActing
"Positive sign for direct acting"
annotation (Placement(transformation(extent={{-60,30},{-40,50}})));
equation
connect(Iy.u, u) annotation (Line(points={{-12,40},{-120,40}},
color={0,0,127}));
connect(refRelOut.y, Iy.y_reset_in) annotation (Line(points={{-38,20},{-20,20},
{-20,32},{-12,32}}, color={0,0,127}));
connect(refRelOut.y, Iy.y_reset_in) annotation (Line(points={{-38,0},{-20,0},{
-20,32},{-12,32}}, color={0,0,127}));
connect(Iy.trigger, triSta) annotation (Line(points={{0,28},{0,-120}},
color={255,0,255}));
connect(divIyIu.u1, Iy.y) annotation (Line(points={{38,6},{18,6},{18,40},{12,
@@ -76,6 +83,14 @@ equation
-46},{-42,-46}}, color={0,0,127}));
connect(divIyIu.y, k)
annotation (Line(points={{62,0},{120,0}}, color={0,0,127}));
connect(gai2.u, u)
annotation (Line(points={{-62,40},{-120,40}}, color={0,0,127}));
connect(gai2.y, Iy.u)
annotation (Line(points={{-38,40},{-12,40}}, color={0,0,127}));
connect(gai1.y, Iy.u) annotation (Line(points={{-38,80},{-20,80},{-20,40},{
-12,40}}, color={0,0,127}));
connect(gai1.u, u) annotation (Line(points={{-62,80},{-80,80},{-80,40},{-120,
40}}, color={0,0,127}));
annotation (
defaultComponentName = "gai",
Icon(coordinateSystem(preserveAspectRatio=false), graphics={
@@ -106,8 +121,10 @@ where <i>I<sub>y</sub></i> and <i>I<sub>u</sub></i> are the integral of the proc
output and the integral of the relay output, respectively.
</p>
<p><i>I<sub>y</sub></i> is calculated by </p>
<p>I<sub>y</sub> = &int; u(t) dt;</p>
<p>where <i>u</i> is the process output.</p>
<p>I<sub>y</sub> = &int; -u(t) dt;</p>
<p>where <i>u</i> is the input difference of a relay controller, see details in <a href=\"modelica://Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.Controller\">
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.Controller</a>
</p>
<p><i>I<sub>u</sub></i> is calculated by </p>
<p align=\"center\" style=\"font-style:italic;\">
I<sub>u</sub> = t<sub>on</sub> (y<sub>hig</sub> - y<sub>ref</sub>)+ t<sub>off</sub>(-y<sub>low</sub> - y<sub>ref</sub>),
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
within Buildings.Controls.OBC.Utilities.PIDWithAutotuning.SystemIdentification.FirstOrderTimedelayed.BaseClasses.Validation;
model Gain "Test model for identifying the gain of the control process"
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.SystemIdentification.FirstOrderTimedelayed.BaseClasses.Gain
gai
gai(reverseActing=false)
"Block that calculates the gain of a first-order model"
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
Buildings.Controls.OBC.CDL.Reals.Sources.Pulse u(
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ block ControlProcessModel
"Lower value for the output";
parameter Real deaBan(min=0) = 0.5
"Deadband for holding the output value";
parameter Boolean reverseActing=true
"Set to true for reverse acting, or false for direct acting control action";
Buildings.Controls.OBC.CDL.Interfaces.RealInput tOn(
final quantity="Time",
final unit="s",
@@ -74,7 +76,8 @@ protected
annotation (Placement(transformation(extent={{12,-30},{32,-10}})));
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.SystemIdentification.FirstOrderTimedelayed.BaseClasses.Gain gain(
final yHig=yHig,
final yLow=yLow)
final yLow=yLow,
final reverseActing = reverseActing)
"Block that calculates the gain"
annotation (Placement(transformation(extent={{-84,10},{-64,30}})));
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.SystemIdentification.FirstOrderTimedelayed.BaseClasses.TimeConstantDelay
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@ within Buildings.Controls.OBC.Utilities.PIDWithAutotuning.SystemIdentification.F
model ControlProcessModel
"Test model for identifying the reduced-order model of the control process"
Buildings.Controls.OBC.Utilities.PIDWithAutotuning.SystemIdentification.FirstOrderTimedelayed.ControlProcessModel
conProMod(yLow=0.1, deaBan=0.05)
conProMod(yLow=0.1, deaBan=0.05,
reverseActing=false)
"Calculate the parameters of a first-order model"
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
Buildings.Controls.OBC.CDL.Reals.Sources.Pulse u(
Original file line number Diff line number Diff line change
@@ -4,4 +4,4 @@ plotExpression(apply(Controller[end].relCon.u_s-0.4), false, "controller[end].re
plotExpression(apply(Controller[end].relCon.u_s+0.4), false, "controller[end].relCon.u_s+deaBan", 1);
createPlot(id=1, position={15, 15, 1148, 620}, y={"enaSig.y"}, range={0.0, 1.0, -1.0, 2.0}, grid=true, subPlot=102, colors={{28,108,200}});
createPlot(id=1, position={15, 15, 1148, 620}, y={"relCon.y"}, range={0.0, 1.0, -2.0, 2.0}, grid=true, subPlot=103, colors={{28,108,200}});
createPlot(id=1, position={15, 15, 1148, 620}, y={"relCon.yErr", "relCon.yOn"}, range={0.0, 1.0, -2.0, 2.0}, grid=true, subPlot=104, colors={{28,108,200}, {238,46,47}});
createPlot(id=1, position={15, 15, 1148, 620}, y={"relCon.yDiff", "relCon.yOn"}, range={0.0, 1.0, -2.0, 2.0}, grid=true, subPlot=104, colors={{28,108,200}, {238,46,47}});
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@ compareVars :=
"relCon.u_m",
"enaSig.y",
"relCon.y",
"relCon.yErr",
"relCon.yDiff",
"relCon.yOn"
};

0 comments on commit f367eb8

Please sign in to comment.