Setup for position control

This commit is contained in:
2026-03-11 19:08:49 +01:00
parent 9e124a5e92
commit cbe611916e
2 changed files with 178 additions and 91 deletions

View File

@@ -12,16 +12,15 @@ package EmbeddedControl
Placement(transformation(origin = {86, -34}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {110, 0}, extent = {{-10, -10}, {10, 10}})));
Modelica.Blocks.Interfaces.BooleanInput tickInput annotation(
Placement(transformation(origin = {-130, -88}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {0, -120}, extent = {{-20, -20}, {20, 20}}, rotation = 90)));
protected
discrete Integer yInt(start=0, fixed=true);
discrete Integer y_internal(start=0, fixed=true);
algorithm
when tickInput then
yInt := integer(floor((scale*u)/stepSize+ 0.5));
y_internal := integer(floor((scale*u)/stepSize+ 0.5));
end when;
equation
y = yInt;
y = y_internal;
annotation(
Documentation(info = "<html>
@@ -245,6 +244,27 @@ end UnitDelay;
Icon(graphics = {Text(textColor = {255, 85, 0}, extent = {{-100, 100}, {100, -100}}, textString = "k"), Text(extent = {{-150, -140}, {150, -100}}, textString = "k=%k")}),
Diagram(graphics));
end ScaledGain;
model Limiter
extends EmbeddedControl.Bases.discreteIntegerSISO;
parameter Integer limit = 100;
protected
discrete Integer y_internal(start=0, fixed=true);
algorithm
if u > limit then
y_internal := limit;
elseif u < -limit then
y_internal := -limit;
else
y_internal := u;
end if;
equation
y = y_internal;
annotation(
Diagram(graphics),
Icon(graphics = {Line(points = {{0, -90}, {0, 68}}, color = {156, 156, 156}), Polygon(lineColor = {156, 156, 156}, fillColor = {192, 192, 192}, fillPattern = FillPattern.Solid, points = {{0, 90}, {-8, 68}, {8, 68}, {0, 90}}), Line(points = {{-90, 0}, {68, 0}}, color = {156, 156, 156}), Polygon(lineColor = {156, 156, 156}, fillColor = {192, 192, 192}, fillPattern = FillPattern.Solid, points = {{90, 0}, {68, -8}, {68, 8}, {90, 0}}), Line(origin = {-36, -36}, points = {{-46, -24}, {-8, -24}, {-8, -8}, {8, -8}, {8, 10}, {22, 10}, {22, 24}, {22, 24}}, color = {255, 85, 0}, thickness = 0.5), Line(origin = {34.5, 20}, points = {{-48.5, -32}, {-34.5, -32}, {-34.5, -20}, {-20.5, -20}, {-20.5, -4}, {-2.5, -4}, {-2.5, 16}, {11.5, 16}, {11.5, 32}, {49.5, 32}, {27.5, 32}}, color = {255, 85, 0}, thickness = 0.5)}));
end Limiter;
annotation(
Icon(graphics = {Line(origin = {-0.95, 0.62}, points = {{-75.0496, -68.6246}, {-61.0496, 1.37545}, {-29.0496, 69.3754}, {-5.04956, 1.37545}, {20.9504, -64.6246}, {50.9504, -2.62455}, {74.9504, 65.3754}, {74.9504, 65.3754}}, color = {255, 85, 0}, thickness = 2, smooth = Smooth.Bezier)}));
end Math;
@@ -296,6 +316,53 @@ end UnitDelay;
equation
end Bases;
package Util
extends Modelica.Icons.UtilitiesPackage;
model PID
extends EmbeddedControl.Bases.discreteIntegerSISO;
parameter Integer kP = 1;
parameter Integer kI = 1;
parameter Integer kD = 1;
parameter Integer scale = 1000000;
EmbeddedControl.Math.Gain P(k = kP) annotation(
Placement(transformation(extent = {{-10, -10}, {10, 10}})));
EmbeddedControl.Math.DDifferentiate dDifferentiate(scaleNumerator = scale) annotation(
Placement(transformation(origin = {-40, 40}, extent = {{-10, -10}, {10, 10}})));
Modelica.Blocks.MathInteger.Sum sum1(nu = 3) annotation(
Placement(transformation(origin = {50, 0}, extent = {{-10, -10}, {10, 10}})));
EmbeddedControl.Math.Gain D(k = kD) annotation(
Placement(transformation(origin = {0, 40}, extent = {{-10, -10}, {10, 10}})));
EmbeddedControl.Math.DIntegrate dIntegrate(scaleDenominator = scale) annotation(
Placement(transformation(origin = {-38, -40}, extent = {{-10, -10}, {10, 10}})));
EmbeddedControl.Math.Gain I(k = kI) annotation(
Placement(transformation(origin = {0, -40}, extent = {{-10, -10}, {10, 10}})));
protected outer Boolean tickUpdate;
equation
connect(P.y, sum1.u[1]) annotation(
Line(points = {{11, 0}, {40, 0}}, color = {255, 127, 0}));
connect(dDifferentiate.y, D.u) annotation(
Line(points = {{-29, 40}, {-12, 40}}, color = {255, 127, 0}));
connect(D.y, sum1.u[2]) annotation(
Line(points = {{11, 40}, {20, 40}, {20, 0}, {40, 0}}, color = {255, 127, 0}));
connect(dIntegrate.y, I.u) annotation(
Line(points = {{-27, -40}, {-12, -40}}, color = {255, 127, 0}));
connect(I.y, sum1.u[3]) annotation(
Line(points = {{11, -40}, {19, -40}, {19, 0}, {40, 0}}, color = {255, 127, 0}));
connect(u, dDifferentiate.u) annotation(
Line(points = {{-100, 0}, {-70, 0}, {-70, 40}, {-52, 40}}, color = {255, 127, 0}));
connect(u, P.u) annotation(
Line(points = {{-100, 0}, {-12, 0}}, color = {255, 127, 0}));
connect(u, dIntegrate.u) annotation(
Line(points = {{-100, 0}, {-70, 0}, {-70, -40}, {-50, -40}}, color = {255, 127, 0}));
connect(sum1.y, y) annotation(
Line(points = {{62, 0}, {100, 0}}, color = {255, 127, 0}));
annotation(
Icon(graphics = {Text(textColor = {255, 85, 0}, extent = {{-100, 100}, {100, -100}}, textString = "PID")}),
Diagram(coordinateSystem(extent = {{-120, 60}, {120, -60}})));
end PID;
end Util;
annotation(
Icon(graphics = {Text(origin = {1, 1}, textColor = {255, 170, 0}, extent = {{-99, 99}, {99, -99}}, textString = "EC", textStyle = {TextStyle.Bold})}),
uses(Modelica(version = "4.1.0")));