diff --git a/Modelica/Blocks/Interfaces.mo b/Modelica/Blocks/Interfaces.mo index 9676f0d186..7964ba0e42 100644 --- a/Modelica/Blocks/Interfaces.mo +++ b/Modelica/Blocks/Interfaces.mo @@ -355,6 +355,28 @@ continuous Real output signal y. end SI2SO; + partial block SI2SO2 + "2 Single Input / 2 Single Output continuous control block" + extends Modelica.Blocks.Icons.Block; + + RealInput u1 "Connector of Real input signal 1" annotation (Placement( + transformation(extent={{-140,40},{-100,80}}))); + RealInput u2 "Connector of Real input signal 2" annotation (Placement( + transformation(extent={{-140,-80},{-100,-40}}))); + RealOutput y1 "Connector of Real output signal 1" annotation (Placement( + transformation(extent={{100,50},{120,70}}))); + RealOutput y2 "Connector of Real output signal 2" annotation (Placement( + transformation(extent={{100,-70},{120,-50}}))); + + annotation (Documentation(info=" +

+Block has two continuous Real input signals u1 and u2 and two +continuous Real output signals y1 and y2. +

+")); + + end SI2SO2; + partial block SIMO "Single Input Multiple Output continuous control block" extends Modelica.Blocks.Icons.Block; parameter Integer nout=1 "Number of outputs"; @@ -370,6 +392,22 @@ continuous Real output signal y. ")); end SIMO; + partial block SI2MO "2 Single Input / 1 Multiple Output continuous control block" + extends Modelica.Blocks.Icons.Block; + parameter Integer nout=1 "Number of outputs"; + RealInput u1 "Connector of Real input signal 1" annotation (Placement( + transformation(extent={{-140,40},{-100,80}}, rotation=0))); + RealInput u2 "Connector of Real input signal 2" annotation (Placement( + transformation(extent={{-140,-80},{-100,-40}}, rotation=0))); + RealOutput y[nout] "Connector of Real output signal" annotation (Placement( + transformation(extent={{100,-10},{120,10}}, rotation=0))); + + annotation (Documentation(info=" +

Block has two continuous Real input signals and a vector of continuous Real output signals.

+")); + + end SI2MO; + partial block MISO "Multiple Input Single Output continuous control block" extends Modelica.Blocks.Icons.Block; @@ -386,6 +424,24 @@ one continuous Real output signal. ")); end MISO; + partial block MI2SO + "2 Multiple Input / Single Output continuous control block" + extends Modelica.Blocks.Icons.Block; + parameter Integer n=1 "Dimension of input vector."; + RealInput u1[n] "Connector 1 of Real input signals" annotation (Placement( + transformation(extent={{-140,40},{-100,80}}))); + RealInput u2[n] "Connector 2 of Real input signals" annotation (Placement( + transformation(extent={{-140,-80},{-100,-40}}))); + RealOutput y "Connector of Real output signals" annotation (Placement( + transformation(extent={{100,-10},{120,10}}))); + + annotation (Documentation(info=" +

Block has two continuous Real input vectors u1 and u2 and one +continuous Real output signal y. All input vectors have the same number of elements. +

+")); + end MI2SO; + partial block PartialRealMISO "Partial block with a RealVectorInput and a RealOutput signal" diff --git a/Modelica/Blocks/Logical.mo b/Modelica/Blocks/Logical.mo index 79704e5f8c..f76a9b56ee 100644 --- a/Modelica/Blocks/Logical.mo +++ b/Modelica/Blocks/Logical.mo @@ -460,6 +460,52 @@ u1, else it is set equal to u3.

extent={{2,-6},{18,8}})})); end LogicalSwitch; + block IntegerSwitch "Switch between two Integer signals" + extends Modelica.Blocks.Icons.PartialBooleanBlock; + Blocks.Interfaces.IntegerInput u1 "First input signal" + annotation (Placement(transformation(extent={{-140,60},{-100,100}}))); + Blocks.Interfaces.BooleanInput u2 "Boolean condition to select between u1 and u3" + annotation (Placement(transformation(extent={{-140,-20},{-100,20}}))); + Blocks.Interfaces.IntegerInput u3 "Second input signal" + annotation (Placement(transformation(extent={{-140,-100},{-100,-60}}))); + Blocks.Interfaces.IntegerOutput y "Output signal" + annotation (Placement(transformation(extent={{100,-10},{120,10}}))); + + equation + y = if u2 then u1 else u3; + annotation ( + Documentation(info=" +

The IntegerSwitch switches, depending on the +Boolean u2 connector (the middle connector), +between the two possible input signals +u1 (upper connector) and u3 (lower connector).

+

If u2 is true, connector y is set equal to +u1, else it is set equal to u3.

+"), + Icon(coordinateSystem( + preserveAspectRatio=true, + extent={{-100,-100},{100,100}}), graphics={ + Line(points={{12,0},{100,0}}, + color={255,127,0}), + Line(points={{-100,0},{-40,0}}, + color={255,0,255}), + Line(points={{-100,-80},{-40,-80},{-40,-80}}, + color={255,127,0}), + Line(points={{-40,12},{-40,-12}}, + color={255,0,255}), + Line(points={{-100,80},{-38,80}}, + color={255,127,0}), + Line(points=DynamicSelect({{-38,80},{6,2}}, if u2 then {{-38,80},{6,2}} else {{-38,-80},{6,2}}), + color={255,127,0}, + thickness=1, + smooth=Smooth.Bezier), + Ellipse(lineColor={255,127,0}, + pattern=LinePattern.None, + fillPattern=FillPattern.Solid, + extent={{-2,-8},{14,8}}, + fillColor={244,125,35})})); + end IntegerSwitch; + block Switch "Switch between two Real signals" extends Modelica.Blocks.Icons.PartialBooleanBlock; Blocks.Interfaces.RealInput u1 "Connector of first Real input signal" diff --git a/Modelica/Blocks/Math.mo b/Modelica/Blocks/Math.mo index 0ffb0e28fd..2690f7ebec 100644 --- a/Modelica/Blocks/Math.mo +++ b/Modelica/Blocks/Math.mo @@ -997,6 +997,65 @@ y = u1 * u2; Ellipse(lineColor={0,0,127}, extent={{-50,-50},{50,50}})})); end Product; + block ScalarProduct "Output scalar product of the two inputs with dimension n" + extends Modelica.Blocks.Interfaces.MI2SO; + + equation + y = u1 * u2; + annotation ( + Documentation( + info = " +

This blocks computes the output y as scalar product of the two input vectors u1 and u2:

+
+y = u1 * u2;
+
+

As example, for three-dimensional input vectors the equation would be:

+
+y = u1[1]*u2[1] + u1[2]*u2[2] + u1[3]*u2[3];
+
+The output y is scalar. +"), + Icon(coordinateSystem( + preserveAspectRatio=true, + extent={{-100,-100},{100,100}}), graphics={ + Line(points={{-100,60},{-40,60},{-30,40}}, color={0,0,127}), + Line(points={{-100,-60},{-40,-60},{-30,-40}}, color={0,0,127}), + Line(points={{50,0},{100,0}}, color={0,0,127}), + Line(points={{-30,0},{30,0}}), + Line(points={{-15,25.99},{15,-25.99}}), + Line(points={{-15,-25.99},{15,25.99}}), + Ellipse(lineColor={0,0,127}, extent={{-50,-50},{50,50}})}), + Diagram( + coordinateSystem( + preserveAspectRatio = true, + extent = { + {-100, -100}, + {100, 100}}), + graphics = { + Line( + points = { + {-100, 60}, + {-40, 60}, + {-30, 40}}, + color = {0, 0, 255}), + Line( + points = {{-100, -60}, {-40, -60}, {-30, -40}}, + color = {0, 0, 255}), + Line(points = {{50, 0}, {100, 0}}, color = {0, 0, 255}), + Line(points = {{-30, 0}, {30, 0}}), + Line( + points = { + {-15, 25.99}, + {15, -25.99}}), + Line( + points = { + {-15, -25.99}, + {15, 25.99}}), + Ellipse( + extent = {{-50, 50}, {50, -50}}, + lineColor = {0, 0, 255})})); + end ScalarProduct; + block Division "Output first input divided by second input" extends Interfaces.SI2SO; @@ -1033,6 +1092,77 @@ y = u1 / u2; color={0,0,255})})); end Division; + block NormalizeVector "Normalizes a vector" + extends Modelica.Blocks.Interfaces.MIMOs(n = 3); + + parameter Real eps(min = 0.0) = 100 * Modelica.Constants.eps + "if |v| < eps then result = y0"; + parameter Real y0[n] = {1, 0, 0} + "Output vector if length(u) < eps"; + + equation + y = noEvent(Modelica.Math.Vectors.normalize(u, eps)); + + annotation ( + Icon( + graphics = { + Line( + points = {{-42.1048, -27.0405}, {34, -28}, {34, -28}, {14, -18}, {14, -18}, {14, -38}, {14, -38}, {34, -28}, {34, -28}}, + color = {0, 86, 134}, + rotation = 55, + origin = {-14, 50}, + visible = true, + pattern = LinePattern.Dash, + thickness = 0.5, + smooth = Smooth.Bezier), + Line( + points = { + {-46.5285, -27.6965}, + {-46.5285, -27.6965}, + {33.92, -27.5215}, + {33.92, -27.5215}, + {14, -18}, + {14, -18}, + {14, -38}, + {14, -38}, + {33.92, -27.5215}, + {33.92, -27.5215}}, + color = {0, 86, 134}, + rotation = 55, + origin = {-58, -12}, + pattern = LinePattern.Solid, + thickness = 0.5, + smooth = Smooth.Bezier), + Line(points = {{-62, -74}, {-62, 58}}, color = {200, 200, 200}), + Polygon( + points = [-62.0, 72.0; -62.0, 72.0; -66.0, 56.0; -66.0, 56.0; -58.0, 56.0; -58.0, 56.0; -62.0, 72.0; -62.0, 72.0], + lineColor = {200, 200, 200}, + fillColor = {200, 200, 200}, + fillPattern = FillPattern.Solid, + pattern = LinePattern.None, + smooth = Smooth.Bezier), + Line(points = {{-68, -66}, {58, -66}}, color = {200, 200, 200}), + Polygon( + points = {{0, 8}, {0, 8}, {-4, -8}, {-4, -8}, {4, -8}, {4, -8}, {0, 8}, {0, 8}}, + lineColor = {200, 200, 200}, + fillColor = {200, 200, 200}, + fillPattern = FillPattern.Solid, + pattern = LinePattern.None, + smooth = Smooth.Bezier, + origin = {58, -66}, + rotation = 270), + Line(points = {{-16,-70},{-16,-62}}, color = {200, 200, 200}), + Line( + points = {{0, -4}, {0, 4}}, + color = {200, 200, 200}, + origin = {-62, 0}, + rotation = 90)}), + Documentation( + info = " +

This block normalizes an input vector u using the normalize function.

+")); + end NormalizeVector; + block Abs "Output the absolute value of the input" extends Interfaces.SISO; parameter Boolean generateEvent=false diff --git a/Modelica/Blocks/Nonlinear.mo b/Modelica/Blocks/Nonlinear.mo index 57cb86023f..b2755c5689 100644 --- a/Modelica/Blocks/Nonlinear.mo +++ b/Modelica/Blocks/Nonlinear.mo @@ -250,6 +250,79 @@ with derivative time constant Td. Smaller time constant Td")); end SlewRateLimiter; + block ZeroProtection "Limit the input to a minimum value around zero" + + // Base model + extends Modelica.Blocks.Interfaces.SISO; + + // Parameter + parameter Real threshold(min = 0, start = Modelica.Constants.eps) + "Smallest value around zero, which the output can have"; + + equation + + y = + if noEvent(u >= threshold or u <= -threshold) then + u + elseif noEvent(u >= 0) then + threshold + else + -threshold; + + annotation ( + Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}})), + Icon( + coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), + graphics = { + Line(points = {{-78, 0}, {78, 0}}, color = {192, 192, 192}), + Line(points = {{0, -80}, {0, 68}}, color = {192, 192, 192}), + Text( + extent = {{62, 32}, {80, 8}}, + textColor = {0, 0, 0}, + textString = "u"), + Text( + extent = {{-24, 84}, {-8, 64}}, + textColor = {0, 0, 0}, + textString = "y"), + Text( + extent = {{-82, 22}, {-12, 6}}, + textColor = {0, 0, 0}, + textString = "%threshold", + horizontalAlignment = TextAlignment.Right), + Line(points = {{-4, 10}, {2, 10}}, color = {192, 192, 192}), + Line( + points = {{-2, -10}, {4, -10}}, + color = {192, 192, 192}), + Line( + points = {{60, 60}, {10, 10}, {0, 10}}, + color = {0, 0, 0}), + Line( + points = {{-60, -60}, {-10, -10}, {0, -10}}, + color = {0, 0, 0}), + Polygon( + points = {{0, 80}, {-6, 64}, {6, 64}, {0, 80}}, + lineColor = {192, 192, 192}, + fillColor = {192, 192, 192}, + fillPattern = FillPattern.Solid), + Polygon( + points = {{0, 8}, {-6, -8}, {6, -8}, {0, 8}}, + lineColor = {192, 192, 192}, + fillColor = {192, 192, 192}, + fillPattern = FillPattern.Solid, + origin = {72, 0}, + rotation = 270), + Text( + extent = {{8, -8}, {78, -24}}, + textColor = {0, 0, 0}, + horizontalAlignment = TextAlignment.Left, + textString = "-%threshold")}), + Documentation( + info = " +

This block avoids a value of zero and gives +/- threshold as output instead.

+")); + + end ZeroProtection; + block DeadZone "Provide a region of zero output" parameter Real uMax(start=1) "Upper limits of dead zones"; parameter Real uMin=-uMax "Lower limits of dead zones"; @@ -293,6 +366,370 @@ function of the input with a slope of 1. textString="uMax=%uMax")})); end DeadZone; + block LinearShifter + "Shifts y between y1 and y2 linearly depending on x" + + // Base model + extends Modelica.Blocks.Interfaces.SISO; + + // Parameters + parameter Real u1(start = -1) + "Lower boundary of input u, switching from constant value y1 to linear interpolation"; + parameter Real u2(start = 1) + "Upper boundary of input u, switching from linear interpolation to constant value y2"; + parameter Real y1(start = -1) + "Minimum value for y"; + parameter Real y2(start = 1) + "Maximum value for y"; + + parameter Boolean strict = false + "= true, if strict limits with noEvent(..)" + annotation (Evaluate = true, choices(checkBox = true), Dialog(group = "Discontinuities")); + + final parameter Real k = (y2 - y1) / (u2 - u1) + "Slope of the resulting line equation"; + final parameter Real y0 = if k > 0 then -k * u1 + y1 else -k * u2 + y2 + "Offset of the resulting line equation"; + + // Components + Modelica.Blocks.Math.Gain gradient(k = k) + annotation (Placement(transformation(extent = {{-60, -10}, {-40, 10}}))); + Modelica.Blocks.Math.Add add + annotation (Placement(transformation(extent = {{0, -10}, {20, 10}}))); + Modelica.Blocks.Sources.Constant offset(k = y0) + annotation (Placement(transformation(extent = {{-60, 30}, {-40, 50}}))); + Modelica.Blocks.Nonlinear.Limiter limiter(uMax = max(y1, y2), uMin = min(y1, y2), strict = strict) + annotation (Placement(transformation(extent = {{40, -10}, {60, 10}}))); + + initial equation + + assert(u1 < u2, "Invalid parameters for " + getInstanceName() + ": Lower point has to be smaller than upper point on the abscissa."); + + equation + + connect(gradient.u, u) + annotation (Line(points = {{-62, 0}, {-120, 0}}, color = {0, 0, 127})); + connect(add.u2, gradient.y) + annotation (Line(points = {{-2, -6}, {-30, -6}, {-30, 0}, {-39, 0}}, color = {0, 0, 127})); + connect(offset.y, add.u1) + annotation (Line(points = {{-39, 40}, {-20, 40}, {-20, 6}, {-2, 6}}, color = {0, 0, 127})); + connect(limiter.u, add.y) + annotation (Line(points = {{38, 0}, {21, 0}}, color = {0, 0, 127})); + connect(limiter.y, y) + annotation (Line(points = {{61, 0}, {110, 0}}, color = {0, 0, 127})); + + annotation ( + Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}})), + Documentation( + info = " +

The output y is shifted in between the parameters y1 and y2 depending on the + input u.

+

If the input u≤u1 then y=y1, if u≥u2 then y=y2. For + values of u between u1 and u2 the output y is interpolated + linearly between y1 and y2.

+
+

Application

+

This block can be useful e.g. to limit the torque (y) of an electric machine if speed (u) gets to high. Usual + parameters in such a case could be:

+ +"), + Icon( + coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), + graphics = { + Line(points = {{0, -66}, {0, 84}}, color = {192, 192, 192}), + Line(points = {{-84, 0}, {74, 0}}, color = {192, 192, 192}), + Polygon( + points = {{90, 0}, {74, 6}, {74, -6}, {90, 0}}, + lineColor = {192, 192, 192}, + fillColor = {192, 192, 192}, + fillPattern = FillPattern.Solid), + Polygon( + points = {{0, 90}, {-6, 74}, {6, 74}, {0, 90}}, + lineColor = {192, 192, 192}, + fillColor = {192, 192, 192}, + fillPattern = FillPattern.Solid), + Line(points = {{-76, -60}, {-32, -60}, {32, 64}, {78, 64}}, color = {0, 86, 134}), + Line(points = {{-32, -4}, {-32, 4}}, color = {192, 192, 192}), + Line(points = {{32, -8}, {32, 64}}, color = {192, 192, 192}), + Text( + extent = {{-30, 76}, {-4, 50}}, + textColor = {0, 86, 134}, + textString = "%y2"), + Text( + extent = {{6, -48}, {32, -74}}, + textColor = {0, 86, 134}, + textString = "%y1"), + Text( + extent = {{18, -6}, {44, -32}}, + textColor = {0, 86, 134}, + textString = "%u2"), + Text( + extent = {{-44, -6}, {-20, -32}}, + textColor = {0, 86, 134}, + textString = "%u1"), + Line(points = {{-4, 64}, {32, 64}}, color = {192, 192, 192}), + Line(points = {{-32, -60}, {4, -60}}, color = {192, 192, 192}), + Line(points = {{-32, -60}, {-32, -36}}, color = {192, 192, 192})})); + + end LinearShifter; + + model SinSquareShifter + "Shifts y between y1 and y2 depending on x" + + import Modelica.Constants.pi; + + // Base model + extends Modelica.Blocks.Interfaces.SISO; + + // Parameters + parameter Real u1(start = 1) + "Lower boundary of input u, switching from constant value y1 to sin^2 interpolation"; + parameter Real u2(start = 2) + "Upper boundary of input u, switching from sin^2 interpolation to constant value y2"; + parameter Real y1(start = 0) + "Minimum value for y"; + parameter Real y2(start = 1) + "Maximum value for y"; + + equation + + if noEvent(u <= u1) then + y = y1; + elseif noEvent(u > u1 and u < u2) then + y = y1 + (y2 - y1) * sin((u - u1) / (u2 - u1) * pi / 2) ^ 2; + else + y = y2; + end if; + + annotation ( + Icon( + graphics = { + Line(points = {{0, -66}, {0, 84}}, color = {192, 192, 192}), + Line(points = {{-84, 0}, {74, 0}}, color = {192, 192, 192}), + Polygon( + points = {{90, 0}, {74, 6}, {74, -6}, {90, 0}}, + lineColor = {192, 192, 192}, + fillColor = {192, 192, 192}, + fillPattern = FillPattern.Solid), + Polygon( + points = {{0, 90}, {-6, 74}, {6, 74}, {0, 90}}, + lineColor = {192, 192, 192}, + fillColor = {192, 192, 192}, + fillPattern = FillPattern.Solid), + Line( + points = {{-76, -60}, {-18, -60}, {20, 64}, {78, 64}}, + color = {0, 86, 134}, + smooth = Smooth.Bezier), + Line(points = {{-46, -4}, {-46, 4}}, color = {192, 192, 192}), + Line(points = {{48, -8}, {48, 64}}, color = {192, 192, 192}), + Text( + extent = {{-30, 76}, {-4, 50}}, + textColor = {0, 86, 134}, + textString = "%y2"), + Text( + extent = {{6, -48}, {32, -74}}, + textColor = {0, 86, 134}, + textString = "%y1"), + Text( + extent = {{34, -6}, {60, -32}}, + textColor = {0, 86, 134}, + textString = "%u2"), + Text( + extent = {{-58, -6}, {-34, -32}}, + textColor = {0, 86, 134}, + textString = "%u1"), + Line(points = {{-4, 64}, {48, 64}}, color = {192, 192, 192}), + Line(points = {{-46, -60}, {4, -60}}, color = {192, 192, 192}), + Line(points = {{-46, -60}, {-46, -36}}, color = {192, 192, 192})}), + Documentation( + info = " +

The output y is shifted in between the parameters y1 and y2 depending on the + input u.

+

If the input u≤u1 then y=y1, if u≥u2 then y=y2. For + values of u between u1 and u2 the output y is interpolated + using a sin² function between y1 and y2.

+
+

Application

+

The block has the same applications as the LinearShifter + with potentially improved stability due to the smoother behavior of the output. +

+")); + + end SinSquareShifter; + + block VariableLinearShifter + "Shifting between u1 and u2 depending on x" + + // Base model + extends Modelica.Blocks.Interfaces.SISO; + + // Components + Modelica.Blocks.Interfaces.RealInput u1 + annotation (Placement(transformation(extent = {{-140, 40}, {-100, 80}}))); + Modelica.Blocks.Interfaces.RealInput u2 + annotation (Placement(transformation(extent = {{-140, -80}, {-100, -40}}))); + Modelica.Blocks.Math.Product resultFromFirstInput + annotation (Placement(transformation(extent = {{20, 30}, {40, 50}}))); + Modelica.Blocks.Math.Product resultFromSecondInput + annotation (Placement(transformation(extent = {{20, -50}, {40, -30}}))); + Modelica.Blocks.Math.Add valueForInversion(k1 = -1) + annotation (Placement(transformation(extent = {{-20, -34}, {0, -14}}))); + Modelica.Blocks.Sources.Constant negationValue(k = 1) + annotation (Placement(transformation(extent = {{-60, -40}, {-40, -20}}))); + Modelica.Blocks.Nonlinear.Limiter limitedShiftingFactor( + uMax = 1, + uMin = 0, + strict = true) + annotation (Placement(transformation(extent = {{-80, -10}, {-60, 10}}))); + Modelica.Blocks.Math.Add sumOfWheightedInputs + annotation (Placement(transformation(extent = {{60, -10}, {80, 10}}))); + + equation + + connect(u1, resultFromFirstInput.u1) + annotation ( + Line( + points = {{-120, 60}, {-30, 60}, {-30, 46}, {18, 46}}, + color = {0, 0, 127}, + smooth = Smooth.None)); + connect(negationValue.y, valueForInversion.u2) + annotation ( + Line( + points = {{-39, -30}, {-22, -30}}, + color = {0, 0, 127}, + smooth = Smooth.None)); + connect(limitedShiftingFactor.u, u) + annotation ( + Line( + points = {{-82, 0}, {-120, 0}}, + color = {0, 0, 127}, + smooth = Smooth.None)); + connect(limitedShiftingFactor.y, resultFromFirstInput.u2) + annotation ( + Line( + points = {{-59, 0}, {-30, 0}, {-30, 34}, {18, 34}}, + color = {0, 0, 127}, + smooth = Smooth.None)); + connect(valueForInversion.u1, resultFromFirstInput.u2) + annotation ( + Line( + points = {{-22, -18}, {-30, -18}, {-30, 34}, {18, 34}}, + color = {0, 0, 127}, + smooth = Smooth.None)); + connect(valueForInversion.y, resultFromSecondInput.u1) + annotation ( + Line( + points = {{1, -24}, {8, -24}, {8, -34}, {18, -34}}, + color = {0, 0, 127}, + smooth = Smooth.None)); + connect(u2, resultFromSecondInput.u2) + annotation ( + Line( + points = {{-120, -60}, {8, -60}, {8, -46}, {18, -46}}, + color = {0, 0, 127}, + smooth = Smooth.None)); + connect(sumOfWheightedInputs.u1, resultFromFirstInput.y) + annotation ( + Line( + points = {{58, 6}, {50, 6}, {50, 40}, {41, 40}}, + color = {0, 0, 127}, + smooth = Smooth.None)); + connect(sumOfWheightedInputs.u2, resultFromSecondInput.y) + annotation ( + Line( + points = {{58, -6}, {50, -6}, {50, -40}, {41, -40}}, + color = {0, 0, 127}, + smooth = Smooth.None)); + connect(sumOfWheightedInputs.y, y) + annotation ( + Line( + points = {{81, 0}, {110, 0}}, + color = {0, 0, 127}, + smooth = Smooth.None)); + + annotation ( + Diagram( + coordinateSystem( + preserveAspectRatio = false, + extent = { + {-100, -100}, + {100, 100}})), + Documentation( + info = " +

The output y is shifted in between u1 and u2 depending on the input u. +

+

If the input u≤0 then y=u2, if u≥1 then + y=u1. For values of u between 0 and 1 the output y is interpolated + linearly between u1 and u2.

+ +
+

Application

+

This can be useful e.g. to limit the torque(y) of an electric machine if a temperature indicator (u) gets + too high. Usual parameters in such a case could be:

+ +"), + Icon( + coordinateSystem( + preserveAspectRatio = false, + extent = { + {-100, -100}, + {100, 100}}), + graphics = { + Line( + points = {{-32, -6}, {-32, 84}}, + color = {192, 192, 192}), + Line(points = {{-84, 0}, {74, 0}}, color = {192, 192, 192}), + Polygon( + points = {{90, 0}, {74, 6}, {74, -6}, {90, 0}}, + lineColor = {192, 192, 192}, + fillColor = {192, 192, 192}, + fillPattern = FillPattern.Solid), + Polygon( + points = {{-32, 86}, {-38, 70}, {-26, 70}, {-32, 86}}, + lineColor = {192, 192, 192}, + fillColor = {192, 192, 192}, + fillPattern = FillPattern.Solid), + Line( + points = {{-76, -64}, {-32, -64}, {32, 60}, {78, 60}}, + color = {0, 86, 134}), + Line(points = {{32, -6}, {32, 60}}, color = {192, 192, 192}), + Text( + extent = {{-68, 74}, {-42, 48}}, + textColor = {0, 86, 134}, + textString = "u1"), + Text( + extent = {{8, -50}, {34, -76}}, + textColor = {0, 86, 134}, + textString = "u2"), + Text( + extent = {{18, -6}, {44, -32}}, + textColor = {0, 86, 134}, + textString = "1"), + Text( + extent = {{-44, -6}, {-20, -32}}, + textColor = {0, 86, 134}, + textString = "0"), + Line( + points = {{-36, 60}, {32, 60}}, + color = {192, 192, 192}), + Line( + points = {{-32, -64}, {4, -64}}, + color = {192, 192, 192}), + Line( + points = {{-32, -64}, {-32, -34}}, + color = {192, 192, 192})})); + + end VariableLinearShifter; + block FixedDelay "Delay block with fixed DelayTime" extends Modelica.Blocks.Interfaces.SISO; parameter SI.Time delayTime(start=1) diff --git a/ModelicaTest/Blocks.mo b/ModelicaTest/Blocks.mo index d1629a24ea..b4e5fd804b 100644 --- a/ModelicaTest/Blocks.mo +++ b/ModelicaTest/Blocks.mo @@ -720,6 +720,65 @@ if homotopy is active, the solution accepted by the assert statement (x = 100) i ")); end LimitersHomotopy; + model Shifters + extends Modelica.Icons.Example; + Modelica.Blocks.Sources.Sine sine(amplitude=2, f=1) annotation ( + Placement(transformation(extent={{-80,20},{-60,40}}))); + Modelica.Blocks.Sources.Constant constPos(k=+1) annotation (Placement( + transformation(extent={{-80,-20},{-60,0}}))); + Modelica.Blocks.Sources.Constant constNeg(k=-1) annotation (Placement( + transformation(extent={{-80,-60},{-60,-40}}))); + Modelica.Blocks.Nonlinear.ZeroProtection zeroProtection(threshold=0.5) + annotation (Placement(transformation(extent={{-2,70},{18,90}}))); + Modelica.Blocks.Nonlinear.LinearShifter linearShifter( + u1=-0.6, + u2=0.6, + y1=-0.7, + y2=0.7) annotation (Placement(transformation(extent={{0,20},{20,40}}))); + Modelica.Blocks.Nonlinear.SinSquareShifter sinSquareShifter( + u1=-0.7, + u2=0.7, + y1=-0.6, + y2=0.6) annotation (Placement(transformation(extent={{0,-20},{20,0}}))); + Modelica.Blocks.Nonlinear.VariableLinearShifter variableLinearShifter + annotation (Placement(transformation(extent={{0,-70},{20,-50}}))); + equation + connect(sine.y, zeroProtection.u) annotation (Line(points={{-59,30},{-20,30},{-20,80},{-4,80}}, color={0,0,127})); + connect(sine.y, linearShifter.u) annotation (Line(points={{-59,30},{-2,30}}, color={0,0,127})); + connect(sine.y, sinSquareShifter.u) annotation (Line(points={{-59,30},{-20,30},{-20,-10},{-2,-10}}, color={0,0,127})); + connect(sine.y, variableLinearShifter.u) annotation (Line(points={{-59,30},{-20,30},{-20,-60},{-2,-60}}, color={0,0,127})); + connect(constPos.y, variableLinearShifter.u1) + annotation (Line(points={{-59,-10},{-30,-10},{-30,-54},{-2,-54}}, color={0,0,127})); + connect(constNeg.y, variableLinearShifter.u2) + annotation (Line(points={{-59,-50},{-40,-50},{-40,-66},{-2,-66}}, color={0,0,127})); + annotation (experiment(StopTime=1.1)); + end Shifters; + + model Vectors + extends Modelica.Icons.Example; + Modelica.Blocks.Sources.Sine sine(amplitude=2, f=1) annotation ( + Placement(transformation(extent={{-80,20},{-60,40}}))); + Modelica.Blocks.Sources.Constant constPos(k=+1) annotation (Placement( + transformation(extent={{-80,-20},{-60,0}}))); + Modelica.Blocks.Sources.Constant constNeg(k=-1) annotation (Placement( + transformation(extent={{-80,-60},{-60,-40}}))); + Modelica.Blocks.Routing.Multiplex3 multiplex3 annotation (Placement(transformation(extent={{-40,-20},{-20,0}}))); + Modelica.Blocks.Routing.Multiplex3 multiplex1 annotation (Placement(transformation(extent={{-20,40},{0,60}}))); + Modelica.Blocks.Math.ScalarProduct scalarProduct(n=3) annotation (Placement(transformation(extent={{30,20},{50,40}}))); + Modelica.Blocks.Math.NormalizeVector normalizeVector annotation (Placement(transformation(extent={{30,-20},{50,0}}))); + equation + connect(sine.y, multiplex3.u1[1]) annotation (Line(points={{-59,30},{-50,30},{-50,-3},{-42,-3}}, color={0,0,127})); + connect(constPos.y, multiplex3.u2[1]) annotation (Line(points={{-59,-10},{-42,-10}}, color={0,0,127})); + connect(constNeg.y, multiplex3.u3[1]) annotation (Line(points={{-59,-50},{-48,-50},{-48,-17},{-42,-17}}, color={0,0,127})); + connect(constPos.y, multiplex1.u1[1]) annotation (Line(points={{-59,-10},{-52,-10},{-52,57},{-22,57}}, color={0,0,127})); + connect(multiplex1.y, scalarProduct.u1) annotation (Line(points={{1,50},{10,50},{10,36},{28,36}}, color={0,0,127})); + connect(multiplex3.y, scalarProduct.u2) annotation (Line(points={{-19,-10},{10,-10},{10,24},{28,24}}, color={0,0,127})); + connect(multiplex3.y, normalizeVector.u) annotation (Line(points={{-19,-10},{28,-10}}, color={0,0,127})); + connect(constNeg.y, multiplex1.u3[1]) annotation (Line(points={{-59,-50},{-48,-50},{-48,43},{-22,43}}, color={0,0,127})); + connect(sine.y, multiplex1.u2[1]) annotation (Line(points={{-59,30},{-50,30},{-50,50},{-22,50}}, color={0,0,127})); + annotation (experiment(StopTime=1.1)); + end Vectors; + model KinematicPTP extends Modelica.Icons.Example; Modelica.Blocks.Sources.KinematicPTP kinematicPTP1a( @@ -1099,6 +1158,23 @@ if homotopy is active, the solution accepted by the assert statement (x = 100) i annotation (experiment(StopTime=3)); end BooleanTable; + model IntegerSwitch + extends Modelica.Icons.Example; + Modelica.Blocks.Sources.BooleanStep table1(startTime=1, startValue=true) + annotation (Placement(transformation(extent={{-80,-10},{-60,10}}))); + Modelica.Blocks.Logical.IntegerSwitch integerSwitch annotation (Placement(transformation(extent={{-10,-10},{10,10}}))); + Modelica.Blocks.Sources.ContinuousClock continuousClock annotation (Placement(transformation(extent={{-80,-50},{-60,-30}}))); + Modelica.Blocks.Sources.IntegerStep integerStep(startTime=2) + annotation (Placement(transformation(extent={{-80,30},{-60,50}}))); + Modelica.Blocks.Math.RealToInteger realToInteger annotation (Placement(transformation(extent={{-50,-50},{-30,-30}}))); + equation + connect(table1.y, integerSwitch.u2) annotation (Line(points={{-59,0},{-12,0}}, color={255,0,255})); + connect(integerStep.y, integerSwitch.u1) annotation (Line(points={{-59,40},{-20,40},{-20,8},{-12,8}}, color={255,127,0})); + connect(continuousClock.y, realToInteger.u) annotation (Line(points={{-59,-40},{-52,-40}}, color={0,0,127})); + connect(realToInteger.y, integerSwitch.u3) annotation (Line(points={{-29,-40},{-20,-40},{-20,-8},{-12,-8}}, color={255,127,0})); + annotation (experiment(StopTime=3.1)); + end IntegerSwitch; + model RootMeanSquare extends Modelica.Icons.Example; Modelica.Blocks.Math.Mean mean1(f=expSine.f) diff --git a/ModelicaTest/Resources/Reference/ModelicaTest/Blocks/IntegerSwitch/comparisonSignals.txt b/ModelicaTest/Resources/Reference/ModelicaTest/Blocks/IntegerSwitch/comparisonSignals.txt new file mode 100644 index 0000000000..5b935ee484 --- /dev/null +++ b/ModelicaTest/Resources/Reference/ModelicaTest/Blocks/IntegerSwitch/comparisonSignals.txt @@ -0,0 +1,2 @@ +time +integerSwitch.y diff --git a/ModelicaTest/Resources/Reference/ModelicaTest/Blocks/Shifters/comparisonSignals.txt b/ModelicaTest/Resources/Reference/ModelicaTest/Blocks/Shifters/comparisonSignals.txt new file mode 100644 index 0000000000..d1c091ac4f --- /dev/null +++ b/ModelicaTest/Resources/Reference/ModelicaTest/Blocks/Shifters/comparisonSignals.txt @@ -0,0 +1,5 @@ +time +zeroProtection.y +linearShifter.y +sinSquareShifter.y +variableLinearShifter.y diff --git a/ModelicaTest/Resources/Reference/ModelicaTest/Blocks/Vectors/comparisonSignals.txt b/ModelicaTest/Resources/Reference/ModelicaTest/Blocks/Vectors/comparisonSignals.txt new file mode 100644 index 0000000000..15ba618deb --- /dev/null +++ b/ModelicaTest/Resources/Reference/ModelicaTest/Blocks/Vectors/comparisonSignals.txt @@ -0,0 +1,3 @@ +time +scalarProduct.y +normalizeVector.y