1 | model plant
|
---|
2 | /* A PID Controller Controller */
|
---|
3 |
|
---|
4 | parameter Real Kc = 2 ; // Proportional Gain (%)
|
---|
5 | parameter Real Ti = 20 ; // Integral Time
|
---|
6 | parameter Real Td = 1e-3 ; // Derivative Time
|
---|
7 | parameter Boolean reverseActing = false;
|
---|
8 | /* Manipulated varibale decreases when
|
---|
9 | measured variable increases */
|
---|
10 |
|
---|
11 | parameter Real mvMin = 0;
|
---|
12 | parameter Real mvMax = 100;
|
---|
13 | parameter Real pvMin = 0;
|
---|
14 | parameter Real pvMax = 100;
|
---|
15 | parameter Integer action = if reverseActing then -1
|
---|
16 | else 1 ;
|
---|
17 |
|
---|
18 |
|
---|
19 | Real sp; // Setpoint
|
---|
20 | Real pv; // Measured value
|
---|
21 | Real mv(min = 0, max = 1); // Controller Output (manipulated value)
|
---|
22 | Real err; // Setpoint - Measurevalue
|
---|
23 | Real intErr; // error integral
|
---|
24 | Real x, derx, y;
|
---|
25 | Real BandGain ;
|
---|
26 |
|
---|
27 | equation
|
---|
28 | err = (sp - pv) ;
|
---|
29 | // Integral Action with (No windup)
|
---|
30 | der(intErr) = noEvent(if mv < mvMin and err < 0
|
---|
31 | or
|
---|
32 | mv > mvMax and err > 0
|
---|
33 | then 0 else err);
|
---|
34 |
|
---|
35 | BandGain = action * 100 * (mvMax - mvMin) / (pvMax - pvMin) ;
|
---|
36 | mv = BandGain * Kc * ( err + intErr / Ti + Td * der(err) ) ;
|
---|
37 |
|
---|
38 | derx = der(x);
|
---|
39 | y = der(derx) + 2 * 0.5 * der(x) + x;
|
---|
40 |
|
---|
41 | sp = 0.5;
|
---|
42 | pv = y;
|
---|
43 | mv = x;
|
---|
44 | initial equation
|
---|
45 | intErr = 0;
|
---|
46 | derx = 2.0;
|
---|
47 |
|
---|
48 | end plant;
|
---|