From fc329738a7453b3e8eafe1180cf3a734cf3657bc Mon Sep 17 00:00:00 2001 From: JayHuLBL Date: Fri, 18 Aug 2023 15:16:02 -0700 Subject: [PATCH] added controller type --- .../PIDWithAutotuning/FirstOrderAMIGO.mo | 38 +++++++++---------- .../Types/SimpleController.mo | 33 ++++++++++++++++ .../PIDWithAutotuning/Types/package.mo | 37 ++++++++++++++++++ .../PIDWithAutotuning/Types/package.order | 1 + .../Validation/PIDWithFirstOrderAMIGO.mo | 2 +- .../Validation/PIWithFirstOrderAMIGO.mo | 6 +-- .../Utilities/PIDWithAutotuning/package.order | 1 + 7 files changed, 95 insertions(+), 23 deletions(-) create mode 100644 Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Types/SimpleController.mo create mode 100644 Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Types/package.mo create mode 100644 Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Types/package.order diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/FirstOrderAMIGO.mo b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/FirstOrderAMIGO.mo index 0f4565fdb0c..e5600f14c3b 100644 --- a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/FirstOrderAMIGO.mo +++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/FirstOrderAMIGO.mo @@ -1,7 +1,7 @@ within Buildings.Controls.OBC.Utilities.PIDWithAutotuning; block FirstOrderAMIGO "An autotuning PID controller with an AMIGO tuner that employs a first-order time delayed system model" - parameter Buildings.Controls.OBC.CDL.Types.SimpleController controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI + parameter Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController controllerType=Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController.PI "Type of controller"; parameter Real r( min=100*CDL.Constants.eps)=1 @@ -15,22 +15,22 @@ block FirstOrderAMIGO parameter Real Ni( min=100*CDL.Constants.eps)=0.9 "Ni*Ti is time constant of anti-windup compensation" - annotation (Dialog(tab="Advanced",group="Integrator anti-windup",enable=controllerType == CDL.Types.SimpleController.PI or controllerType ==CDL.Types.SimpleController.PID)); + annotation (Dialog(tab="Advanced",group="Integrator anti-windup")); parameter Real Nd( min=100*CDL.Constants.eps)=10 "The higher Nd, the more ideal the derivative block" - annotation (Dialog(tab="Advanced",group="Derivative block",enable=controllerType == CDL.Types.SimpleController.PD or controllerType ==CDL.Types.SimpleController.PID)); + annotation (Dialog(tab="Advanced",group="Derivative block",enable=controllerType ==Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController.PID)); parameter Real xi_start=0 "Initial value of integrator state" - annotation (Dialog(tab="Advanced",group="Initialization",enable=controllerType == CDL.Types.SimpleController.PI or controllerType == CDL.Types.SimpleController.PID)); + annotation (Dialog(tab="Advanced",group="Initialization")); parameter Real yd_start=0 "Initial value of derivative output" - annotation (Dialog(tab="Advanced",group="Initialization",enable=controllerType == CDL.Types.SimpleController.PD or controllerType == CDL.Types.SimpleController.PID)); + annotation (Dialog(tab="Advanced",group="Initialization",enable=controllerType == Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController.PID)); parameter Boolean reverseActing=true "Set to true for reverse acting, or false for direct acting control action"; parameter Real y_reset=xi_start "Value to which the controller output is reset if the boolean trigger has a rising edge" - annotation (Dialog(enable=controllerType == CDL.Types.SimpleController.PI or controllerType == CDL.Types.SimpleController.PID,group="Integrator reset")); + annotation (Dialog(group="Integrator reset")); Buildings.Controls.OBC.CDL.Interfaces.RealInput u_s "Connector of setpoint input signal" @@ -54,7 +54,7 @@ block FirstOrderAMIGO "Simulation time" annotation (Placement(transformation(extent={{80,60},{60,80}}))); Buildings.Controls.OBC.Utilities.PIDWithInputGains PID( - final controllerType=controllerType, + final controllerType=conTyp, final r=r, final yMax=yMax, final yMin=yMin, @@ -117,13 +117,13 @@ protected final unit="s", min=100*Buildings.Controls.OBC.CDL.Constants.eps)=0.5 "Start value of the time constant of integrator block" - annotation (Dialog(group="Control gains",enable=controllerType == CDL.Types.SimpleController.PI or controllerType == CDL.Types.SimpleController.PID)); + annotation (Dialog(group="Control gains")); final parameter Real Td_start( final quantity="Time", final unit="s", min=100*Buildings.Controls.OBC.CDL.Constants.eps)=0.1 "Start value of the time constant of derivative block" - annotation (Dialog(group="Control gains",enable=controllerType == CDL.Types.SimpleController.PD or controllerType == CDL.Types.SimpleController.PID)); + annotation (Dialog(group="Control gains",enable=controllerType == Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController.PID)); final parameter Real yHig(min=1E-6) = 1 "Higher value for the relay output"; final parameter Real yLow(min=1E-6) = 0.1 @@ -132,14 +132,14 @@ protected "Deadband for holding the output value"; final parameter Real yRef(min=1E-6) = 0.8 "Reference output for the tuning process"; - final parameter Boolean with_D=controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PID or controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PD + final parameter Boolean with_D=controllerType == Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController.PID "Boolean flag to enable derivative action" annotation (Evaluate=true,HideResult=true); - -initial equation - assert( - controllerType <> Buildings.Controls.OBC.CDL.Types.SimpleController.PD and controllerType <> Buildings.Controls.OBC.CDL.Types.SimpleController.P, - "Only PI and PID are supported"); + final parameter Buildings.Controls.OBC.CDL.Types.SimpleController conTyp = + if controllerType==Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController.PI + then Buildings.Controls.OBC.CDL.Types.SimpleController.PI + else Buildings.Controls.OBC.CDL.Types.SimpleController.PID + "Type of controller"; equation connect(PID.u_s, u_s) annotation (Line(points={{-2,-40},{-54,-40},{-54,0},{-120, @@ -208,14 +208,14 @@ equation annotation (Line(points={{82,-20},{90,-20},{90,0},{120,0}}, color={0,0,127})); connect(u_m, PID.u_m) annotation (Line(points={{0,-120},{0,-96},{10,-96},{10, -52}}, color={0,0,127})); - connect(rel.trigger, triTun) annotation (Line(points={{24,-2},{24,-82},{60,-82}, + connect(rel.trigger, triTun) annotation (Line(points={{24,-2},{24,-90},{60,-90}, {60,-120}}, color={255,0,255})); connect(or1.u1, resPro.triEnd) annotation (Line(points={{58,-60},{52,-60},{52, -50},{46,-50},{46,-20},{-10,-20},{-10,32},{-2,32}}, color={255,0,255})); connect(or1.y, swi.u2) annotation (Line(points={{82,-60},{90,-60},{90,-40},{ 48,-40},{48,-20},{58,-20}}, color={255,0,255})); - connect(not1.u, triTun) annotation (Line(points={{28,-68},{24,-68},{24,-82},{60, - -82},{60,-120}}, color={255,0,255})); + connect(not1.u, triTun) annotation (Line(points={{28,-68},{24,-68},{24,-90},{60, + -90},{60,-120}}, color={255,0,255})); connect(not1.y, or1.u2) annotation (Line(points={{52,-68},{58,-68}}, color={255,0,255})); annotation (Documentation(info=" @@ -285,7 +285,7 @@ First implementation
fillPattern=FillPattern.Solid), Text( extent={{-26,-22},{74,-62}}, - textString= if controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PID then "PID" else "PI", + textString= if controllerType == Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController.PID then "PID" else "PI", fillPattern=FillPattern.Solid, fillColor={175,175,175}), Polygon( diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Types/SimpleController.mo b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Types/SimpleController.mo new file mode 100644 index 00000000000..cb0908a8339 --- /dev/null +++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Types/SimpleController.mo @@ -0,0 +1,33 @@ +within Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types; +type SimpleController = enumeration( + PI + "PI controller", + PID + "PID controller") + "Enumeration defining PI, or PID simple controller type" + annotation (Evaluate=true,Documentation(info=" +

+Enumeration to define the type of the controller. +Possible values are: +

+ + + + + + + + +
EnumerationDescription
PI +Controller with proportional and integral terms. +
PID +Controller with proportional, integral and derivative terms. +
+",revisions=" + +")); diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Types/package.mo b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Types/package.mo new file mode 100644 index 00000000000..fb5d1ef551f --- /dev/null +++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Types/package.mo @@ -0,0 +1,37 @@ +within Buildings.Controls.OBC.Utilities.PIDWithAutotuning; +package Types "Package with type definitions" + annotation ( + Documentation( + info=" +

+This package contains type definitions. +

+"), + Icon( + graphics={ + Rectangle( + lineColor={200,200,200}, + fillColor={248,248,248}, + fillPattern=FillPattern.HorizontalCylinder, + extent={{-100.0,-100.0},{100.0,100.0}}, + radius=25.0), + Rectangle( + lineColor={128,128,128}, + extent={{-100.0,-100.0},{100.0,100.0}}, + radius=25.0), + Polygon( + origin={-12.167,-23}, + fillColor={128,128,128}, + pattern=LinePattern.None, + fillPattern=FillPattern.Solid, + points={{12.167,65},{14.167,93},{36.167,89},{24.167,20},{4.167,-30},{14.167,-30},{24.167,-30},{24.167,-40},{-5.833,-50},{-15.833,-30},{4.167,20},{12.167,65}}, + smooth=Smooth.Bezier, + lineColor={0,0,0}), + Polygon( + origin={2.7403,1.6673}, + fillColor={128,128,128}, + pattern=LinePattern.None, + fillPattern=FillPattern.Solid, + points={{49.2597,22.3327},{31.2597,24.3327},{7.2597,18.3327},{-26.7403,10.3327},{-46.7403,14.3327},{-48.7403,6.3327},{-32.7403,0.3327},{-6.7403,4.3327},{33.2597,14.3327},{49.2597,14.3327},{49.2597,22.3327}}, + smooth=Smooth.Bezier)})); +end Types; diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Types/package.order b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Types/package.order new file mode 100644 index 00000000000..10fd40ffff6 --- /dev/null +++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Types/package.order @@ -0,0 +1 @@ +SimpleController diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Validation/PIDWithFirstOrderAMIGO.mo b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Validation/PIDWithFirstOrderAMIGO.mo index 3a8eb4c53de..a8af62ee9c5 100644 --- a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Validation/PIDWithFirstOrderAMIGO.mo +++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Validation/PIDWithFirstOrderAMIGO.mo @@ -4,7 +4,7 @@ model PIDWithFirstOrderAMIGO "Test model for an autotuning PID controller" "Setpoint value" annotation (Placement(transformation(extent={{-80,0},{-60,20}}))); Buildings.Controls.OBC.Utilities.PIDWithAutotuning.FirstOrderAMIGO PIDWitTun( - controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PID) + controllerType=Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController.PID) "PID controller with an autotuning feature" annotation (Placement(transformation(extent={{-20,-30},{0,-10}}))); Buildings.Controls.OBC.CDL.Continuous.PIDWithReset PID( diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Validation/PIWithFirstOrderAMIGO.mo b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Validation/PIWithFirstOrderAMIGO.mo index 59ccc51e097..2b067b2c18d 100644 --- a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Validation/PIWithFirstOrderAMIGO.mo +++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/Validation/PIWithFirstOrderAMIGO.mo @@ -4,7 +4,7 @@ model PIWithFirstOrderAMIGO "Test model for an autotuning PI controller" "Setpoint value" annotation (Placement(transformation(extent={{-80,0},{-60,20}}))); Buildings.Controls.OBC.Utilities.PIDWithAutotuning.FirstOrderAMIGO PIWitTun( - controllerType=Buildings.Controls.OBC.CDL.Types.SimpleController.PI) + controllerType=Buildings.Controls.OBC.Utilities.PIDWithAutotuning.Types.SimpleController.PI) "PI controller with an autotuning feature" annotation (Placement(transformation(extent={{-20,-30},{0,-10}}))); Buildings.Controls.OBC.CDL.Continuous.PIDWithReset PI( @@ -40,12 +40,12 @@ model PIWithFirstOrderAMIGO "Test model for an autotuning PI controller" Buildings.Controls.OBC.CDL.Continuous.Derivative derivative2 "A derivative block that is used to mimic the first order process 2" annotation (Placement(transformation(extent={{80,-60},{60,-40}}))); - - CDL.Logical.Sources.Pulse autTunSig( + Buildings.Controls.OBC.CDL.Logical.Sources.Pulse autTunSig( width=0.9, period=10000, shift=-9000) "Signal for enabling the autotuning" annotation (Placement(transformation(extent={{-80,-60},{-60,-40}}))); + equation connect(resSig.y, PI.trigger) annotation (Line(points={{-58,70},{-30,70},{-30, 40},{-16,40},{-16,48}}, color={255,0,255})); diff --git a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/package.order b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/package.order index 3833c69659b..6019a200cf9 100644 --- a/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/package.order +++ b/Buildings/Controls/OBC/Utilities/PIDWithAutotuning/package.order @@ -2,4 +2,5 @@ FirstOrderAMIGO AutoTuner Relay SystemIdentification +Types Validation