From 598133577f55d30e5904dc130b368e53167915bb Mon Sep 17 00:00:00 2001 From: Huang <7q0@ornl.gov> Date: Thu, 14 Dec 2023 21:57:01 -0500 Subject: [PATCH 1/6] fix the model doc --- .../PIDWithAutotuning/Relay/Controller.mo | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo index b5ae105e3f5..342225573d8 100644 --- a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo +++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo @@ -49,7 +49,7 @@ protected final k=-yLow) "Lower value for the output" annotation (Placement(transformation(extent={{-80,20},{-60,40}}))); - Buildings.Controls.OBC.CDL.Reals.Subtract conErr +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 @@ -57,16 +57,16 @@ protected 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" 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" @@ -86,9 +86,9 @@ equation 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})); +color={0,0,127})); connect(conErr.y, yErr) annotation (Line(points={{62,10},{120,10}}, - color={0,0,127})); + color={0,0,127})); connect(swi1.u3, u_s) annotation (Line(points={{-62,-68},{-90,-68},{-90,0},{ -120,0}}, color={0,0,127})); @@ -98,7 +98,7 @@ equation 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, + 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}}, @@ -131,7 +131,7 @@ equation connect(hys.y, yOn) annotation (Line(points={{62,-50},{80,-50},{80,-60},{120, -60}}, color={255,0,255})); - annotation (defaultComponentName = "relCon", + annotation (defaultComponentName = "relCon", Icon(coordinateSystem(preserveAspectRatio=false), graphics={ Rectangle( extent={{-100,-100},{100,100}}, @@ -164,21 +164,25 @@ 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="
This block generates a real control output y
, a
-boolean relay switch output yOn
, and the control error
+boolean relay switch output yOn
, a input difference
+yDif
, and the control error
yErr
. They are calculated as below:
yErr = u_s - u_m
,
+reverseActing = false
yErr = u_m - u_s
,
+yDif = - yErr
,
reverseActing = false
else
yErr = u_s - u_m
,
+yDif = yErr
,
yErr < -deaBan
and trigger
is true
,
+if yDif < -deaBan
and trigger
is true
,
then y = yHig
, yOn = true
,
yErr > deaBan
and trigger
is true
,
+else if yDif > deaBan
and trigger
is true
,
then y = -yLow
,
yOn = false
,
This block generates a real control output y
, a
-boolean relay switch output yOn
, a input difference
-yDif
, and the control error
+boolean relay switch output yOn
, an input difference
+yDif
, and a control error
yErr
. They are calculated as below:
yErr = u_s - u_m
,
+yErr = u_m - u_s
,
reverseActing = false
+if the parameter reverseActing = true
yDif = - yErr
,
From bf463d90a6e65e4d04b138b86a04b0a2efd48b2c Mon Sep 17 00:00:00 2001
From: Huang <7q0@ornl.gov>
Date: Fri, 15 Dec 2023 09:19:20 -0500
Subject: [PATCH 4/6] remove extra space
---
.../OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo
index 7a7e9525dcb..619d2071d18 100644
--- a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo
+++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo
@@ -121,8 +121,7 @@ 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}));
+ -60}},color={255,0,255}));
annotation (defaultComponentName = "relCon",
Icon(coordinateSystem(preserveAspectRatio=false), graphics={
Rectangle(
From e9cab007d0ddbd2c9a82af2e11de313cecdee954 Mon Sep 17 00:00:00 2001
From: Huang <7q0@ornl.gov>
Date: Fri, 15 Dec 2023 15:57:50 -0500
Subject: [PATCH 5/6] correct the definition of control error
---
.../PIDWithAutotuning/FirstOrderAMIGO.mo | 7 ++--
.../PIDWithAutotuning/Relay/Controller.mo | 37 +++++++------------
.../FirstOrderTimedelayed/BaseClasses/Gain.mo | 33 +++++++++++++----
.../BaseClasses/Validation/Gain.mo | 2 +-
.../ControlProcessModel.mo | 5 ++-
.../Validation/ControlProcessModel.mo | 3 +-
6 files changed, 50 insertions(+), 37 deletions(-)
diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/FirstOrderAMIGO.mo b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/FirstOrderAMIGO.mo
index 1345d4bbc09..9cf8136dc42 100644
--- a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/FirstOrderAMIGO.mo
+++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/FirstOrderAMIGO.mo
@@ -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}));
diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo
index 619d2071d18..20946ace0d4 100644
--- a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo
+++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Controller.mo
@@ -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,9 +48,6 @@ 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 (measurement - set point)"
- 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}},
@@ -63,7 +59,7 @@ protected
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 for direct acting"
@@ -86,18 +82,12 @@ equation
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}));
connect(swi1.u3, u_s) annotation (Line(points={{-62,-68},{-90,-68},{-90,0},{
-120,0}},color={0,0,127}));
connect(trigger, swi1.u2) annotation (Line(points={{-80,-120},{-80,-60},{-62,
-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}));
connect(sub1.y, hys.u) annotation (Line(points={{22,-70},{30,-70},{30,-50},{
38,-50}},color={0,0,127}));
connect(sub.y, hys.u) annotation (Line(points={{22,-40},{30,-40},{30,-50},{38,
@@ -122,6 +112,10 @@ equation
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}));
+ 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(
@@ -161,19 +155,16 @@ equation
Documentation(info="
This block generates a real control output y
, a
-boolean relay switch output yOn
, an input difference
-yDif
, and a control error
-yErr
. They are calculated as below:
+boolean relay switch output yOn
,
+and an input difference yDiff
.
+They are calculated as below:
yErr = u_m - u_s
,
-reverseActing = true
yDif = - yErr
,
+yDiff = u_s - u_m
,
reverseActing = true
else
yDif = yErr
,
+yDiff = u_m - u_s
,
yDif < -deaBan
and trigger
is true
,
+if yDiff > deaBan
and trigger
is true
,
then y = yHig
, yOn = true
,
yDif > deaBan
and trigger
is true
,
+else if yDiff < -deaBan
and trigger
is true
,
then y = -yLow
,
yOn = false
,
Iy is calculated by
-Iy = ∫ u(t) dt;
-where u is the process output.
+Iy = ∫ -u(t) dt;
+where u is the input difference of a relay controller, see details in +Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.Controller +
Iu is calculated by
Iu = ton (yhig - yref)+ toff(-ylow - yref), diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/SystemIdentification/FirstOrderTimedelayed/BaseClasses/Validation/Gain.mo b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/SystemIdentification/FirstOrderTimedelayed/BaseClasses/Validation/Gain.mo index d4251ecb888..fff0e1f3aed 100644 --- a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/SystemIdentification/FirstOrderTimedelayed/BaseClasses/Validation/Gain.mo +++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/SystemIdentification/FirstOrderTimedelayed/BaseClasses/Validation/Gain.mo @@ -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( diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/SystemIdentification/FirstOrderTimedelayed/ControlProcessModel.mo b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/SystemIdentification/FirstOrderTimedelayed/ControlProcessModel.mo index b4c1497b8ae..89667f4c95a 100644 --- a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/SystemIdentification/FirstOrderTimedelayed/ControlProcessModel.mo +++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/SystemIdentification/FirstOrderTimedelayed/ControlProcessModel.mo @@ -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 diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/SystemIdentification/FirstOrderTimedelayed/Validation/ControlProcessModel.mo b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/SystemIdentification/FirstOrderTimedelayed/Validation/ControlProcessModel.mo index 08a1f4072b8..420c309fca4 100644 --- a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/SystemIdentification/FirstOrderTimedelayed/Validation/ControlProcessModel.mo +++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/SystemIdentification/FirstOrderTimedelayed/Validation/ControlProcessModel.mo @@ -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( From 8f68c8c0d2b216914515a315f2d8ef80e15f15d4 Mon Sep 17 00:00:00 2001 From: Huang <7q0@ornl.gov> Date: Fri, 15 Dec 2023 15:58:41 -0500 Subject: [PATCH 6/6] plot script and ref data update --- .../Utilities/PIDWithAutotuning/Relay/Validation/Controller.mos | 2 +- ....Utilities.PIDWithAutotuning.Relay.Validation.Controller.mos | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Buildings/Resources/Scripts/Dymola/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Validation/Controller.mos b/Buildings/Resources/Scripts/Dymola/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Validation/Controller.mos index ec5423133e8..b40e52e278a 100644 --- a/Buildings/Resources/Scripts/Dymola/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Validation/Controller.mos +++ b/Buildings/Resources/Scripts/Dymola/Controls/OBC/Utilities/PIDWithAutotuning/Relay/Validation/Controller.mos @@ -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}}); \ No newline at end of file +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}}); \ No newline at end of file diff --git a/Buildings/Resources/Scripts/OpenModelica/compareVars/Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.Validation.Controller.mos b/Buildings/Resources/Scripts/OpenModelica/compareVars/Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.Validation.Controller.mos index 39f12c5b1e3..bf63a686995 100644 --- a/Buildings/Resources/Scripts/OpenModelica/compareVars/Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.Validation.Controller.mos +++ b/Buildings/Resources/Scripts/OpenModelica/compareVars/Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Relay.Validation.Controller.mos @@ -3,6 +3,6 @@ compareVars := "relCon.u_m", "enaSig.y", "relCon.y", - "relCon.yErr", + "relCon.yDiff", "relCon.yOn" };