Ticket #1159: test.mo
| File test.mo, 1.3 KB (added by , 16 years ago) |
|---|
| Line | |
|---|---|
| 1 | package 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; |
| 35 | end PhysicalModels; |
| 36 | |
| 37 | |
| 38 | model 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 | |
| 49 | equation |
| 50 | connect(mot.Position, hall.Position); |
| 51 | |
| 52 | algorithm |
| 53 | if hall.HallSignal <> pre(hall.HallSignal) then |
| 54 | Counter := Count_Fkt(mot.omega); |
| 55 | end if; |
| 56 | |
| 57 | end Motor; |
