Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

ControlAut http://localhost:8888/nbconvert/html/Documents/ProgPython/ControlA...

import emoji
import numpy as np
import matplotlib.pyplot as plt
import control as co
from scipy import signal
from IPython.display import Image
from IPython.core.display import HTML
import ipywidgets as widgets
from ipywidgets import interact, interactive, fixed, interact_manual

1 de 9 22/01/2021 04:43 p. m.
ControlAut http://localhost:8888/nbconvert/html/Documents/ProgPython/ControlA...

2 de 9 22/01/2021 04:43 p. m.
ControlAut http://localhost:8888/nbconvert/html/Documents/ProgPython/ControlA...

R=1; L=0.5; J=0.01; b=0.1; Km=0.01;

A=[[-R/L, -Km/L],[Km/J, -b/J]]


B=[[1/L],[0]]
C=[0,1]
D=0
sys2=signal.StateSpace(A,B,C,D)
t2,y2=signal.step(sys2)

plt.plot(t2,y2)
#plt.plot(t2, [1 for i in t2])
plt.grid()
plt.xlabel('Voltaje (V)')
plt.ylabel('Tiempo (t)')
#plt.ylim(0,1.20)
#plt.xlim(0,3)
plt.show()

3 de 9 22/01/2021 04:43 p. m.
ControlAut http://localhost:8888/nbconvert/html/Documents/ProgPython/ControlA...

sys2

sys=signal.ss2tf(A,B,C,D)
t3,y3=signal.step(sys)
plt.plot(t3,y3)
plt.plot(t2,y2)
#plt.plot(t2, [1 for i in t2])
plt.grid()
plt.ylabel('Velocidad ($\omega$)')
plt.xlabel('Tiempo (t)')
#plt.ylim(0,1.20)
#plt.xlim(0,3)
plt.show()

4 de 9 22/01/2021 04:43 p. m.
ControlAut http://localhost:8888/nbconvert/html/Documents/ProgPython/ControlA...

sys

systf = co.tf([2], [1, 12 ,20.02]) # Creamos el sistema mediante la


t,y=co.step_response(systf)
plt.plot(t,y)
#plt.plot(t2, [1 for i in t2])
plt.grid()
plt.ylabel('Velocidad ($\omega$)')
plt.xlabel('Tiempo (t)')
#plt.ylim(0,1.20)
#plt.xlim(0,3)
plt.show()

systf

5 de 9 22/01/2021 04:43 p. m.
ControlAut http://localhost:8888/nbconvert/html/Documents/ProgPython/ControlA...

sysr=co.feedback(systf,1,-1)

sysr

t,y=co.step_response(sysr)
plt.plot(t,y)
#plt.plot(t2, [1 for i in t2])
plt.grid()
plt.ylabel('Velocidad ($\omega$)')
plt.xlabel('Tiempo (t)')
#plt.ylim(0,1.20)
#plt.xlim(0,3)
plt.show()

6 de 9 22/01/2021 04:43 p. m.
ControlAut http://localhost:8888/nbconvert/html/Documents/ProgPython/ControlA...

ganancia=widgets.IntSlider(
value=10,
min=1,
max=150,
step=1,
description='Ganancia:',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='d'
)
display(ganancia)

systf=co.tf([2*ganancia.value], [1, 12 ,20.02])


sysrg=co.feedback(systf,1)
tr,yr=co.step_response(sysrg)
plt.plot(tr,yr)
#plt.plot(t2, [1 for i in t2])
plt.grid()
plt.ylabel('Velocidad ($\omega$)')
plt.xlabel('Tiempo (t)')
#plt.ylim(0,1.20)
#plt.xlim(0,3)
plt.show()

7 de 9 22/01/2021 04:43 p. m.
ControlAut http://localhost:8888/nbconvert/html/Documents/ProgPython/ControlA...

sysrg

kp=100;kd=10;ki=200;
contr=co.tf([kd, kp, ki],[1, 0])
systf=co.tf([2], [1, 12 ,20.02])
sysc=contr*systf
syscr=co.feedback(sysc,1,-1)
tr,yr=co.step_response(syscr)
plt.plot(tr,yr)
#plt.plot(t2, [1 for i in t2])
plt.grid()
plt.ylabel('Velocidad ($\omega$)')
plt.xlabel('Tiempo (t)')
#plt.ylim(0,1.20)
#plt.xlim(0,3)
plt.show()

8 de 9 22/01/2021 04:43 p. m.
ControlAut http://localhost:8888/nbconvert/html/Documents/ProgPython/ControlA...

contr

sysc

syscr

tr,yr=co.step_response(syscr)

9 de 9 22/01/2021 04:43 p. m.

You might also like