diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml index f27461991b6..4936af0b8de 100644 --- a/.github/workflows/formatting.yml +++ b/.github/workflows/formatting.yml @@ -42,6 +42,13 @@ jobs: - name: "Install BuildingsPy" run: pip3 install git+https://github.com/lbl-srg/BuildingsPy@v4.0.0 + - name: Check for UTF-8 BOM + run : | + for ff in `grep -rlI --exclude="ffd.vcxproj" --exclude-dir="\.git" $'^\xEF\xBB\xBF' .`; do + echo "::error file=${ff}:: Found BOM in ${ff}." + done; + test -z "${ff}" + - name: "Test html syntax" run : ../bin/runUnitTests.py --validate-html-only @@ -75,9 +82,6 @@ jobs: python Buildings/Resources/src/Controls/OBC/UnitConversions/unit_converters.py git diff --exit-code Buildings - - name: Check for UTF-8 BOM - run: "! find . -name '*.mo' -print0 | xargs -0 grep -l $'^\\xEF\\xBB\\xBF' | grep ." - - name: Check for file permissions run : | set -o noglob diff --git a/Buildings/Controls/OBC/CDL/Continuous/Derivative.mo b/Buildings/Controls/OBC/CDL/Continuous/Derivative.mo new file mode 100644 index 00000000000..5ac07e449ba --- /dev/null +++ b/Buildings/Controls/OBC/CDL/Continuous/Derivative.mo @@ -0,0 +1,121 @@ +within Buildings.Controls.OBC.CDL.Continuous; +block Derivative + "Block that approximates the derivative of the input" + parameter Real y_start=0 + "Initial value of output (= state)" + annotation (Dialog(group="Initialization")); + + Buildings.Controls.OBC.CDL.Interfaces.RealInput k + "Connector for gain signal" + annotation (Placement(transformation(extent={{-140,60},{-100,100}}))); + Buildings.Controls.OBC.CDL.Interfaces.RealInput T( + final quantity="Time", + final unit="s", + min=100*Buildings.Controls.OBC.CDL.Constants.eps) + "Time constant (T>0 required; T=0 is ideal derivative block)" + annotation (Placement(transformation(extent={{-140,20},{-100,60}}))); + Buildings.Controls.OBC.CDL.Interfaces.RealInput u + "Input to be differentiated" + annotation (Placement(transformation(extent={{-140,-20},{-100,20}}))); + Buildings.Controls.OBC.CDL.Interfaces.RealOutput y + "Approximation of derivative du/dt" + annotation (Placement(transformation(extent={{100,-20},{140,20}}))); +protected + Real T_nonZero(final unit="s") "Non-zero value for T"; + + output Real x + "State of block"; + +initial equation + x= if abs(k) < Buildings.Controls.OBC.CDL.Constants.eps then u else u - T*y_start/k; + +equation + T_nonZero = max(T, 100*Buildings.Controls.OBC.CDL.Constants.eps); + der(x) = (u-x)/T_nonZero; + y = (k/T_nonZero)*(u-x); + + annotation ( + defaultComponentName="der", + Documentation( + info=" +

+This blocks defines the transfer function between the +input u and the output y +as approximated derivative: +

+
+                s
+  y = k * ------------ * u
+            T * s + 1
+
+

+If k=0, the block reduces to y=0. +

+", + revisions=" + +"), + Icon( + coordinateSystem( + extent={{-100.0,-100.0},{100.0,100.0}}), + graphics={ + Rectangle( + extent={{-100,-100},{100,100}}, + lineColor={0,0,127}, + fillColor={255,255,255}, + fillPattern=FillPattern.Solid), + Line( + points={{-56,78},{-56,-90}}, + color={192,192,192}), + Polygon( + lineColor={192,192,192}, + fillColor={192,192,192}, + fillPattern=FillPattern.Solid, + points={{-56,90},{-64,68},{-48,68},{-56,90}}), + Line( + points={{-64,-80},{82,-80}}, + color={192,192,192}), + Polygon( + lineColor={192,192,192}, + fillColor={192,192,192}, + fillPattern=FillPattern.Solid, + points={{90.0,-80.0},{68.0,-72.0},{68.0,-88.0},{90.0,-80.0}}), + Line( + origin={-24.667,-27.333}, + points={{-31.333,89.333},{-19.333,-40.667},{86.667,-52.667}}, + color={0,0,127}, + smooth=Smooth.Bezier), + Text( + extent={{-150,150},{150,110}}, + textString="%name", + textColor={0,0,255}), + Text( + extent={{226,60},{106,10}}, + textColor={0,0,0}, + textString=DynamicSelect("",String(y, + leftJustified=false, + significantDigits=3))), + Text( + extent={{-106,14},{-62,-12}}, + textColor={0,0,0}, + textString="u"), + Text( + extent={{46,14},{90,-12}}, + textColor={0,0,0}, + textString="y=du/dt"), + Text( + extent={{-108,94},{-64,68}}, + textColor={0,0,0}, + textString="k"), + Text( + extent={{-108,54},{-64,28}}, + textColor={0,0,0}, + textString="T")})); +end Derivative; diff --git a/Buildings/Controls/OBC/CDL/Continuous/PID.mo b/Buildings/Controls/OBC/CDL/Continuous/PID.mo index 8744a2af46c..41bd1e82446 100644 --- a/Buildings/Controls/OBC/CDL/Continuous/PID.mo +++ b/Buildings/Controls/OBC/CDL/Continuous/PID.mo @@ -63,9 +63,7 @@ block PID final y_start=xi_start) if with_I "Integral term" annotation (Placement(transformation(extent={{-50,-10},{-30,10}}))); - Derivative D( - final k=k*Td, - final T=Td/Nd, + Buildings.Controls.OBC.CDL.Continuous.Derivative D( final y_start=yd_start) if with_D "Derivative term" annotation (Placement(transformation(extent={{-50,60},{-30,80}}))); @@ -100,6 +98,12 @@ protected final parameter Boolean with_D=controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PD or controllerType == Buildings.Controls.OBC.CDL.Types.SimpleController.PID "Boolean flag to enable derivative action" annotation (Evaluate=true,HideResult=true); + Sources.Constant kDer(k=k*Td) if with_D + "Gain for derivative block" + annotation (Placement(transformation(extent={{-100,110},{-80,130}}))); + Sources.Constant TDer(k=Td/Nd) if with_D + "Time constant for approximation in derivative block" + annotation (Placement(transformation(extent={{-100,80},{-80,100}}))); Buildings.Controls.OBC.CDL.Continuous.Sources.Constant Dzero( final k=0) if not with_D "Zero input signal" @@ -144,152 +148,6 @@ protected "Constant false" annotation (Placement(transformation(extent={{-100,-90},{-80,-70}}))); - block Derivative - "Block that approximates the derivative of the input" - parameter Real k( - unit="1")=1 - "Gains"; - parameter Real T( - final quantity="Time", - final unit="s", - min=1E-60)=0.01 - "Time constant (T>0 required)"; - parameter Real y_start=0 - "Initial value of output (= state)" - annotation (Dialog(group="Initialization")); - Interfaces.RealInput u - "Connector of Real input signal" - annotation (Placement(transformation(extent={{-140,-20},{-100,20}}))); - Interfaces.RealOutput y - "Connector of Real output signal" - annotation (Placement(transformation(extent={{100,-20},{140,20}}))); - output Real x - "State of block"; - - protected - parameter Boolean zeroGain=abs(k) < 1E-17 - "= true, if gain equals to zero"; - - initial equation - if zeroGain then - x=u; - else - x=u-T*y_start/k; - end if; - - equation - der(x)= - if zeroGain then - 0 - else - (u-x)/T; - y=if zeroGain then - 0 - else - (k/T)*(u-x); - annotation ( - defaultComponentName="der", - Documentation( - info=" -

-This blocks defines the transfer function between the -input u and the output y -as approximated derivative: -

-
-             k * s
-     y = ------------ * u
-            T * s + 1
-
-

-If k=0, the block reduces to y=0. -

-", - revisions=" - -"), - Icon( - coordinateSystem( - preserveAspectRatio=true, - extent={{-100.0,-100.0},{100.0,100.0}}), - graphics={ - Rectangle( - extent={{-100,-100},{100,100}}, - lineColor={0,0,127}, - fillColor={255,255,255}, - fillPattern=FillPattern.Solid), - Line( - points={{-80.0,78.0},{-80.0,-90.0}}, - color={192,192,192}), - Polygon( - lineColor={192,192,192}, - fillColor={192,192,192}, - fillPattern=FillPattern.Solid, - points={{-80.0,90.0},{-88.0,68.0},{-72.0,68.0},{-80.0,90.0}}), - Line( - points={{-90.0,-80.0},{82.0,-80.0}}, - color={192,192,192}), - Polygon( - lineColor={192,192,192}, - fillColor={192,192,192}, - fillPattern=FillPattern.Solid, - points={{90.0,-80.0},{68.0,-72.0},{68.0,-88.0},{90.0,-80.0}}), - Line( - origin={-24.667,-27.333}, - points={{-55.333,87.333},{-19.333,-40.667},{86.667,-52.667}}, - color={0,0,127}, - smooth=Smooth.Bezier), - Text( - extent={{-150.0,-150.0},{150.0,-110.0}}, - textString="k=%k"), - Text( - extent={{-150,150},{150,110}}, - textString="%name", - textColor={0,0,255}), - Text( - extent={{226,60},{106,10}}, - textColor={0,0,0}, - textString=DynamicSelect("",String(y, - leftJustified=false, - significantDigits=3)))})); - end Derivative; - equation connect(u_s,uS_revAct.u) annotation (Line(points={{-240,0},{-212,0},{-212,40},{-202,40}},color={0,0,127})); @@ -352,8 +210,11 @@ equation connect(uMea_revAct.y, errI1.u2) annotation (Line(points={{-158,-40},{-150, -40},{-150,-6},{-142,-6}}, color={0,0,127})); connect(antWinGai.y, errI2.u2) annotation (Line(points={{158,-20},{-100,-20}, - {-100,-6},{-92,-6}}, - color={0,0,127})); + {-100,-6},{-92,-6}}, color={0,0,127})); + connect(kDer.y, D.k) annotation (Line(points={{-78,120},{-58,120},{-58,78},{ + -52,78}}, color={0,0,127})); + connect(TDer.y, D.T) annotation (Line(points={{-78,90},{-60,90},{-60,74},{-52, + 74}}, color={0,0,127})); annotation ( defaultComponentName="conPID", Icon( @@ -619,6 +480,12 @@ American Society of Heating Refrigerating and Air-Conditioning Engineers Inc. At revisions="