Skip to content

Commit

Permalink
adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaRB committed Nov 29, 2024
1 parent 336a485 commit ba6ae4f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
31 changes: 14 additions & 17 deletions resources/modelica_libraries/CRMLtoModelica.mo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ record CRMLClock
CRMLtoModelica.Types.Boolean4 b (start= CRMLtoModelica.Types.Boolean4.false4);

Real ticks[50](each start = -1, each fixed = true);
discrete Integer counter(start=1, fixed=true);
discrete Integer counter(start=0, fixed=true);

CRMLtoModelica.Types.Boolean4 out(start = CRMLtoModelica.Types.Boolean4.false4);

Expand All @@ -18,19 +18,22 @@ end CRMLClock;

CRMLClock clock;

protected Boolean e;
Boolean e;

initial algorithm

algorithm
e := (clock.b == CRMLtoModelica.Types.Boolean4.true4 and change(clock.b));
when (e) then
clock.ticks[clock.counter] := time;
//e := (clock.b == CRMLtoModelica.Types.Boolean4.true4);
when (clock.b == CRMLtoModelica.Types.Boolean4.true4 and change(clock.b)) then
clock.counter := pre(clock.counter)+1;
clock.ticks[clock.counter] := time;

end when;

equation
clock.out = Functions.cvBooleanToBoolean4(e);
clock.out = Functions.cvBooleanToBoolean4(e);

end CRMLClock_build;

type Boolean4 = enumeration(
Expand Down Expand Up @@ -308,24 +311,18 @@ end cvBooleanToBoolean4;
output Types.CRMLClock out annotation (
Placement(transformation(extent={{100,-10},{120,10}}),
iconTransformation(extent={{100,-10},{120,10}})));

Types.CRMLClock_build clock_c(clock=out);
input Types.Boolean4 r2 //cond
"Condition" annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=0,
origin={-110,80})));
equation

algorithm
e := (r1.out == CRMLtoModelica.Types.Boolean4.true4 and r2 == CRMLtoModelica.Types.Boolean4.true4 and change(r2));
when (e ) then
out.ticks[out.counter] := time;
out.counter := pre(out.counter)+1;
out.out := CRMLtoModelica.Types.Boolean4.true4 ;
out.b :=Functions.cvBooleanToBoolean4(e);
end when;

e = (r1.out == CRMLtoModelica.Types.Boolean4.true4 and r2 == CRMLtoModelica.Types.Boolean4.true4);

out.b = Functions.cvBooleanToBoolean4(e);


annotation (Icon(coordinateSystem(preserveAspectRatio=false), graphics={
Rectangle(
Expand Down Expand Up @@ -503,7 +500,7 @@ end cvBooleanToBoolean4;

input CRMLtoModelica.Types.CRMLClock r1;

output Integer out(start = 0);
output Integer out;

equation
out = r1.counter;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/crml/compiler/OperatorMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ public static HashMap<String, List<Signature>> get_operator_map() {
List<Signature> and_sigs = Arrays.asList(
new Signature("CRMLtoModelica.Functions.and4", bool2, params, "Boolean", Type.FUNCTION),
new Signature("arrayAnd", bool1, params, "Boolean", Type.SET_OP, setUnary, false),
new Signature("CRMLtoModelica.Blocks.unaryBoolAnd", bool1, params, "Boolean", Type.BLOCK));
new Signature("CRMLtoModelica.Blocks.unaryBoolAnd", bool1, params, "Boolean", Type.BLOCK),
new Signature ("andOnPeriod", Arrays.asList("Periods"), params, "Boolean", Type.FUNCTION));
built_in_operators.put("and", and_sigs);

// or operators
Expand Down
Binary file added test_model.zip
Binary file not shown.
4 changes: 4 additions & 0 deletions test_model/package.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
within ;
package test_model

end test_model;
1 change: 1 addition & 0 deletions test_model/package.order
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test_clock
10 changes: 10 additions & 0 deletions test_model/test_clock.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
within test_model;

model test_clock

CRMLtoModelica.Types.Boolean4 b1 = if (CRMLtoModelica.Functions.and4(CRMLtoModelica.Functions.cvBooleanToBoolean4(time < 5), CRMLtoModelica.Functions.cvBooleanToBoolean4(2.5 < time))== CRMLtoModelica.Types.Boolean4.true4) then CRMLtoModelica.Types.Boolean4.true4 else CRMLtoModelica.Types.Boolean4.false4;

CRMLtoModelica.Types.CRMLClock C1 = c8;
CRMLtoModelica.Types.CRMLClock c8(b=b1);
CRMLtoModelica.Types.CRMLClock_build c8_init(clock =c8);
end test_clock;

0 comments on commit ba6ae4f

Please sign in to comment.