1 | package TestOptAnn
|
---|
2 | model BangBang "Model to verify that optimization gives bang-bang optimal control"
|
---|
3 | parameter Real m = 1;
|
---|
4 | parameter Real p = 1 "needed for final constraints";
|
---|
5 | Real a;
|
---|
6 | Real v(start = 0);
|
---|
7 | Real pos(start = 0);
|
---|
8 | Real pow(min = -30, max = 30) = f * v annotation(
|
---|
9 | isConstraint = true);
|
---|
10 | input Real f(min = -10, max = 10);
|
---|
11 | Real costPos(nominal = 1) = -pos "minimize -pos(tf)" annotation(
|
---|
12 | isMayer = true);
|
---|
13 | Real conSpeed(min = 0, max = 0) = p * v " 0<= p*v(tf) <=0 " annotation(
|
---|
14 | isFinalConstraint = true);
|
---|
15 | equation
|
---|
16 | der(pos) = v;
|
---|
17 | der(v) = a;
|
---|
18 | f = m * a;
|
---|
19 | annotation(
|
---|
20 | experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-08, Interval = 0.0142857),
|
---|
21 | __OpenModelica_commandLineOptions="+gDynOpt",
|
---|
22 | __OpenModelica_simulationFlags(optimizerNP = "1", s = "optimization"));
|
---|
23 | end BangBang;
|
---|
24 |
|
---|
25 |
|
---|
26 |
|
---|
27 | model RL
|
---|
28 | Modelica.Electrical.Analog.Basic.Resistor resistor1(R = 1) annotation(
|
---|
29 | Placement(visible = true, transformation(origin = {-18, 36}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
|
---|
30 | Modelica.Electrical.Analog.Basic.Inductor inductor1(L = 0.1) annotation(
|
---|
31 | Placement(visible = true, transformation(origin = {38, 6}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
|
---|
32 | Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage1 annotation(
|
---|
33 | Placement(visible = true, transformation(origin = {-66, 18}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
|
---|
34 | Modelica.Electrical.Analog.Basic.Ground ground1 annotation(
|
---|
35 | Placement(visible = true, transformation(origin = {-66, -32}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
|
---|
36 | equation
|
---|
37 | connect(resistor1.p, constantVoltage1.p) annotation(
|
---|
38 | Line(points = {{-28, 36}, {-66, 36}, {-66, 28}}, color = {0, 0, 255}));
|
---|
39 | connect(resistor1.n, inductor1.p) annotation(
|
---|
40 | Line(points = {{-8, 36}, {38, 36}, {38, 16}}, color = {0, 0, 255}));
|
---|
41 | connect(ground1.p, constantVoltage1.n) annotation(
|
---|
42 | Line(points = {{-66, -22}, {-66, -22}, {-66, 8}, {-66, 8}}, color = {0, 0, 255}));
|
---|
43 | connect(constantVoltage1.n, inductor1.n) annotation(
|
---|
44 | Line(points = {{-66, 8}, {-66, 8}, {-66, -14}, {38, -14}, {38, -4}, {38, -4}}, color = {0, 0, 255}));
|
---|
45 | annotation(
|
---|
46 | Diagram(coordinateSystem(extent = {{-100, -80}, {100, 80}})),
|
---|
47 | experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-07, Interval = 0.002));end RL;
|
---|
48 | annotation(
|
---|
49 | Diagram(coordinateSystem(extent = {{-100, -80}, {100, 80}})),
|
---|
50 | uses(Modelica(version = "3.2.2")));
|
---|
51 | end TestOptAnn;
|
---|