Function manual of ctrl
pylib_sakata.ctrl
ZpkModel
class pylib_sakata.ctrl.ZpkModel(z, p, k, dt=0)
- Parameters:
- z: zeros array of the LTI model
- p: poles array of the LTI model
- k: gain of the LTI model. Note: the gain is not system dc gain but coefficient of monic polynomials. This is different from the definition of dc gain in TransferFunction class.
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
Examples
>>> ctrl.ZpkModel([-1., -2.], [-3., -4., -5.], 2.)
(s+1)(s+2)
2 * ---------------
(s+3)(s+4)(s+5)If you set same zeros and poles, the pole-zero cancellation is automatically done as following. Unnecessary increase of the system order can be avoided.
>>> ctrl.ZpkModel([0.1, 0.3, 0.4], [0.3, 0.4, 0.5], 2., 0.001)
The common pole-zeros of the zpk model have been deleted.
(z-0.1)
2 * -------
(z-0.5)
dt = 0.001Methods - __neg__() Negate a zpk model.
__add__(other) Add two zpk models (parallel connection).
__radd__(other) Right add two zpk models (parallel connection).
__sub__(other) Subtract two zpk models.
__rsub__(other) Right subtract two zpk models.
__mul__(other) Multiply two zpk models (serial connection).
__rmul__(other) Right multiply two zpk models (serial connection).
__truediv__(other) Divide two zpk models.
__rtruediv__(other) Right divide two zpk models.
__pow__(other) A zpk model to the power of x.
feedback(other=1, sys=‘S’) Calculate the feedback system that consist of two zpk model (P: self and C: other). sys: FB type (Optional), Default: ‘S’, Set in ‘S’: sensitivity function, ‘T’: complementary sensitivity function, ‘SP’: response from input disturbance to output
tf
pylib_sakata.ctrl.tf(num, den, dt=0)
This function calls tf function in control library.
- Parameters:
- num: polynomial coefficients of the numerator of the LTI model
- den: polynomial coefficients of the denominator of the LTI model
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- Returns:
- out: instance of TransferFuntion class
Examples
>>> print(ctrl.tf([1., 2.], [3., 4., 5.]))
s + 2
---------------
3 s^2 + 4 s + 5ss
pylib_sakata.ctrl.ss(A, B, C, D, dt=0)
This function calls ss function in control library.
- Parameters:
- A, B, C, D: state space matrices
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- Returns:
- out: instance of StateSpace class
Examples
>>> print(ctrl.ss("1. -2.; 3. -4.", "5.; 7.", "6. 8.", "9."))
A = [[ 1. -2.]
[ 3. -4.]]
B = [[5.]
[7.]]
C = [[6. 8.]]
D = [[9.]]zpk
pylib_sakata.ctrl.zpk(z, p, k, dt=0)
- Parameters:
- A, B, C, D: state space matrices
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- Returns:
- out: instance of ZpkModel class
Examples
>>> ctrl.zpk([-1., -2.], [-3., -4., -5.], 2.)
(s+1)(s+2)
2 * ---------------
(s+3)(s+4)(s+5)tf2ss
pylib_sakata.ctrl.tf2ss(tf, form=None)
- Parameters:
- tf: instance of TransferFunction class
- form: canonical form (Optional), you can select the canonical form in ‘reachable’, ‘observable’, and ‘modal’.
- Returns:
- out: instance of StateSpace class
Examples
>>> Sys_tf = ctrl.tf([1., 2.], [3., 4., 5.])
>>> print(ctrl.tf2ss(Sys_tf))
A = [[-1.33333333 -1.66666667]
[ 1. 0. ]]
B = [[1.]
[0.]]
C = [[0.33333333 0.66666667]]
D = [[0.]]tf2zpk
pylib_sakata.ctrl.tf2zpk(tf)
- Parameters:
- tf: instance of TransferFunction class
- Returns:
- out: instance of ZpkModel class
Examples
>>> Sys_tf = ctrl.tf([1., 2.], [3., 4., 5.])
>>> ctrl.tf2zpk(Sys_tf)
(s+2)
0.3333 * ----------------------------------
(s+0.6667+1.106j)(s+0.6667-1.106j)ss2tf
pylib_sakata.ctrl.ss2tf(ss)
- Parameters:
- ss: instance of StateSpace class
- Returns:
- out: instance of TransferFunction class
Examples
>>> Sys_ss = ctrl.ss("1. -2.; 3. -4.", "5.; 7.", "6. 8.", "9.")
>>> print(ctrl.ss2tf(Sys_ss))
9 s^2 + 113 s + 118
-------------------
s^2 + 3 s + 2ss2zpk
pylib_sakata.ctrl.ss2zpk(ss)
- Parameters:
- ss: instance of StateSpace class
- Returns:
- out: instance of ZpkModel class
Examples
>>> Sys_ss = ctrl.ss("1. -2.; 3. -4.", "5.; 7.", "6. 8.", "9.")
>>> ctrl.ss2zpk(Sys_ss)
(s+11.41)(s+1.149)
9 * ------------------
(s+2)(s+1)zpk2tf
pylib_sakata.ctrl.zpk2tf(zpk)
- Parameters:
- zpk: instance of ZpkModel class
- Returns:
- out: instance of TransferFunction class
Examples
>>> Sys_zpk = ctrl.zpk([-1., -2.], [-3., -4., -5.], 2.)
>>> print(ctrl.zpk2tf(Sys_zpk))
2 s^2 + 6 s + 4
------------------------
s^3 + 12 s^2 + 47 s + 60zpk2ss
pylib_sakata.ctrl.zpk2ss(zpk, form=‘reachable’)
- Parameters:
- zpk: instance of ZpkModel class
- form: canonical form (Optional), Default: reachable. You can select the canonical form in reachable, observable, and modal.
- Returns:
- out: instance of StateSpace class
Examples
>>> Sys_zpk = ctrl.zpk([-1., -2.], [-3., -4., -5.], 2.)
>>> print(ctrl.zpk2ss(Sys_zpk))
A = [[-12. -47. -60.]
[ 1. 0. 0.]
[ 0. 1. 0.]]
B = [[1.]
[0.]
[0.]]
C = [[2. 6. 4.]]
D = [[0.]]sys2frd
pylib_sakata.ctrl.sys2frd(sys, freq)
- Parameters:
- sys: LTI model (StateSpace or TransferFunction or ZpkModel)
- freq: 1-D array frequency data [Hz]
- Returns:
- freqresp: instance of FreqResp class (Refer FreqResp.)
Examples
>>> import numpy as np
>>> freq = np.logspace(np.log10(1.), np.log10(1000.), 10000, base=10)
>>> Sys_tf = ctrl.tf([1., 2.], [3., 4., 5.])
>>> ctrl.sys2frd(Sys_tf, freq)
freq = array([ 1. 1.00069108 1.00138264 ... 998.61926487 999.30939397
1. ])
resp = array([-5.10821217e-03-5.65218353e-02j -5.10191815e-03-5.64779702e-02j
-5.09563061e-03-5.64341455e-02j ... -5.64453060e-09-5.31250027e-05j
-5.63673700e-09-5.30883142e-05j -5.62895416e-09-5.30516511e-05j])>>> Sys_zpk = ctrl.zpk([-1., -2.], [-3., -4., -5.], 2.)
>>> ctrl.sys2frd(Sys_zpk, freq)
freq = array([ 1. 1.00069108 1.00138264 ... 998.61926487 999.30939397
1000. ])
resp = array([1.89109027e-01-0.06951671j 1.89033162e-01-0.06962001j
1.88957165e-01-0.0697232j ... 4.57206511e-07-0.00031875j
4.56575231e-07-0.00031853j 4.55944822e-07-0.00031831j])feedback
pylib_sakata.ctrl.feedback(sysP, sysC, sys=‘S’)
This function is for calculating the feedback system that consist of two LTI model (P: plant and C: controller).
- Parameters:
- sysP: LTI model (StateSpace or TransferFunction or ZpkModel) of the plant
- sysC: LTI model (StateSpace or TransferFunction or ZpkModel) of the controller
- sys: FB type (Optional), Default: ‘S’, Set in ‘S’: sensitivity function, ‘T’: complementary sensitivity function, ‘SP’: response from input
- Returns:
- out: LTI model (StateSpace or TransferFunction or ZpkModel) of the feedback system
Examples
>>> P_tf = ctrl.tf([1.], [1., 2., 0.])
>>> C_tf = ctrl.tf([2., 4., 1.], [1., 2., 0.])
>>> print(ctrl.feedback(P_tf, C_tf))
s^4 + 4 s^3 + 4 s^2
-----------------------------
s^4 + 4 s^3 + 6 s^2 + 4 s + 1>>> P_zpk = ctrl.zpk([], [0., -2.])
>>> C_zpk = ctrl.zpk([-1.7071067811865475, -0.29289321881345254], [0., -2.], 2.)
>>> ctrl.feedback(P_zpk, C_zpk)
s(s+2)(s+2)s
1 * -----------------------------------------------
(s+1)(s+1-0.0001508j)(s+1+0.0001508j)(s+0.9998)frdfeedback
pylib_sakata.ctrl.frdfeedback(frdP, frdC, sys=‘S’)
This function is for calculating the feedback system that consist of two freqresp (P: plant and C: controller).
- Parameters:
- frdP: 1-D array complex data of the frequency response of the plant
- frdC: 1-D array complex data of the frequency response of the controller
- sys: FB type (Optional), Default: ‘S’, Set in ‘S’: sensitivity function, ‘T’: complementary sensitivity function, ‘SP’: response from input
- Returns:
- out: 1-D array complex data of the frequency response of the feedback system
Examples
>>> import numpy as np
>>> freq = np.logspace(np.log10(1.), np.log10(1000.), 10000, base=10)
>>> P_tf = ctrl.tf([1.], [1., 2., 0.])
>>> C_tf = ctrl.tf([2., 4., 1.], [1., 2., 0.])
>>> P_frd = ctrl.tf2frd(P_tf, freq)
>>> C_frd = ctrl.tf2frd(C_tf, freq)
>>> ctrl.frdfeedback(P_frd, C_frd)
array([1.04746047+1.56990662e-02j, 1.04739933+1.56671729e-02j,
1.04733826+1.56353434e-02j, ..., 1.00000005+1.61927479e-11j,
1.00000005+1.61592227e-11j, 1.00000005+1.61257668e-11j])c2d
pylib_sakata.ctrl.c2d(sysC, dt, method=‘tustin’)
The matched method of c2d in control library does not supported for pure integrals and pure derivatives because of dc gain inf error. This function solved this problem.
- Parameters:
- sysC: continuous time LTI model (StateSpace or TransferFunction or ZpkModel) of the plant
- dt: sampling time of the LTI model (Optional), Default: 0, set the value > 0.
- method: discretized method (Optional), Default: ‘tustin’, set a method in ‘tustin’, ‘matched’, ‘zoh’, and etc.
- Returns:
- out: discrete time LTI model (StateSpace or TransferFunction or ZpkModel) of the feedback system
Examples
>>> C_tf = ctrl.tf([1., 3., 2.], [1., 3., 0.])
>>> print(ctrl.c2d(C_tf, 0.001, 'matched'))
z^2 - 1.997 z + 0.997
---------------------
z^2 - 1.997 z + 0.997
dt = 0.001>>> C_zpk = ctrl.zpk([-1., -2.,], [0., -3.,], 1.)
>>> ctrl.c2d(C_zpk, 0.001, 'matched')
(z-0.999)(z-0.998)
1 * ------------------
(z-1)(z-0.997)
dt = 0.001pi
pylib_sakata.ctrl.pi(freq, zeta, L, R, dt=None, method=‘tustin’)
This function is for design of a PI controller. \[C_{\mathbf{PI}}(s) = K_P + \frac{K_I}{s} = \frac{b_1s+b_0}{s}\] \[P(s) = \frac{1}{Ls+R}\]
- Parameters:
- freq: frequency[Hz] of the pole pair of the feedback system with the PI controller
- zeta: damping of the pole pair of the feedback system with the PI controller
- L: inductance[H] of the plant
- R: resistance[\(\Omega\)] of the plant
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- method: discretized method (Optional), Default: ‘tustin’, set a method if dt > 0
- Returns:
- out: instance of TransferFunction class of the PI controller
Examples
>>> print(ctrl.pi(1000., 0.7, 0.1, 10.))
869.6 s + 3.948e+06
-------------------
s>>> print(ctrl.pi(1000., 0.7, 0.1, 10., 0.001))
2844 z + 1104
-------------
z - 1
dt = 0.001pd
pylib_sakata.ctrl.pd(freq1, freq2, zeta2, M, C, K, dt=None, method=‘tustin’)
This function is for design of a PD controller. \[C_{\mathbf{PD}}(s) = K_P + \frac{K_D s}{\tau_D s+1} = \frac{b_1s+b_0}{s+a_0}\] \[P(s) = \frac{1}{Ms^2+Cs+K}\]
- Parameters:
- freq1: frequency[Hz] of the first pole of the feedback system with the PD controller
- freq2: frequency[Hz] of the second pole pair of the feedback system with the PD controller
- zeta2: damping of the second pole pair of the feedback system with the PD controller
- M: mass[kg] of the plant
- C: viscosity[N/(m/s)] of the plant
- K: stiffness[N/m] of the plant
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- method: discretized method (Optional), Default: ‘tustin’, set a method if dt > 0
- Returns:
- out: instance of TransferFunction class of the PD controller
Examples
>>> print(ctrl.pd(10., 10., 0.7, 2., 10., 0.))
1.749e+04 s + 4.961e+05
-----------------------
s + 145.8>>> print(ctrl.pd(10., 10., 0.7, 2., 10., 0., 0.001))
1.653e+04 z - 1.607e+04
-----------------------
z - 0.8641
dt = 0.001pid
pylib_sakata.ctrl.pid(freq1, zeta1, freq2, zeta2, M, C, K, dt=None, method=‘tustin’)
This function is for design of a PID controller. \[C_{\mathbf{PID}}(s) = K_P + \frac{K_I}{s} + \frac{K_D s}{\tau_D s+1} = \frac{b_2s^2+b_1s+b_0}{s^2+a_1s}\] \[P(s) = \frac{1}{Ms^2+Cs+K}\]
- Parameters:
- freq1: frequency[Hz] of the first pole pair of the feedback system with the PID controller
- zeta1: damping of the first pole pair of the feedback system with the PID controller
- freq2: frequency[Hz] of the second pole pair of the feedback system with the PID controller
- zeta2: damping of the second pole pair of the feedback system with the PID controller
- M: mass[kg] of the plant
- C: viscosity[N/(m/s)] of the plant
- K: stiffness[N/m] of the plant
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- method: discretized method (Optional), Default: ‘tustin’, set a method if dt > 0
- Returns:
- out: instance of TransferFunction class of the PID controller
Examples
>>> print(ctrl.pid(10., 1., 10., 0.7, 2., 10., 0.))
3.581e+04 s^2 + 1.687e+06 s + 3.117e+07
---------------------------------------
s^2 + 208.6 s>>> print(ctrl.pid(10., 1., 10., 0.7, 2., 10., 0., 0.001))
3.32e+04 z^2 - 6.485e+04 z + 3.167e+04
--------------------------------------
z^2 - 1.811 z + 0.8111
dt = 0.001pl1st
pylib_sakata.ctrl.pl1st(freq1, freq2, dt=None, method=‘tustin’)
This function is for design of a first order phase lead filter. \[F_{\mathbf{PL}}(s) = \frac{f_2}{f_1} * \frac{s+2\pi f_1}{s+2\pi f_2}\]
- Parameters:
- freq1: frequency[Hz] of numerator of the phase lead filter
- freq2: frequency[Hz] of denominator of the phase lead filter
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- method: discretized method (Optional), Default: ‘tustin’, set a method if dt > 0
- Returns:
- out: instance of TransferFunction class of the phase lead filter
Examples
>>> ctrl.tf2zpk(ctrl.pl1st(50., 100.))
(s+314.2)
2 * ---------
(s+628.3)>>> ctrl.tf2zpk(ctrl.pl1st(50., 100., 0.001))
(z-0.7285)
1.761 * ----------
(z-0.5219)
dt = 0.001pl2nd
pylib_sakata.ctrl.pl2nd(freq1, zeta1, freq2, zeta2, dt=None, method=‘tustin’)
This function is for design of a second order phase lead filter. \[F_{\mathbf{PL}^2}(s) = \left( \frac{f_2}{f_1} \right)^2 * \frac{s^2+2\zeta_1 (2\pi f_1)s+(2\pi f_1)^2}{s^2+2\zeta_2 (2\pi f_2)s+(2\pi f_2)^2}\]
- Parameters:
- freq1: frequency[Hz] of numerator of the phase lead filter
- zeta1: damping of numerator of the phase lead filter
- freq2: frequency[Hz] of denominator of the phase lead filter
- zeta2: damping of denominator of the phase lead filter
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- method: discretized method (Optional), Default: ‘tustin’, set a method if dt > 0
- Returns:
- out: instance of TransferFunction class of the phase lead filter
Examples
>>> print(ctrl.pl2nd(50., 0.7, 100., 0.7))
2 s^2 + 879.6 s + 1.974e+05
---------------------------
s^2 + 879.6 s + 3.948e+05>>> print(ctrl.pl2nd(50., 0.7, 100., 0.7, 0.001))
1.618 z^2 - 2.536 z + 1.046
---------------------------
z^2 - 1.172 z + 0.4283
dt = 0.001lpf1st
pylib_sakata.ctrl.lpf1st(freq, dt=None, method=‘tustin’)
This function is for design of a first order low pass filter. \[F_{\mathbf{LP}}(s) = \frac{2\pi f}{s+2\pi f}\]
- Parameters:
- freq: frequency[Hz] of the low pass filter
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- method: discretized method (Optional), Default: ‘tustin’, set a method if dt > 0
- Returns:
- out: instance of TransferFunction class of the low pass filter
Examples
>>> print(ctrl.lpf1st(100.))
628.3
---------
s + 628.3>>> print(ctrl.lpf1st(100., 0.001))
0.2391 z + 0.2391
-----------------
z - 0.5219
dt = 0.001lpf2nd
pylib_sakata.ctrl.lpf2nd(freq, zeta, dt=None, method=‘tustin’)
This function is for design of a second order low pass filter. \[F_{\mathbf{LP}^2}(s) = \frac{(2\pi f)^2}{s^2+2\zeta (2\pi f)s+(2\pi f)^2}\]
- Parameters:
- freq: frequency[Hz] of the low pass filter
- zeta1: damping of the low pass filter
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- method: discretized method (Optional), Default: ‘tustin’, set a method if dt > 0
- Returns:
- out: instance of TransferFunction class of the low pass filter
Examples
>>> print(ctrl.lpf2nd(100., 0.7))
3.948e+05
-------------------------
s^2 + 879.6 s + 3.948e+05>>> print(ctrl.lpf2nd(100., 0.7, 0.001))
0.06415 z^2 + 0.1283 z + 0.06415
--------------------------------
z^2 - 1.172 z + 0.4283
dt = 0.001hpf1st
pylib_sakata.ctrl.hpf1st(freq, dt=None, method=‘tustin’)
This function is for design of a first order high pass filter. \[F_{\mathbf{HP}}(s) = 1 - F_{LP}(s) = \frac{s}{s+2\pi f}\]
- Parameters:
- freq: frequency[Hz] of the high pass filter
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- method: discretized method (Optional), Default: ‘tustin’, set a method if dt > 0
- Returns:
- out: instance of TransferFunction class of the high pass filter
Examples
>>> print(ctrl.hpf1st(100.))
s
---------
s + 628.3>>> print(ctrl.hpf1st(100., 0.001))
0.7609 z - 0.7609
-----------------
z - 0.5219
dt = 0.001hpf2nd
pylib_sakata.ctrl.hpf2nd(freq, zeta, dt=None, method=‘tustin’)
This function is for design of a second order high pass filter. \[F_{\mathbf{HP}^2}(s) = 1 - F_{LP^2}(s) = \frac{s^2+2\zeta (2\pi f)s}{s^2+2\zeta (2\pi f)s+(2\pi f)^2}\]
- Parameters:
- freq: frequency[Hz] of the high pass filter
- zeta1: damping of the high pass filter
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- method: discretized method (Optional), Default: ‘tustin’, set a method if dt > 0
- Returns:
- out: instance of TransferFunction class of the high pass filter
Examples
>>> print(ctrl.hpf2nd(100., 0.7))
s^2 + 879.6 s
-------------------------
s^2 + 879.6 s + 3.948e+05>>> print(ctrl.hpf2nd(100., 0.7, 0.001))
0.9358 z^2 - 1.3 z + 0.3641
---------------------------
z^2 - 1.172 z + 0.4283
dt = 0.001nf
pylib_sakata.ctrl.nf(freq, zeta, depth, dt=None, method=‘matched’)
This function is for design of notch filters. \[F_{\mathbf{notch}}(s) = \frac{s^2+2d\zeta (2\pi f)s+(2\pi f)^2}{s^2+2\zeta (2\pi f)s+(2\pi f)^2}\]
- Parameters:
- freq: array of frequency[Hz] of the notch filters
- zeta: array of damping of the notch filters
- depth: array of depth of the notch filters (0 < depth < 1)
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- method: discretized method (Optional), Default: ‘matched’, set a method if dt > 0
- Returns:
- out: array of instance of TransferFunction class of the notch filters
Examples
>>> ctrl.nf([100., 200., 300.], [0.02, 0.02, 0.02], [0.01, 0.01, 0.01])
array([TransferFunction(array([1.00000000e+00, 2.51327412e-01, 3.94784176e+05]), array([1.00000000e+00, 2.51327412e+01, 3.94784176e+05])),
TransferFunction(array([1.00000000e+00, 5.02654825e-01, 1.57913670e+06]), array([1.00000000e+00, 5.02654825e+01, 1.57913670e+06])),
TransferFunction(array([1.00000000e+00, 7.53982237e-01, 3.55305758e+06]), array([1.00000000e+00, 7.53982237e+01, 3.55305758e+06]))],
dtype=object)>>> ctrl.nf([100., 200., 300.], [0.02, 0.02, 0.02], [0.01, 0.01, 0.01], 0.001)
array([TransferFunction(array([ 0.9876627 , -1.59787102, 0.9874145 ]), array([ 1. , -1.59797428, 0.97518046]), 0.001),
TransferFunction(array([ 0.97553399, -0.6027617 , 0.97504375]), array([ 1. , -0.60316088, 0.95097692]), 0.001),
TransferFunction(array([0.96362486, 0.59532837, 0.96289858]), array([1. , 0.59447771, 0.92737411]), 0.001)],
dtype=object)rf
pylib_sakata.ctrl.rf(freq, zeta, k, phi, dt=None, method=‘tustin’)
This function is for design of resonant filters (resonant filters). \[F_{\mathbf{reso}}(s) = \frac{k(s^2-\phi s)}{s^2+2\zeta (2\pi f)s+(2\pi f)^2}\]
- Parameters:
- freq: array of frequency[Hz] of the resonant filters
- zeta: array of damping of the resonant filters
- k: array of peak width of the resonant filters
- phi: array of phase lead of the resonant filter
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- method: discretized method (Optional), Default: ‘tustin’, set a method if dt > 0
- Returns:
- out: array of instance of TransferFunction class of the resonant filters
Examples
>>> ctrl.rf([2., 3., 5.], [0.001, 0.001, 0.001], [-0.00025695, -0.00049616, 0.0003898], [860.21053991, 633.22924516, -1090.49879949])
>>> ctrl.rf([2., 3., 5.], [0.001, 0.001, 0.001], [-0.00025695, -0.00049616, 0.0003898], [860.21053991, 633.22924516, -1090.49879949])
array([TransferFunction(array([-0.00025695, 0.2210311 , 0. ]), array([1.00000000e+00, 2.51327412e-02, 1.57913670e+02])),
TransferFunction(array([-0.00049616, 0.31418302, 0. ]), array([1.00000000e+00, 3.76991118e-02, 3.55305758e+02])),
TransferFunction(array([3.89800000e-04, 4.25076432e-01, 0.00000000e+00]), array([1.00000000e+00, 6.28318531e-02, 9.86960440e+02]))],
dtype=object)>>> ctrl.rf([2., 3., 5.], [0.001, 0.001, 0.001], [-0.00025695, -0.00049616, 0.0003898], [860.21053991, 633.22924516, -1090.49879949], 0.001)
array([TransferFunction(array([-0.00014643, 0.00051387, -0.00036745]), array([ 1. , -1.99981696, 0.99997487]), 0.001),
TransferFunction(array([-0.00033903, 0.00099221, -0.00065318]), array([ 1. , -1.99960704, 0.9999623 ]), 0.001),
TransferFunction(array([ 0.00060217, -0.00077938, 0.00017721]), array([ 1. , -1.9989505 , 0.99993719]), 0.001)],
dtype=object)rfoptparam
pylib_sakata.ctrl.rfoptparam(freq, zeta, depth, sysT)
This function is for getting parameters of optimized resonant filters (resonant filters).
- Parameters:
- freq: array of frequency[Hz] of the resonant filters
- zeta: array of damping of the resonant filters
- depth: array of depth of the resonant filters (0 < depth < 1)
- sysT: LTI model (StateSpace or TransferFunction or ZpkModel or FreqResp) of complementary sensitivity function of the previous feedback system
- Returns:
- freq: array of frequency[Hz] of the resonant filters
- zeta: array of damping of the resonant filters
- k: array of peak width of the resonant filters
- phi: array of phase lead of the resonant filter
Examples
>>> Ps = ctrl.tf([1.], [2., 10., 0.])
>>> Cs = ctrl.pid(10., 1., 10., 0.7, 2., 10., 0.)
>>> ctrl.rfoptparam([2., 3., 5.], [0.001, 0.001, 0.001], [0.1, 0.1, 0.1], ctrl.feedback(Ps, Cs, sys='T'))
The common pole-zeros of the zpk model have been deleted.
([2.0, 3.0, 5.0], [0.001, 0.001, 0.001], array([-0.00025695, -0.00049616, 0.0003898 ]), array([ 860.21053991, 633.22924516, -1090.49879949]))rfopt
pylib_sakata.ctrl.rfopt(freq, zeta, depth, sysT, dt=None, method=‘tustin’)
This function is for design of optimized resonant filters (resonant filters).
- Parameters:
- freq: array of frequency[Hz] of the resonant filters
- zeta: array of damping of the resonant filters
- depth: array of depth of the resonant filters (0 < depth < 1)
- sysT: LTI model (StateSpace or TransferFunction or ZpkModel or FreqResp) of complementary sensitivity function of the previous feedback system
- dt: sampling time of the LTI model (Optional), Default: 0, set the value >= 0. If dt = 0, the system is continuous time system.
- method: discretized method (Optional), Default: ‘tustin’, set a method if dt > 0
- Returns:
- out: array of instance of TransferFunction class of the resonant filters
Examples
>>> Ps = ctrl.tf([1.], [2., 10., 0.])
>>> Cs = ctrl.pid(10., 1., 10., 0.7, 2., 10., 0.)
>>> ctrl.rfopt([2., 3., 5.], [0.001, 0.001, 0.001], [0.1, 0.1, 0.1], ctrl.feedback(Ps, Cs, sys='T'))
The common pole-zeros of the zpk model have been deleted.
array([TransferFunction(array([0.00486434, 0.24323591, 0. ]), array([1.00000000e+00, 2.51327412e-02, 1.57913670e+02])),
TransferFunction(array([0.00723091, 0.35823306, 0. ]), array([1.00000000e+00, 3.76991118e-02, 3.55305758e+02])),
TransferFunction(array([0.01199547, 0.56160871, 0. ]), array([1.00000000e+00, 6.28318531e-02, 9.86960440e+02]))],
dtype=object)>>> ctrl.rfopt([2., 3., 5.], [0.001, 0.001, 0.001], [0.1, 0.1, 0.1], ctrl.feedback(Ps, Cs, sys='T'), 0.001)
The common pole-zeros of the zpk model have been deleted.
array([TransferFunction(array([ 0.0049857 , -0.00972818, 0.00474248]), array([ 1. , -1.99981696, 0.99997487]), 0.001),
TransferFunction(array([ 0.00740923, -0.01446026, 0.00705103]), array([ 1. , -1.99960704, 0.9999623 ]), 0.001),
TransferFunction(array([ 0.01227286, -0.02398427, 0.01171141]), array([ 1. , -1.9989505 , 0.99993719]), 0.001)],
dtype=object)dob
pylib_sakata.ctrl.dob(freq, zeta, M, C, K, dt, nd=0)
This function is for design of a discrete-time disturbance observer (DOB). \[\hat{d} = -z^{-n_d} Q[z] u + Q[z] P^{-1}[z] y\]
Here, it is defined that disturbance \(d\) is injected in the system as plus sign.
- Parameters:
- freq: frequency[Hz] of the pole pair of the DOB
- zeta: damping of the pole pair of the DOB
- M: mass[kg] of the plant
- C: viscosity[N/(m/s)] of the plant
- K: stiffness[N/m] of the plant
- dt: sampling time of the system
- nd: sampling number of the dead-time of the system
- Returns:
- DOBu: \(z^{-n_d} Q[z]\)
- DOBy: \(Q[z] P^{-1}[z]\)
Examples
>>> DOBu, DOBy = ctrl.dob(5., 0.7, 1., 10., 0., 0.001, 1)
>>> print(DOBu)
0.0004836 z + 0.0004819
-------------------------
z^3 - 1.956 z^2 + 0.957 z
dt = 0.001
>>> print(DOBy)
970.3 z^2 - 1931 z + 960.7
--------------------------
z^2 - 1.956 z + 0.957
dt = 0.001zpetc
pylib_sakata.ctrl.zpetc(Pz, dt, zerothr=0.99)
This function is for design of a zero phase error tracking controller (ZPETC).
- Parameters:
- Pz: instance of TransferFunction class of discrete-time LTI system
- dt: sampling time of the system
- zerothr: threshold to recognize unstable zeros (Optional), Default: 0.99
- Returns:
- Czpetc: instance of TransferFunction class of ZPETC
- Nzpetc: number of forward samples
>>> Ps = ctrl.tf([1.],[1., 10., 0.])
>>> Pz = ctrl.c2d(Ps, 0.001)
>>> print(Pz)
2.488e-07 z^2 + 4.975e-07 z + 2.488e-07
---------------------------------------
z^2 - 1.99 z + 0.99
dt = 0.001
>>> Czpetc, Nzpetc = ctrl.zpetc(Pz)
The common pole-zeros of the zpk model have been deleted.
>>> print(Czpetc)
2.512e+05 z^4 + 2500 z^3 - 5e+05 z^2 - 2500 z + 2.487e+05
---------------------------------------------------------
z^4
dt = 0.001
>>> Nzpetc
2filt
pylib_sakata.ctrl.filt(num, den, dt)
This function is to create transfer functions as rational expressions in \(z^{-1}\) and to order the numerator and denominator terms in ascending powers of \(z^{-1}\).
- Parameters:
- num: polynomial coefficients of the numerator of the discrete-time LTI model
- den: polynomial coefficients of the denominator of the discrete-time LTI model
- dt: sampling time of the discrete-time LTI model
- Returns:
- out: instance of TransferFunction class of ZPETC
minreal
pylib_sakata.ctrl.minreal(sys)
This function is to delete the common pole-zeros of the system.
- Parameters:
- sys: LTI model (StateSpace or TransferFunction or ZpkModel)
- Returns:
- out: LTI model whose the common pole-zeros were deleted
makeprmset
pylib_sakata.ctrl.makeprmset(path=‘.’)
This function is to create Cpp and header files of controller parameter sets
- Parameters:
- path: path to create Cpp and header files of controller parameter sets
- Returns:
- None
defprmset
pylib_sakata.ctrl.defprmset(tfz, prmSetName, path=‘.’, mode=‘a’)
- Parameters:
- tfz: discrete time TransferFunction model
- prmSetName: parameter set name of the following struct in Cpp
- path: path to create Cpp and header files of controller parameter sets
- mode: mode to open Cpp and header files
- Returns:
- None
typedef struct {
double dA[2];
double dB[2];
double dInPre;
double dOutPre;
} TF1_INF; // 1st order TF information
typedef struct {
double dA[3];
double dB[3];
double dInPre[2];
double dOutPre[2];
} TF2_INF; // 2nd order TF information
typedef struct {
double dA[4];
double dB[4];
double dInPre[3];
double dOutPre[3];
} TF3_INF; // 3rd order TF information