from numpy import e,arange def hp(t,Kp,Ki,Kd,Td): if t<0: z=0 elif Td==0: z=Kp+Ki*t else: z=Kp+Ki*t+Kp*Kd*e**(-t/Td) return z
#!/usr/bin/env python #coding=utf8 import matplotlib.pyplot as plt import matplotlib as mpl mpl.rcParams['font.family'] = 'fantasy' mpl.rcParams['font.fantasy'] = 'Comic Sans MS, Arial' from numpy import e,arange def hp(t,Kp,Ki,Kd,Td): if t<0: z=0 elif Td==0: z=Kp+Ki*t else: z=Kp+Ki*t+Kp*Kd*e**(-t/Td) return z x=arange(-2,10,0.01) y=[hp(t,2,0,0,0) for t in x] y1=[hp(t,2,0.25,0,0) for t in x] y2=[hp(t,2,0.25,2,2) for t in x] plt.title(' ') plt.plot(x, y, linewidth=2, label=' ') plt.plot(x, y1, linewidth=2, label=' ') plt.plot(x, y2, linewidth=2, label=' ') plt.legend(loc='best') plt.grid(True) plt.show()
#!/usr/bin/env python #coding=utf8 import matplotlib.pyplot as plt import matplotlib as mpl mpl.rcParams['font.family'] = 'fantasy' mpl.rcParams['font.fantasy'] = 'Comic Sans MS, Arial' from numpy import arange,sin,cos,sign def z(t,a,b): if -a<4*sin(t)<b and 4*cos(t)>0: z=0 elif -b<4*sin(t)<a and 4*cos(t)<0: z=0 else: z=sign(sin(t)) return zx=arange(0,6,0.005) y=[4*sin(t) for t in x] y1=[z(t,2,3) for t in x] y2=[2 for t in x] y3=[3 for t in x] plt.figure() plt.title(' : -') plt.plot(x, y, linewidth=2, label=' ') plt.plot(x, y1, linewidth=2, label=' ') plt.plot(x, y2, linewidth=1, label='2 ') plt.plot(x, y3,linewidth=1, label='3') plt.legend(loc='best') plt.grid(True) plt.figure() plt.title(' . ') plt.plot(y, y1, linewidth=2, label=' ') plt.legend(loc='best') plt.grid(True) plt.show()
#!/usr/bin/env python #coding=utf8 import matplotlib.pyplot as plt import matplotlib as mpl mpl.rcParams['font.family'] = 'fantasy' mpl.rcParams['font.fantasy'] = 'Comic Sans MS, Arial' from numpy import e,arange def hp(t,Kp,Ti,Kd,Td): z=Kp+Kp*t/Ti+Kp*Kd*e**(-t/Td) return z x=arange(0,10,0.02) y1=[hp(t,2,2,0,0.5) for t in x] y2=[hp(t,2,2,4,0.5) for t in x] plt.title(' ') plt.plot(x, y1, linewidth=1, label=' ') plt.plot(x, y2, linewidth=2, label=' ') plt.legend(loc='best') plt.grid(True) plt.show()
#!/usr/bin/env python #coding=utf8 import matplotlib.pyplot as plt import matplotlib as mpl mpl.rcParams['font.family'] = 'fantasy' mpl.rcParams['font.fantasy'] = 'Comic Sans MS, Arial' from numpy import arange,sign def fd(Kd,Td,dt,x,x1,y):# - () return (1-dt/Td)*y+Kd*(x-x1) def fa(Ta,Ka,dt,x,y):# ( ) return (1-dt/Ta)*y+Ka*x*dt/Ta def fi(so,dt,x,y):# ( ) return y+so*x*dt """ """ te=15;N=300;dt=0.05 x0=[0 for w in arange(0,N+1)];x1=[0 for w in arange(0,N+1)] x2=[0 for w in arange(0,N+1)];x3=[0 for w in arange(0,N+1)] z=[0 for w in arange(0,N+1)];z1=[0 for w in arange(0,N+1)] z2=[0 for w in arange(0,N+1)];m=[0 for w in arange(0,N+1)] x=[0 for w in arange(0,N+1)] """ """ def P(so,Ka,Ta,a,b,Kd,Td,Dl,e): for j in arange(0,N,1): x0[j+1]=e-Dl*m[j] x[j+1]=x0[j+1]+x2[j]-x3[j] if -a<x[j+1]<b and x[j+1]>x[j]: z1[j+1]=0 else: z1[j+1]=sign(x[j-1]) if -b<x[j+1]<a and x[j+1]<x[j]: z2[j+1]=0 else: z2[j+1]=sign(x[j-1]) if x[j+1]>x[j]: z[j+1]=z1[j+1] else: z[j+1]=z2[j+1] x1[j+1]=fd(Kd,Td,dt,x0[j+1],x0[j],x1[j]) x2[j+1]=fd(1,Ta,dt,x1[j+1],x1[j],x2[j]) x3[j+1]=fa(Ta,Ka,dt,z[j+1],x3[j]) m[j+1]=fi(so,dt,z[j],m[j]) return m NN=[j*dt for j in arange(0,N+1,1)] #P(so,Ka,Ta,a,b,Kd,Td,Dl,e) #PID=P(1,10,5,0.4,0.5,10,1,0,1) #PP=P(1,0.1,0.1,0.2,0.6,0,0.2,4,1) #PI=P(1,10,5,0.4,0.5,0,0.2,0,1) #PI1=P(0.5,10,5,0.4,0.5,0,0.2,0,1) plt.figure() plt.title(' - ') plt.plot(NN, P(1,10,5,0.4,0.5,0,0.2,0,1), linewidth=2, label=' - ') plt.plot(NN,P(1,10,5,0.4,0.5,10,1,0,1), linewidth=2, label=' - ') plt.legend(loc='best') plt.grid(True) plt.figure() plt.title(' - ') plt.plot(NN, P(1,10,5,0.4,0.5,0,0.2,0,1), linewidth=2, label=' -. -1 -1') plt.plot(NN,P(0.5,10,5,0.4,0.5,0,0.2,0,1), linewidth=2, label=' -. -0.5 -1') plt.plot(NN,P(1,0.1,0.1,0.2,0.6,0,0.2,4,1), linewidth=2, label=' -. -1 -1') plt.legend(loc='best') plt.grid(True) plt.show()
Source: https://habr.com/ru/post/345714/
All Articles