Esempio n. 1
0
    def testDcgain(self, siso):
        """Test dcgain() for SISO system"""
        # Create different forms of a SISO system using scipy.signal
        A, B, C, D = siso.ss1.A, siso.ss1.B, siso.ss1.C, siso.ss1.D
        Z, P, k = sp.signal.ss2zpk(A, B, C, D)
        num, den = sp.signal.ss2tf(A, B, C, D)
        sys_ss = siso.ss1

        # Compute the gain with ``dcgain``
        gain_abcd = dcgain(A, B, C, D)
        gain_zpk = dcgain(Z, P, k)
        gain_numden = dcgain(np.squeeze(num), den)
        gain_sys_ss = dcgain(sys_ss)
        # print('\ngain_abcd:', gain_abcd, 'gain_zpk:', gain_zpk)
        # print('gain_numden:', gain_numden, 'gain_sys_ss:', gain_sys_ss)

        # Compute the gain with a long simulation
        t = linspace(0, 1000, 1000)
        y, _t = step(sys_ss, t)
        gain_sim = y[-1]
        # print('gain_sim:', gain_sim)

        # All gain values must be approximately equal to the known gain
        np.testing.assert_array_almost_equal(
            [gain_abcd, gain_zpk, gain_numden, gain_sys_ss, gain_sim],
            [59, 59, 59, 59, 59])
Esempio n. 2
0
 def __init__(self, sysc=sysc_default, Ts=dt_default, epsilon=1e-7):
     self.sysd = c2d(sysc, Ts)
     self.Ts = Ts
     self.sysc = sysc
     self.epsilon = epsilon
     self.est = Estimator(self.sysd, 500, self.epsilon)
     self.y_index = None
     self.worst_case_control = 'current'
     self.k = None
     self.y_up = None
     self.y_lo = None
     # diy
     self.p = 0.5
     self.i = 7
     self.d = 0
     self.total = 10
     self.slot = int(self.total / Ts)
     self.t_arr = linspace(0, self.total, self.slot + 1)
     self.ref = [0] * 251 + [1] * 250
     self.thres = 5
     self.drift = 0.12
     self.x_0 = [0]
     self.y_real_arr = []
     self.s = 0
     self.att = 0
     self.cin = 0
     self.ymeasure = 0
     self.yreal = 0
     self.score = []
     self.place = 350
     self.maxc = 5
     # --------------------------------------
     self.safeset = {'lo': [-2.7], 'up': [2.7]}
Esempio n. 3
0
 def __init__(self, sysc=sysc_default, Ts=dt_default, epsilon=1e-7):
     self.sysd = c2d(sysc, Ts)
     self.Ts = Ts
     self.sysc = sysc
     self.epsilon = epsilon
     self.est = Estimator(self.sysd, 500, self.epsilon)
     self.y_index = None
     self.worst_case_control = 'current'
     self.k = None
     self.y_up = None
     self.y_lo = None
     # diy
     self.p = 0.1
     self.i = 0
     self.d = 0.6
     self.total = 30
     self.slot = int(self.total / Ts)
     self.t_arr = linspace(0, self.total, self.slot + 1)
     self.ref = [2] * 601 + [4] * 600 + [2] * 300
     self.thres = 3
     self.drift = 1
     self.x_0 = [0]
     self.y_real_arr = []
     self.s = 0
     self.att = 0
     self.cin = 0
     self.ymeasure = 0
     self.yreal = 0
     self.score = []
     self.place = 700
     self.maxc = 50
     self.xmeasure = [[0], [0], [0], [0], [0], [0], [0], [0], [0]]
     self.xreal = [[0], [0], [0], [0], [0], [0], [0], [0], [0]]
     self.safeset = {'lo': [-10000] * 8 + [-1], 'up': [10000] * 8 + [8]}
Esempio n. 4
0
 def __init__(self, sysc=sysc_default, Ts=dt_default, epsilon=1e-7):
     self.sysd = c2d(sysc, Ts)
     self.Ts = Ts
     self.sysc = sysc
     self.epsilon = epsilon
     self.est = Estimator(self.sysd, 500, self.epsilon)
     self.y_index = None
     self.worst_case_control = 'current'
     self.k = None
     self.y_up = None
     self.y_lo = None
     # diy
     self.p = 14
     self.i = 0.8
     self.d = 5.7
     self.total = 10
     self.slot = int(self.total / Ts)
     self.t_arr = linspace(0, self.total, self.slot + 1)
     self.ref = [0.5] * 201 + [0.7] * 200 + [0.5] * 100
     self.thres = 10
     self.drift = 1
     self.x_0 = [0]
     self.y_real_arr = []
     self.s = 0
     self.att = 0
     self.cin = 0
     self.ymeasure = 0
     self.yreal = 0
     self.score = []
     self.place = 300
     self.maxc = 20
     self.xmeasure = [[0], [0], [0]]
     self.xreal = [[0], [0], [0]]
Esempio n. 5
0
 def __init__(self, sysc=sysc_default, Ts=dt_default, epsilon=1e-7):
     self.sysd = c2d(sysc, Ts)
     self.Ts = Ts
     self.sysc = sysc
     self.epsilon = epsilon
     self.est = Estimator(self.sysd, 500, self.epsilon)
     self.y_index = None
     self.worst_case_control = 'current'
     self.k = None
     self.y_up = None
     self.y_lo = None
     # diy
     self.p = 11
     self.i = 0
     self.d = 5
     self.total = 24
     self.slot = int(self.total / Ts)
     self.t_arr = linspace(0, self.total, self.slot + 1)
     self.ref = [math.pi / 2] * 71 + [math.pi / 2] * 50
     self.thres = 0.2
     self.drift = 0.01
     self.x_0 = [0]
     self.y_real_arr = []
     self.s = 0
     self.att = 0
     self.cin = 0
     self.ymeasure = 0
     self.yreal = 0
     self.score = []
     self.place = 20
     self.maxc = 20
     self.xmeasure = [[0], [0], [0]]
     self.xreal = [[0], [0], [0]]
     self.safeset = {
         'lo': [-4, -1000000000, -100000000],
         'up': [4, 1000000000, 100000000]
     }
Esempio n. 6
0
plt.figure('Simulation 10')
plt.plot(tt, temp-1100, label='temp')
plt.plot(tt, sim_wfs, label='sim_wfs')
plt.plot(tt, sim_temp, label='sim_temp')
plt.legend()
plt.grid()

plt.ylim((-400,1200))


plant = control.tf(.3, (1/10, 1))
b, a = signal.butter(3, 2/500, 'low')
flt = control.tf(b, a, .001)
# t1,y1 = control.step_response(flt, T=tt)
t1,y1 = control.step_response(700*plant_d, T=mt.linspace(0,12,1201))
t3,y3 = control.step_response(700*plant_d*flt, T=mt.linspace(0,12,1201))
c_p = control.feedback(ctrl2_d*plant_d*flt)
t2,y2 = control.step_response(200*c_p, T=mt.linspace(0,12,1201))
plt.figure('Controller')
plt.plot(t1, y1, label='Plant')
plt.plot(t3, y3, label='Plant*Filter')
plt.plot(t2, y2, label='K*G')
# plt.plot(tt, temp-1100, label='temp')
# plt.plot(tt, temp_filtered_2, label='temp_filtered_2')
plt.ylim((0,400))
plt.legend()
plt.grid()


Kp=3