Ticket #1159: test.mo

File test.mo, 1.3 KB (added by Henning Kiel, 15 years ago)

{{{OpenModelica 1.5.0 Copyright (c) OSMC 2002-2009

To get help on using OMShell and OpenModelica, type "help()" and press enter.

cd()

"C:/OpenModelica1.5.0/tmp"

system("gcc -c test.c")

0

loadFile("test.mo")

true

simulate(Motor, stopTime=1.0, numberOfIntervals=2000)

record SimulationResult

resultFile = "Motor_res.plt"

end SimulationResult;

}}} edit test.h such that a compile error must occur (e.g. "int" -> "intx")

>> simulate(Motor, stopTime=1.0, numberOfIntervals=2000)

record SimulationResult

    resultFile = "Motor_res.plt"

end SimulationResult;
 
>> }}}
Line 
1package PhysicalModels
2 block MotorModel
3 parameter Real R=1;
4 parameter Real L=0.001;
5 parameter Real U=12;
6 parameter Real kphi=0.1;
7 parameter Real J=0.0005;
8
9 Real I(start=0);
10 output Real omega(start=0);
11 output Real Position(start=-100);
12 protected
13 Real frc(start=0);
14
15 equation
16 frc = if Position > -25 then -50*(Position+25) else 0;
17 der(I) = (U - R*I - kphi*omega)/L;
18 der(omega) = kphi*I/J + frc;
19 der(Position) = omega;
20 end MotorModel;
21
22 block Hall
23 input Real Position(start=-100);
24 output Integer HallSignal(start=0);
25 output Integer HallPos(start=0);
26 algorithm
27 if sin(Position*10.0) > 0 then
28 HallSignal := -10;
29 HallPos := HallPos + 1;
30 elseif sin(Position*10.0) < 0 then
31 HallSignal := 0;
32 HallPos := HallPos + 1;
33 end if;
34 end Hall;
35end PhysicalModels;
36
37
38model Motor
39 function Count_Fkt
40 input Real omega;
41 output Integer Counter;
42 external "C" Counter = Count_Fkt(omega) annotation(Library="test.o",Include="#include \"test.h\"");
43 end Count_Fkt;
44
45 PhysicalModels.MotorModel mot;
46 PhysicalModels.Hall hall;
47 Integer Counter(start=0);
48
49equation
50 connect(mot.Position, hall.Position);
51
52algorithm
53 if hall.HallSignal <> pre(hall.HallSignal) then
54 Counter := Count_Fkt(mot.omega);
55 end if;
56
57end Motor;