Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/examples/control.m4

raw
1 .PS
2 # control.m4
3 gen_init
4 linewid = linewid*0.8
5 circlerad = 0.35/2
6 bw = boxwid/2
7 bh = boxht/2
8
9 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . #
10
11 PID: [
12 {"$r(s)$" above ljust}
13 arrow
14 S1: circle
15 line right "$e(s)$" above
16 { arrow right ; box ht bh wid bw "$K_P$"
17 arrow right linewid-circlerad ; S2: circle }
18 { arrow up linewid then right ; box ht bh wid bw "$K_D s$"
19 arrow to (S2,Here) then to S2.n }
20 { arrow down linewid then right ; box ht bh wid bw "$K_I/s$"
21 arrow to (S2,Here) then to S2.s }
22 arrow right from S2.e "$u(s)$" above
23 box "$G(s)$"
24 arrow right ; "$y(s)$" above rjust at Here+(0,2pt__)
25 arrow down boxht*5/4 from last arrow.c then left last arrow.c.x-S1.x \
26 then to S1.s
27 "$-\;$" below rjust
28 ]
29 "(a) $PID$ control" below ljust at PID.sw+(0,-5pt__)
30
31 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . #
32
33 # https://tex.stackexchange.com/questions/575592/how-to-create-a-controls-system-diagram
34 Observer: [
35 define(`thickarrow',`arrow thick 3 wid 7bp__')
36 define(`thickline',`line thick 3')
37 fillval = 0.6
38 boxwid = 0.3
39 boxht = 0.4
40 circlerad = 0.1
41 {"$r$" above ljust}
42 R: arrow
43 S: circle fill
44 {"$-$" below ljust at S.s; "$+$" above rjust at S.w+(2bp__,0)}
45 { OLP: box invis fill 0.9 wid 3.1 ht 1.4 with .nw at Here+(0.3,boxht*5/4)
46 "\sf plant" at OLP.sw above ljust }
47 U: arrow right 0.4
48 {"$u$" at last arrow+(2bp__,0) above }
49 Bp: box fill "$B$"
50 thickarrow right 0.4
51 Sp: circle fill
52 {"$\;+$" below ljust at Sp.s; "$+$" above rjust at Sp.w+(2bp__,2bp__)}
53 thickarrow right 0.4
54 {"`$\dot{\mathbf x}$'" at last arrow + (0,7bp__)}
55 Ip: box fill "$I/s$"
56 thickarrow right 1
57 {"$\mathbf x$" at last arrow + (0,7bp__) }
58 Cp: box fill "$C$"
59 # print Cp.e.x - Bp.w.x + 0.2
60 thickline right 0.4
61 Yp: thickarrow
62 {"$\mathbf y$" at last arrow + (0,7bp__) }
63 Ap: box fill "$A$" with .n at Ip.s+(0,-boxht/2)
64 thickarrow <- from Ap.e right 0.4 then up Ip.y-Ap.y
65 thickarrow from Ap.w to (Sp,Ap) then to Sp.s
66 # print OLP.n.y-Ap.s.y+0.1
67 #
68 K: box fill "$K$" at Ap + (0,-boxht*3/2)
69 arrow from K.w to (S,K) then to S.s
70 {OBS: box invis fill 0.9 wid 4.3 ht 1.8 with .nw at (S.w,K.s)-(0.1,0.1)
71 "\sf observer" at OBS.sw ljust above }
72 Io: box fill "$I/s$" at K + (0,-boxht*3/2)
73 thickarrow <- from Io.w left 0.4
74 {"`$\dot{\hat{\mathbf x}}$'" at last arrow + (0,7bp__)}
75 Sxo: circle fill
76 {"$\;+$" below ljust at Sxo.s; "$+$" above rjust at Sxo.w+(2bp__,2bp__)}
77 thickarrow <- left 0.4
78 SLo: circle fill
79 {"$\;+$" below ljust at SLo.s; "$+$" above rjust at SLo.w+(2bp__,2bp__)}
80 thickarrow <- left 0.4
81 Bo: box fill "$B$"
82 arrow from 1/4 between U.start and U.end up boxht \
83 then left 2*boxht then down Bp.y-Bo.y+boxht then to Bo.w
84 Ao: box fill "$A$" with .n at Io.s+(0,-boxht/2)
85 thickline from Io.e right 0.4
86 {thickarrow <-> from K.e to (Here,K.e) then to (Here,Ao) then to Ao.e
87 thickarrow from Ao.w to (Sxo,Ao.w) then to Sxo.s }
88 Xhat: Here
89 Co: box fill "$C$" at (Cp,Here)
90 thickarrow right 0.4
91 {"$\hat{\mathbf y}$" at last arrow + (0,7bp__) }
92 { thickarrow from Xhat to Co.w }
93 {"$\hat{\mathbf x}$" at last arrow + (0,7bp__) }
94 Syo: circle fill
95 {"$\;+$" above ljust at Syo.n; "$-$" below rjust at Syo.w+(2bp__,-2bp__)}
96 thickarrow <- from Syo.n to (Syo,Cp)
97 Lo: box fill "$L$" with .n at Ao.s+(0,-boxht/2)
98 # print Io.n.y+0.1 - (Lo.s.y-0.1)
99 thickarrow from Syo.s down Syo.s.y-Lo.y then to Lo.e
100 thickarrow from Lo.w to (SLo,Lo.w) then to SLo.s
101 ] with .nw at last [].sw+(0,-0.3)
102 "(b) Single-input plant with feedback from a full-order observer" \
103 below ljust at Observer.sw+(0,-5pt__)
104
105 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . #
106
107 ifelse(0,1,`
108 Observer: [ {"$r$" above ljust}
109 arrow
110 S: circle
111 "$-\;$" below rjust at S.s
112 arrow <- down linewid/2 from S.s
113 box ht bh wid bw "$K$"
114 arrow <- down linewid/2
115 line right linewid "$\hat x$" above
116 Obs:box wid linewid*5 ht boxht*5/4 \
117 "$\frac{d}{dt}\hat x = (A{-}LC)\hat x + B u + L y$"
118 "\sl Observer" above ljust at Obs.sw
119 arrow <- right linewid/2 from 3/4<Obs.se,Obs.ne>
120 line to (Here,S)
121 {"$u$" above at Here+(linewid/2,0)}
122 arrow from S.e to Here+(linewid,0)
123 Plant: box wid boxwid*3/2 ht boxht*5/4 \
124 "$\frac{d}{dt} x=Ax+Bu$" "$\quad y=Cx$\hfill\hbox{}"
125 "\sl Plant" above ljust at Plant.sw
126 arrow right from Plant.e
127 "$y$" above rjust at Here+(0,2pt__)
128 move to last arrow.c
129 line to (Here, 1/4<Obs.se,Obs.ne>)
130 arrow to (Obs.e,Here)
131 ] with .nw at last [].sw+(0,-0.5)
132 ')
133
134 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . #
135
136 ifelse(0,1,`
137 Multiblock: [
138 boxht = 0.4
139 boxwid = boxht
140 circlerad = boxht*0.4
141
142 define summer { [ C: circle
143 line from C.nw to C.se
144 line from C.sw to C.ne
145 "$$1$" at C.n+(0,1bp__) below
146 "$$2$" at C.s-(0,1bp__) above
147 "$$3$" at C.e+(1bp__,0) rjust
148 "$$4$" at C.w-(1bp__,0) ljust ]
149 }
150 define doublebox {[box "$$1$"; arrow; box "$$2$"]}
151
152 arrow "$E_1$" above
153 S1: summer(,-,,+)
154 linewid = boxwid/2
155 arrow "$\epsilon$" above
156 doublebox(H_1,H_2)
157 arrow
158 S2: summer(-,,,+)
159 arrow
160 T: doublebox(H_3,H_4)
161 line
162 Y: Here
163 arrow
164 "$S_1$" above
165 R1: box "$R_1$" at (T.x,T.y+boxht*5/4)
166 arrow from Y to (Y,R1) then to R1.e
167 arrow from R1.w to (S2,R1) then to S2.n
168 "$n_1$" ljust at S2.n+(0,boxht/2)
169 left
170 Rf: doublebox(R_2,R_3) at ((S1.x+T.x)/2,T.y-boxht*5/4)
171 arrow from T to (T,Rf) then to Rf.e
172 arrow from Rf.w to (S1,Rf) then to S1.s
173 "$n_2$" at S1.s+(0,-boxht/2) ljust
174 ] with .nw at Observer.sw + (0,-0.3)
175 "(c) A multiblock example" below ljust at last [].sw+(0,-3pt__)
176 ')
177
178 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . #
179
180 ifelse(0,1,`
181 Nonlinear: [boxwid = boxwid*3/2; boxht = boxht*3/2
182 thicklines_
183 scale = 0.8
184 circlerad = 0.3/2
185 R: box "reference" "$R$"
186 arrow right linewid*4/3 "${y_c}_{\hbox{\scriptsize ref}}$" above
187 Gh: box "```inverse'''" "$\hat G$"
188 arrow from Gh.s down "${y_m}_{\hbox{\scriptsize ref}}$" ljust
189 E: circle
190 arrow from E.e right "$e$" above
191 box "stabilizer" "$K$"
192 arrow "$\delta u$" above
193 D: circle
194 line from Gh.e to (D,Gh.e) "$u_{\hbox{\scriptsize ref}}$" above; corner
195 arrow to D.n
196 arrow from D.e right "$u$" above
197 G: box "plant" "$G$"
198 arrow <- from G.n up boxht/2
199 "disturbance $z$" above
200 arrow right from G.e + (0,boxht/4)
201 "$y_c$" ljust
202 arrow right from G.e + (0,-boxht/4)
203 "$y_m$" ljust
204 move to last arrow.c
205 arrow down Here.y-G.s.y+boxht*2/3 then left Here.x-E.x then to E.s
206 "$-$" at Here + (-0.15,-0.1)
207 arrow <- down from R.s
208 "$W$ control input" at Here - (0,0.1)
209 UL:R.nw +(-boxht/2,boxht/2)
210 UR:(D.e,UL) + (0.1,0)
211 line dashed from UL to UR then to (UR,G.s+(0,-boxht*3/2))
212 line dashed to (Gh.w,Here) "Controller" above
213 line dashed to (Here,Gh.s+(0,-boxht/2))
214 line dashed to (UL,Here) then to UL
215 ] with .nw at last [].sw + (0,-0.25)
216 "(d) Nonlinear feedforward (for performance) and small-signal feedback
217 (for stability)" below ljust at Nonlinear.sw+(0,-5pt__)
218 ')
219
220 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . #
221 # Gimbal.m4
222 # https://tex.stackexchange.com/questions/734796/how-to-create-a-gimbal-model-for-one-axis-using-tikz
223
224 #gen_init
225 Gimbal: [
226 textht = 15bp__
227 circlerad = 8bp__
228
229 iflatex(command "{\sf
230 \newcommand{\Sub}[1]{{\hbox{\scriptsize `#1'}}}")
231
232 Ir: arrow right_ linewid*3/2
233 { "Current" ljust at Ir.start+(-5bp__,textht) "reference" ljust
234 "$i_\Sub{reference}$" ljust at Ir.start-(0,textht*2/3) }
235 Ka: box "$K_a$"
236 { "Current" at Ka.s -(0,textht) "amplifier gain" }
237 arrow right_ linewid*3/2
238 { "Motor" at last arrow+(0,textht) "current" }
239 Kt: box "$K_t$"
240 { "Motor torque" at Kt.s -(0,textht) "constant" }
241 arrow
242 S1: circle; {"$-$" at S1.n above ljust; "$+$" at S1.w above rjust }
243 arrow right_ linewid*1.2
244 GI: box "$\frac{1}{J_\Sub{s}}$"; arrow "$\omega_h$" above
245 { "Gimbal inertia" at GI.s -(0,textht) }
246 S2: circle at Here+(0,3/2*boxht)
247 {"$-$" at S2.e above ljust; "$+$" at S2.s below rjust }
248 { arrow <- right_; "$\omega_b$" above rjust }
249 arrow left_ from S2.w to (GI.e,S2)
250 Bv: box "$B_v$"
251 arrow left_ "$T_\Sub{viscous}\mathstrut$" below from Bv.w to (S1.e,Bv)
252 S3: circle "$+$"
253 { arrow <- from S3.w; "$T_\Sub{ext}$" above ljust }
254 arrow from S3 to S1 chop
255 Fc: box ht boxht*3/2 at Bv+(0,boxht*7/4)
256 arrow from S2.n to (S2,Fc) then to Fc.e
257 arrow from Fc.w to (S3,Fc) then to S3.n
258 "$T_\Sub{friction}$" at (S3,Fc) above
259 [ Orig: Here; thicktmp = linethick; thicklines_(0.4)
260 V: arrow from Orig up_ Fc.ht*5/12
261 H: arrow right_ Fc.wid*5/6 with .c at Orig; thicklines_(thicktmp)
262 line thick 1.2 up Fc.ht/2 with .c at Orig
263 spline 0.55 thick 1.2 down_ boxht/5 right_ boxht/9 \
264 then right_ boxwid/9 then right_ boxwid/4 up_ boxwid/8
265 { "$F_c$" above rjust }
266 spline 0.55 thick 1.2 from last line.start up_ boxht/5 left_ boxht/9 \
267 then left_ boxwid/9 then left_ boxwid/4 down_ boxwid/8
268 { "${-}F_c$" below ljust }
269 ] with .Orig at Fc
270 Gl: box wid boxwid*5/4 with .e at GI.e+(0,-boxht*2) \
271 "$\frac{\omega_g^2}{s^2+2\zeta \omega_g s + \omega_g^2}$ "
272 { "Gyro lowpass" at Gl.s -(0,textht) }
273 arrow from Gl.e to (S2,Gl) then to S2.s
274 Gd: box wid boxwid*5/3 at (Kt,Gl) \
275 "$\frac{(d^2/12)\,s^2 - (d/2)\,s + 1}{(d^2/12)\,s^2 + (d/2)\,s + 1}$"
276 { "Gyro delay" at Gd.s -(0,textht) }
277 arrow left_ from Gl.w to Gd.e
278 arrow left_ from Gd.w chop 0 chop
279 S4: circle "$+$"
280 {"Gyro noise" at (S4,last ""); arrow from last "".n to S4.s }
281 Rm: arrow left_ from S4.w to (Ir.start,S4)
282 { "Rate" ljust at Here+(0,textht) "measurement" ljust }
283 "$w{}_\Sub{measured}$" ljust at Here-(0,textht*2/3)
284
285 iflatex(command "}%")
286 ] with .nw at last [].sw + (0,-0.25)
287 "(d) Single-axis gimbal model" below ljust at Gimbal.sw+(0,-5pt__)
288
289 #print PID.n.y - Gimbal.s.y
290 .PE