2021.10 Y. Minami

Python-Control Cheat Sheetfrom control.matlab import *import numpy as np

35Frequency response

Stability and Robustness

Pole & Zero

Bode diagram

P.pole()1System representation

Transfer Function

P = tf([0, 4], [1, 2, 3])s = tf('s')
P = 4/(s**2 + 2*s + 3)

Stability margin

Gain

Phase-180[deg]A = [[0, 1],[-4, -5]]
B = [[0], [1]]w [rad/s]
Frequency response at multiple angular frequencies
gain, phase, w = freqresp(sys, [omega])

2

Controllability and Reachability Matrix

Nyquist diagram

Vc = ctrb(P.A, P.B)

x, y, w = nyquist(P, logspace(-2,2,1000))

Vo = obsv(P.A, P.C)

<latexit sha1_base64="B0+dQHYVl/axLSstnacrMXjQK0Q=">AAACsXichVHLLgRRED3auz1mPBYSm4kJsZpUIyFiIbGx9BqPGBnd1zU6069090xCZ37AD1jYILHAZ9j4AQufIJYkNhZqeloEQd3ce+ueW6eqTsrwLDMIiR6alOaW1rb2jk61q7unN5Xu618P3IovZF64lutvGnogLdOR+dAMLbnp+VK3DUtuGOWF+v9GVfqB6Tpr4aEnd2y95Jj7ptBDhorpwYJnG5GaKbi2LOnFyBM1tVZMZylHsWV+OlriZJHYkpu+RQF7cCFQgQ0JByH7FnQEvLahgeAxtoOIMZ89M/6XqEFlboWjJEfojJb5LPFrO0EdftdzBjFbcBWLt8/MDEbpnq7ome7ohh7p7ddcUZyj3ssh30aDK71i6nho9fVfls13iINP1h89f8QGjPpxx5IjBaPWP1pD7GMmZpis2YuRunrRqFs9OnlenV0Zjcbogp5Y9zk90C0rd6ov4nJZrpxC5cFp38f001mfyGmU05ansvNzyQg7MIwRjPOcpjGPRSwhz3WPcIYrXCuTypayqxiNUKUp4Qzgiynld8nnnR8=</latexit>

PM

Pole = [-1, -2]
F = -acker(P.A, P.B, Pole)F = -place(P.A, P.B, Pole)

LQ optimal control

Delay = 0.5[s]2nd order appr.

T = np.arange(0, 10, 0.01)
y, t = impulse(P, T)
0, 0.01, 0.02,…,9.99

GM, PM, wpc, wgc = margin(P)print('GM=‘, 20*np.log10(GM))
print('PM=', PM)
print('wpc=', wpc) Phase crossover
print('wgc=', wgc) Gain crossover

Controller designnum, den = pade(0.5, 2)Pdelay = P*tf(num, den)Impulse response

Step response

6

Phase margin

Pole placement

Pade approximation

Time response

GM<latexit sha1_base64="CA5VUgVuxhKR41Y6e4MPJEf6Plc=">AAACsXichVHLLgRRED3auz1mPBYSm4kJsZpUIyFiIbGx9BqPGBnd1zU6069090xCZ37AD1jYILHAZ9j4AQufIJYkNhZqeloEQd3ce+ueW6eqTsrwLDMIiR6alOaW1rb2jk61q7unN5Xu618P3IovZF64lutvGnogLdOR+dAMLbnp+VK3DUtuGOWF+v9GVfqB6Tpr4aEnd2y95Jj7ptBDhorpwYJnG5GaKbi2LOnFqCRqaq2YzlKOYsv8dLTEySKxJTd9iwL24EKgAhsSDkL2LegIeG1DA8FjbAcRYz57ZvwvUYPK3ApHSY7QGS3zWeLXdoI6/K7nDGK24CoWb5+ZGYzSPV3RM93RDT3S26+5ojhHvZdDvo0GV3rF1PHQ6uu/LJvvEAefrD96/ogNGPXjjiVHCkatf7SG2MdMzDBZsxcjdfWiUbd6dPK8OrsyGo3RBT2x7nN6oFtW7lRfxOWyXDmFyoPTvo/pp7M+kdMopy1PZefnkhF2YBgjGOc5TWMei1hCnuse4QxXuFYmlS1lVzEaoUpTwhnAF1PK77XLnRY=</latexit>

Phase

C = np.eye(2)D = np.zeros([2, 1])
P = ss(A, B, C, D)

Gain margin

Gain
0[dB]

20*np.log10(gain) [dB]phase*180/np.pi [deg]State-Space Equation

pzmap(P)P.zero()gain, phase, w = bode(P, logspace(-2,2))

PPdelay

Q = [ [100, 0], [0, 1]]
R = 1
F, _, _ = lqr(P.A, P.B, Q, R)
F = -Fsolves the continuous-time algebraic Riccati equation

T = np.arange(0, 10, 0.01)
y, t = step(P, T)

Step response characteristics
Info = stepinfo(sys)

4(X, L, G) = care(A, B, Q, R)

Block diagram

series(S1，S2)

Initial condition responseparallel(S1，S2)

Mixed sensitivity designfrom control import mixsyn

K, _, gamma = mixsyn(Sys, w1=WS , w2=WU, w3=WT)<latexit sha1_base64="q9jQeFqFfWF+DcoZdS2ETssh+Rw=">AAACpnichVG7SgNBFD1ZXzE+ErURbMSgWIWJCAargI2VqDFGSILujqMumX2wOwnEkB+wFwtBUbAQP8PGH7DIJ4ilgo2FN5sVUdHcZXfOnDnnzr17DVeavmKsFdF6evv6B6KDsaHhkdF4Ymx823eqHhd57kjH2zF0X0jTFnllKil2XE/oliFFwaistM8LNeH5pmNvqborypZ+aJsHJtcVUcWSpasjrstGrrmbSLIUC2L6N0iHIIkw1p3EPUrYhwOOKiwI2FCEJXT49BSRBoNLXBkN4jxCZnAu0ESMvFVSCVLoxFboe0i7YsjatG/n9AM3p1skvR45pzHLHtkte2EP7I49sfc/czWCHO1a6rQaHa9wd+Mnk7m3ri6LVoWjL9c/NX9qfWK9oGJBSk6s7NKrwgEygcOknt2AaXfPO/fWjs9ecsubs405ds2eqe8r1mL31Llde+U3G2LzHDEaXPrnmH6D7YVUmvDGYjKbCUcYxRRmME9zWkIWq1hHPvjTp7jApTavrWl5rdCRapHQM4Fvoe19AG+Dmbs=</latexit><latexit sha1_base64="q9jQeFqFfWF+DcoZdS2ETssh+Rw=">AAACpnichVG7SgNBFD1ZXzE+ErURbMSgWIWJCAargI2VqDFGSILujqMumX2wOwnEkB+wFwtBUbAQP8PGH7DIJ4ilgo2FN5sVUdHcZXfOnDnnzr17DVeavmKsFdF6evv6B6KDsaHhkdF4Ymx823eqHhd57kjH2zF0X0jTFnllKil2XE/oliFFwaistM8LNeH5pmNvqborypZ+aJsHJtcVUcWSpasjrstGrrmbSLIUC2L6N0iHIIkw1p3EPUrYhwOOKiwI2FCEJXT49BSRBoNLXBkN4jxCZnAu0ESMvFVSCVLoxFboe0i7YsjatG/n9AM3p1skvR45pzHLHtkte2EP7I49sfc/czWCHO1a6rQaHa9wd+Mnk7m3ri6LVoWjL9c/NX9qfWK9oGJBSk6s7NKrwgEygcOknt2AaXfPO/fWjs9ecsubs405ds2eqe8r1mL31Llde+U3G2LzHDEaXPrnmH6D7YVUmvDGYjKbCUcYxRRmME9zWkIWq1hHPvjTp7jApTavrWl5rdCRapHQM4Fvoe19AG+Dmbs=</latexit>

T = np.arange(0, 10, 0.01)
X0 = [0, -1]
y, t = initial(P, T, X0)<latexit sha1_base64="042ZTr/rlQtMnljtQxVxXlQAUpU=">AAACqHichVG7SgNBFD2urxhfURvBRgyKWMisCIpVwMYyD2MiMYTdcdTF2Ye7k4CG/IA/kMLGCBbiZ9j4AxZ+glgq2Fh4s1kRDeodZubMmXvug2t60goUY489Wm9f/8BgbCg+PDI6Np6YmNwJ3KrPRZ670vWLphEIaTkirywlRdHzhWGbUhTM4832f6Em/MBynW116omybRw61oHFDUVUec821BE3ZD3XqOiVRJIts9Bmu4EegSQiS7uJO+xhHy44qrAh4EARljAQ0CpBB4NHXBl14nxCVvgv0ECctFXyEuRhEHtM5yG9ShHr0LsdMwjVnLJI2j4pZzHPHtgNe2H37JY9sfdfY9XDGO1aTuk2O1rhVcbPp3Nv/6psuhWOvlR/1PzpGxDrhxUL8uTEyn96VTjAeqiwqGcvZNrd807e2lnzJbeRna8vsCv2TH232CO7o86d2iu/zojsBeI0OP3nmLrBzsqyTjizmkytRyOMYQZzWKQ5rSGFLaSRp7wnaOISLW1JS2sFbbfjqvVEmil8M838AAPcml8=</latexit><latexit sha1_base64="fQe4ILF5o8te2XhAEjzAbdXu9ds=">AAACqHichVG7SgNBFD1Z3/EVtRFsxBARC5kEQbESbCxjYh6ShLA7jrpk9uHuJKDBH/AHLGyMYCF+ho0/YOEniKWCjYU3mxXRoLnDzJw5c899cA1Xmr5i7Cmi9fUPDA4Nj0RHx8YnJmNT03nfqXtc5LgjHa9o6L6Qpi1yylRSFF1P6JYhRcGobbX/Cw3h+aZj76oTV1Qs/dA2D0yuK6IqZUtXR1yXzexZNVWNxdkKC2y+GyRDEEdoaSd2jzL24YCjDgsCNhRhCR0+rRKSYHCJq6BJnEfIDP4FzhAlbZ28BHnoxNboPKRXKWRterdj+oGaUxZJ2yPlPBLskd2yV/bA7tgz+/gzVjOI0a7lhG6joxVudfJ8NvveU2XRrXD0rfqn5i9fn1gvqFiQJydW9uhV4QDrgcKknt2AaXfPO3kbpxev2Y1MornIrtkL9d1iT+yeOrcbb/xmR2QuEaXBJX+PqRvkUytJwjur8c31cITDmMMClmhOa9jENtLIUd5jXOAKLW1ZS2sFba/jqkVCzQx+mGZ8AgYUmmA=</latexit><latexit sha1_base64="042ZTr/rlQtMnljtQxVxXlQAUpU=">AAACqHichVG7SgNBFD2urxhfURvBRgyKWMisCIpVwMYyD2MiMYTdcdTF2Ye7k4CG/IA/kMLGCBbiZ9j4AxZ+glgq2Fh4s1kRDeodZubMmXvug2t60goUY489Wm9f/8BgbCg+PDI6Np6YmNwJ3KrPRZ670vWLphEIaTkirywlRdHzhWGbUhTM4832f6Em/MBynW116omybRw61oHFDUVUec821BE3ZD3XqOiVRJIts9Bmu4EegSQiS7uJO+xhHy44qrAh4EARljAQ0CpBB4NHXBl14nxCVvgv0ECctFXyEuRhEHtM5yG9ShHr0LsdMwjVnLJI2j4pZzHPHtgNe2H37JY9sfdfY9XDGO1aTuk2O1rhVcbPp3Nv/6psuhWOvlR/1PzpGxDrhxUL8uTEyn96VTjAeqiwqGcvZNrd807e2lnzJbeRna8vsCv2TH232CO7o86d2iu/zojsBeI0OP3nmLrBzsqyTjizmkytRyOMYQZzWKQ5rSGFLaSRp7wnaOISLW1JS2sFbbfjqvVEmil8M838AAPcml8=</latexit><latexit sha1_base64="8feZEoK9b9JChDfQwKyqBk5rKeM=">AAAConichVG7SgNRED2urxhfURvBJhgVQQizIihWARuxSowxQhJkd72JS/bF7iYQQ37AzkowlYKF+Bk2/oBFPkEsFWwsnGxWREWdZe8999xz5s4wqmPonk/U6ZP6BwaHhiMj0dGx8YnJ2NT0vmfXXE3kNNuw3QNV8YShWyLn674hDhxXKKZqiLxa3ere5+vC9XTb2vMbjiiZSsXSy7qm+Ezli46pNldah7EEJSmI+E8ghyCBMNJ27A5FHMGGhhpMCFjwGRtQ4PFXgAyCw1wJTeZcRnpwL9BClL01VglWKMxWea3wqRCyFp+7Ob3ArfErBv8uO+NYpAe6oWe6p1t6pLdfczWDHN1aGryrPa9wDidPZ7Ov/7pM3n0cf7r+qPlD6zHrBhULVmrMGv/06qOMjcChc89OwHS713rv1k/On7Obu4vNJbqiJ+77kjp0x51b9RftOiN224jy4OTvY/oJ9leTMiXlzFoitRaOMII5zGOZ57SOFLaRRi6o7gwXaEsL0o6UkbI9qdQXembwJaTiO+EAl8w=</latexit>

7Digitalization<latexit sha1_base64="q9jQeFqFfWF+DcoZdS2ETssh+Rw=">AAACpnichVG7SgNBFD1ZXzE+ErURbMSgWIWJCAargI2VqDFGSILujqMumX2wOwnEkB+wFwtBUbAQP8PGH7DIJ4ilgo2FN5sVUdHcZXfOnDnnzr17DVeavmKsFdF6evv6B6KDsaHhkdF4Ymx823eqHhd57kjH2zF0X0jTFnllKil2XE/oliFFwaistM8LNeH5pmNvqborypZ+aJsHJtcVUcWSpasjrstGrrmbSLIUC2L6N0iHIIkw1p3EPUrYhwOOKiwI2FCEJXT49BSRBoNLXBkN4jxCZnAu0ESMvFVSCVLoxFboe0i7YsjatG/n9AM3p1skvR45pzHLHtkte2EP7I49sfc/czWCHO1a6rQaHa9wd+Mnk7m3ri6LVoWjL9c/NX9qfWK9oGJBSk6s7NKrwgEygcOknt2AaXfPO/fWjs9ecsubs405ds2eqe8r1mL31Llde+U3G2LzHDEaXPrnmH6D7YVUmvDGYjKbCUcYxRRmME9zWkIWq1hHPvjTp7jApTavrWl5rdCRapHQM4Fvoe19AG+Dmbs=</latexit><latexit sha1_base64="8feZEoK9b9JChDfQwKyqBk5rKeM=">AAAConichVG7SgNRED2urxhfURvBJhgVQQizIihWARuxSowxQhJkd72JS/bF7iYQQ37AzkowlYKF+Bk2/oBFPkEsFWwsnGxWREWdZe8999xz5s4wqmPonk/U6ZP6BwaHhiMj0dGx8YnJ2NT0vmfXXE3kNNuw3QNV8YShWyLn674hDhxXKKZqiLxa3ere5+vC9XTb2vMbjiiZSsXSy7qm+Ezli46pNldah7EEJSmI+E8ghyCBMNJ27A5FHMGGhhpMCFjwGRtQ4PFXgAyCw1wJTeZcRnpwL9BClL01VglWKMxWea3wqRCyFp+7Ob3ArfErBv8uO+NYpAe6oWe6p1t6pLdfczWDHN1aGryrPa9wDidPZ7Ov/7pM3n0cf7r+qPlD6zHrBhULVmrMGv/06qOMjcChc89OwHS713rv1k/On7Obu4vNJbqiJ+77kjp0x51b9RftOiN224jy4OTvY/oJ9leTMiXlzFoitRaOMII5zGOZ57SOFLaRRi6o7gwXaEsL0o6UkbI9qdQXembwJaTiO+EAl8w=</latexit>

Forced response
T = np.arange(0, 10, 0.01)
U = np.sin(5*T)
y, t, x0 = lsim(P, U, T)<latexit sha1_base64="fQe4ILF5o8te2XhAEjzAbdXu9ds=">AAACqHichVG7SgNBFD1Z3/EVtRFsxBARC5kEQbESbCxjYh6ShLA7jrpk9uHuJKDBH/AHLGyMYCF+ho0/YOEniKWCjYU3mxXRoLnDzJw5c899cA1Xmr5i7Cmi9fUPDA4Nj0RHx8YnJmNT03nfqXtc5LgjHa9o6L6Qpi1yylRSFF1P6JYhRcGobbX/Cw3h+aZj76oTV1Qs/dA2D0yuK6IqZUtXR1yXzexZNVWNxdkKC2y+GyRDEEdoaSd2jzL24YCjDgsCNhRhCR0+rRKSYHCJq6BJnEfIDP4FzhAlbZ28BHnoxNboPKRXKWRterdj+oGaUxZJ2yPlPBLskd2yV/bA7tgz+/gzVjOI0a7lhG6joxVudfJ8NvveU2XRrXD0rfqn5i9fn1gvqFiQJydW9uhV4QDrgcKknt2AaXfPO3kbpxev2Y1MornIrtkL9d1iT+yeOrcbb/xmR2QuEaXBJX+PqRvkUytJwjur8c31cITDmMMClmhOa9jENtLIUd5jXOAKLW1ZS2sFba/jqkVCzQx+mGZ8AgYUmmA=</latexit>

Zero Order Hold<latexit sha1_base64="042ZTr/rlQtMnljtQxVxXlQAUpU=">AAACqHichVG7SgNBFD2urxhfURvBRgyKWMisCIpVwMYyD2MiMYTdcdTF2Ye7k4CG/IA/kMLGCBbiZ9j4AxZ+glgq2Fh4s1kRDeodZubMmXvug2t60goUY489Wm9f/8BgbCg+PDI6Np6YmNwJ3KrPRZ670vWLphEIaTkirywlRdHzhWGbUhTM4832f6Em/MBynW116omybRw61oHFDUVUec821BE3ZD3XqOiVRJIts9Bmu4EegSQiS7uJO+xhHy44qrAh4EARljAQ0CpBB4NHXBl14nxCVvgv0ECctFXyEuRhEHtM5yG9ShHr0LsdMwjVnLJI2j4pZzHPHtgNe2H37JY9sfdfY9XDGO1aTuk2O1rhVcbPp3Nv/6psuhWOvlR/1PzpGxDrhxUL8uTEyn96VTjAeqiwqGcvZNrd807e2lnzJbeRna8vsCv2TH232CO7o86d2iu/zojsBeI0OP3nmLrBzsqyTjizmkytRyOMYQZzWKQ5rSGFLaSRp7wnaOISLW1JS2sFbbfjqvVEmil8M838AAPcml8=</latexit><latexit sha1_base64="8feZEoK9b9JChDfQwKyqBk5rKeM=">AAAConichVG7SgNRED2urxhfURvBJhgVQQizIihWARuxSowxQhJkd72JS/bF7iYQQ37AzkowlYKF+Bk2/oBFPkEsFWwsnGxWREWdZe8999xz5s4wqmPonk/U6ZP6BwaHhiMj0dGx8YnJ2NT0vmfXXE3kNNuw3QNV8YShWyLn674hDhxXKKZqiLxa3ere5+vC9XTb2vMbjiiZSsXSy7qm+Ezli46pNldah7EEJSmI+E8ghyCBMNJ27A5FHMGGhhpMCFjwGRtQ4PFXgAyCw1wJTeZcRnpwL9BClL01VglWKMxWea3wqRCyFp+7Ob3ArfErBv8uO+NYpAe6oWe6p1t6pLdfczWDHN1aGryrPa9wDidPZ7Ov/7pM3n0cf7r+qPlD6zHrBhULVmrMGv/06qOMjcChc89OwHS713rv1k/On7Obu4vNJbqiJ+77kjp0x51b9RftOiN224jy4OTvY/oJ9leTMiXlzFoitRaOMII5zGOZ57SOFLaRRi6o7gwXaEsL0o6UkbI9qdQXembwJaTiO+EAl8w=</latexit>

Negative FB<latexit sha1_base64="fQe4ILF5o8te2XhAEjzAbdXu9ds=">AAACqHichVG7SgNBFD1Z3/EVtRFsxBARC5kEQbESbCxjYh6ShLA7jrpk9uHuJKDBH/AHLGyMYCF+ho0/YOEniKWCjYU3mxXRoLnDzJw5c899cA1Xmr5i7Cmi9fUPDA4Nj0RHx8YnJmNT03nfqXtc5LgjHa9o6L6Qpi1yylRSFF1P6JYhRcGobbX/Cw3h+aZj76oTV1Qs/dA2D0yuK6IqZUtXR1yXzexZNVWNxdkKC2y+GyRDEEdoaSd2jzL24YCjDgsCNhRhCR0+rRKSYHCJq6BJnEfIDP4FzhAlbZ28BHnoxNboPKRXKWRterdj+oGaUxZJ2yPlPBLskd2yV/bA7tgz+/gzVjOI0a7lhG6joxVudfJ8NvveU2XRrXD0rfqn5i9fn1gvqFiQJydW9uhV4QDrgcKknt2AaXfPO3kbpxev2Y1MornIrtkL9d1iT+yeOrcbb/xmR2QuEaXBJX+PqRvkUytJwjur8c31cITDmMMClmhOa9jENtLIUd5jXOAKLW1ZS2sFba/jqkVCzQx+mGZ8AgYUmmA=</latexit>

feedback(S1，S2, sign=-1)
minreal(sys)TustinTransformation

ts = 0.2
Pd = c2d(P, ts, method='zoh')ts = 0.2
Pd = c2d(P, ts, method='tustin')