Skip to content

Commit 63dc322

Browse files
Added test for timeInState()
1 parent a78d0d2 commit 63dc322

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

simulation/modelica/statemachines/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ConferenceTut1.mos \
55
Maraninchi2003_2.mos \
66
SMMin.mos \
77
TicksInState.mos \
8+
TimeInState.mos \
89

910
# test that currently fail. Move up when fixed.
1011
# Run make failingtest
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
within ;
2+
model TimeInState "Test for TimeInState"
3+
inner Integer i(start = 0);
4+
5+
block State1
6+
outer output Integer i;
7+
equation
8+
i = previous(i) + 2;
9+
annotation(Icon(graphics={ Text(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, textString = "%name")}), Diagram(graphics={ Text(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, textString = "%stateText", fontSize = 10)}), __Dymola_state = true, showDiagram = true, singleInstance = true);
10+
end State1;
11+
12+
State1 state1 annotation(Placement(transformation(extent={{-56,62},{-10,76}})));
13+
14+
block State2
15+
outer output Integer i;
16+
equation
17+
i = previous(i) - 1;
18+
annotation(Icon(graphics={ Text(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, textString = "%name")}), Diagram(graphics={ Text(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, textString = "%stateText", fontSize = 10)}), __Dymola_state = true, showDiagram = true, singleInstance = true);
19+
end State2;
20+
21+
State2 state2 annotation(Placement(transformation(extent={{-56,40},{-12,54}})));
22+
equation
23+
transition(state1, state2, timeInState() > 4,
24+
immediate=false, reset=true, synchronize=false, priority=1) annotation(Line(points={{-8,69},
25+
{-4,58},{-10,47}}, color = {175, 175, 175}, thickness = 0.25, smooth = Smooth.Bezier), Text(string = "%condition", extent = {{6, -4}, {6, -10}}, lineColor = {95, 95, 95}, fontSize=10, textStyle = {TextStyle.Bold}, horizontalAlignment = TextAlignment.Left));
26+
transition(state2, state1, timeInState() > 5,
27+
immediate=false, reset=true, synchronize=false, priority=1) annotation(Line(points={{-58,47},
28+
{-66,58},{-58,69}}, color = {175, 175, 175}, thickness = 0.25, smooth = Smooth.Bezier), Text(string = "%condition", extent = {{-6, 4}, {-6, 10}}, lineColor = {95, 95, 95}, fontSize=10, textStyle = {TextStyle.Bold}, horizontalAlignment = TextAlignment.Right));
29+
initialState(state1) annotation(Line(points={{-34.5336,78},{-36,84}}, color = {175, 175, 175}, thickness = 0.25, smooth = Smooth.Bezier, arrow = {Arrow.Filled, Arrow.None}));
30+
annotation(Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics={ Text(extent = {{-62, 94}, {-12, 84}}, lineColor = {0, 0, 0}, fontSize = 10,
31+
horizontalAlignment = TextAlignment.Left, textString = "%declarations")}));
32+
end TimeInState;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// name: TimeInState
2+
// keywords: state machines
3+
// status: correct
4+
//
5+
6+
loadFile("TimeInState.mo");
7+
simulate(TimeInState, startTime=0, stopTime=30, numberOfIntervals=0); getErrorString();
8+
val(i,30.0);
9+
10+
// Result:
11+
// true
12+
// record SimulationResult
13+
// resultFile = "TimeInState_res.mat",
14+
// simulationOptions = "startTime = 0.0, stopTime = 30.0, numberOfIntervals = 0, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'TimeInState', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = ''",
15+
// messages = ""
16+
// end SimulationResult;
17+
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
18+
// "
19+
// 20.0
20+
// endResult

0 commit comments

Comments
 (0)