{ "cells": [ { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "import sympy\n", "import matplotlib.pyplot as plt\n", "import numpy\n", "import control \n", "from control.matlab import *\n", "sympy.init_printing()\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "from ipywidgets import interact" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "ts = numpy.linspace(0, 40,1000)\n", "\n", "s = tf([1,0],1)\n", "\n", "def sistema(Kc):\n", " #G = Kc / (s**4 + 3*s**3 + 3*s**2 + 2*s + Kc)\n", " \n", " Gma = (s+2) / (s*(s+3)*(s**2+2*s+5))\n", " G = feedback(Kc*Gma,1)\n", " \n", " \n", " #G = wn_in**2*(1+Tp_in*s)/((s**2+2*zeta_in*wn_in*s + wn_in**2))\n", " \n", " plt.figure(figsize=(12, 6))\n", " ax_impulse = plt.subplot2grid((2, 2), (0, 0))\n", " ax_step = plt.subplot2grid((2, 2), (1, 0))\n", " ax_complex = plt.subplot2grid((2, 2), (0, 1), rowspan=2)\n", "\n", " y,t = impulse(G,ts)\n", " ax_impulse.plot(t , y)\n", " ax_impulse.set_title('Impulse response')\n", " ax_impulse.set_ylim(-1, 2)\n", "\n", " y,t = step(G,ts)\n", " ax_step.set_title('Step response')\n", " ax_step.plot(t ,y)\n", " ax_step.set_ylim(0, 2)\n", "\n", "\n", " ax_complex.set_title('Poles plot')\n", " pole,zero = pzmap(G, Plot = False)\n", " ax_complex.scatter(pole.real, pole.imag, marker='x', s=30)\n", " ax_complex.scatter(zero.real, zero.imag, marker='o', s=30)\n", " #ax_complex.axhline(0, color='black')\n", " #ax_complex.axvline(0, color='black')\n", " ax_complex.axis([-10,0.10, -2, 2])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2ed8d164ad454d4fa75c8e6a1e60b57d", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(FloatSlider(value=15.049999999999999, description='Kc', max=30.0, min=0.1), Output()), _…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "interact(sistema, Kc=(0.1, 30));" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }