1 | #*------------------------------------------------------------------- |
---|
2 | * EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC. |
---|
3 | * |
---|
4 | * This LIBRARY is free software; you can distribute it and/or modify |
---|
5 | * it under the therms of the ALSOC FREE LICENSE as available at |
---|
6 | * http://www.enq.ufrgs.br/alsoc. |
---|
7 | * |
---|
8 | * EMSO is distributed under the terms of the ALSOC LICENSE as |
---|
9 | * available at http://www.enq.ufrgs.br/alsoc. |
---|
10 | *----------------------------------------------------------------------- |
---|
11 | * Author: Jonathan Ospino P. |
---|
12 | * $Id: PID_id.mso 2012$ |
---|
13 | *---------------------------------------------------------------------*# |
---|
14 | |
---|
15 | using "types"; |
---|
16 | |
---|
17 | Model PID_id |
---|
18 | |
---|
19 | ATTRIBUTES |
---|
20 | |
---|
21 | Pallete=true; |
---|
22 | Icon="icon/PID"; |
---|
23 | Info="== PID Controller block =="; |
---|
24 | |
---|
25 | PARAMETERS |
---|
26 | |
---|
27 | #Controller Options |
---|
28 | Controller_Mode as Switcher(Valid=["P","I","D","PI","PD","PID"],Default="PID"); |
---|
29 | Controller_Structure as Switcher(Valid=["Ideal","Approx. Derivative"],Default="Ideal"); |
---|
30 | |
---|
31 | # PID Parameters |
---|
32 | Kc as Real(Brief="Proportional controller gain"); |
---|
33 | TauI as Real(Brief="Integral or reset time",Unit='s'); |
---|
34 | TauD as Real(Brief="Derivative time",Unit='s'); |
---|
35 | N as Real(Brief="Divisor terms when the approximative approach",Unit='1/s', Default=100); |
---|
36 | |
---|
37 | |
---|
38 | VARIABLES |
---|
39 | |
---|
40 | in e as Real(Brief="Deviation error",Protected=true,PosX=0,PosY=0.5); |
---|
41 | Inte as Real(Brief="Integral of the error",Hidden=true); |
---|
42 | Diffe as Real(Brief="Derivative of the error",Hidden=true); |
---|
43 | |
---|
44 | P as Real(Brief="Proportional action",Hidden=true); |
---|
45 | I as Real(Brief="Integral or reset action",Hidden=true); |
---|
46 | D1 as Real(Brief="Derivative or anticipative action for structure 1",Hidden=true); |
---|
47 | D2 as Real(Brief="Derivative or anticipative action for structure 2",Hidden=true); |
---|
48 | D as Real(Brief="Final Derivative or anticipative action",Hidden=true); |
---|
49 | out m as Real(Brief="Controller Output",PosX=1, PosY=0.5,Protected=true); |
---|
50 | |
---|
51 | |
---|
52 | EQUATIONS |
---|
53 | |
---|
54 | "Integral of the error" |
---|
55 | diff(Inte)*'s'=e; |
---|
56 | |
---|
57 | "Derivative of the error" |
---|
58 | Diffe=diff(e)*'s'; |
---|
59 | |
---|
60 | "Proportional action" |
---|
61 | P=Kc*e; |
---|
62 | |
---|
63 | "Integral or reset action" |
---|
64 | I=Kc*(Inte/TauI)*'s'; |
---|
65 | |
---|
66 | switch Controller_Structure |
---|
67 | case "Ideal": |
---|
68 | "Derivative or anticipative action" |
---|
69 | D1=Kc*TauD*Diffe/'s'; |
---|
70 | diff(D2)*'s'=0; |
---|
71 | D=D1; |
---|
72 | case "Approx. Derivative": |
---|
73 | "Derivative or anticipative action" |
---|
74 | (1/N)*diff(D2)+D2=Kc*TauD*Diffe/'s'; |
---|
75 | D1=0; |
---|
76 | D=D2; |
---|
77 | end |
---|
78 | |
---|
79 | #PID Controller equation |
---|
80 | switch Controller_Mode |
---|
81 | case "P": |
---|
82 | m=P; |
---|
83 | case "I": |
---|
84 | m=I; |
---|
85 | case "D": |
---|
86 | m=D; |
---|
87 | case "PI": |
---|
88 | m=P+I; |
---|
89 | case "PID": |
---|
90 | m=P+I+D; |
---|
91 | case "PD": |
---|
92 | m=P+D; |
---|
93 | end |
---|
94 | |
---|
95 | |
---|
96 | INITIAL |
---|
97 | |
---|
98 | Inte=0; |
---|
99 | D2=0; |
---|
100 | |
---|
101 | end |
---|
102 | |
---|
103 | #* |
---|
104 | Notes: |
---|
105 | |
---|
106 | (1) The "PID with approximate Derivative" approach of Simulink was implemented too. |
---|
107 | |
---|
108 | (2) The controller modes I and D were added for analysis purposes. |
---|
109 | |
---|
110 | |
---|
111 | Revision Date: 09.11.2012 |
---|
112 | |
---|
113 | *# |
---|