Skip to content

Commit

Permalink
added controller type
Browse files Browse the repository at this point in the history
  • Loading branch information
JayHuLBL committed Aug 18, 2023
1 parent 820acc0 commit fc32973
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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="<html>
Expand Down Expand Up @@ -285,7 +285,7 @@ First implementation<br/>
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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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="<html>
<p>
Enumeration to define the type of the controller.
Possible values are:
</p>
<table border=\"1\" summary=\"Explanation of the enumeration\">
<tr>
<th>Enumeration</th>
<th>Description</th></tr>
<tr><td><code>PI</code></td>
<td>
Controller with proportional and integral terms.
</td></tr>
<tr><td><code>PID</code></td>
<td>
Controller with proportional, integral and derivative terms.
</td></tr>
</table>
</html>",revisions="<html>
<ul>
<li>
August 18, 2023, by Jianjun Hu:<br/>
First implementation.
</li>
</ul>
</html>"));
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
within Buildings.Controls.OBC.Utilities.PIDWithAutotuning;
package Types "Package with type definitions"
annotation (
Documentation(
info="<html>
<p>
This package contains type definitions.
</p>
</html>"),
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;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SimpleController
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ FirstOrderAMIGO
AutoTuner
Relay
SystemIdentification
Types
Validation

0 comments on commit fc32973

Please sign in to comment.