alchemyst/Skogestad-Python

View on GitHub
reproductions/Example/Example_02_05.ipynb

Summary

Maintainability
Test Coverage
{
  "cells": [
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "from __future__ import print_function\n",
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "%matplotlib inline\n",
        "from robustcontrol.utils import feedback, tf, marginsclosedloop\n",
        "from robustcontrol.utilsplot import  step_response_plot, bodeclosedloop\n",
        "\n",
        "\n",
        "s = tf([1, 0], 1)\n",
        "G = 4/((s - 1)*(0.02*s + 1)**2)\n",
        "Kc = 1.25\n",
        "Tauc = 1.5\n",
        "K = Kc*(1 + 1/(Tauc*s))\n",
        "L = K * G\n",
        "T = feedback(L, 1)\n",
        "S = feedback(1, L)\n",
        "u = S * K\n",
        "\n",
        "plt.figure('Figure 2.9')\n",
        "step_response_plot(T, u, 4, 0)\n",
        "plt.show()\n",
        "\n",
        "plt.figure('Figure 2.15')\n",
        "bodeclosedloop(G, K, -1, 2, margin=True)\n",
        "plt.show()\n",
        "# TODO there is a discrepancy with the phase plots\n",
        "\n",
        "GM, PM, wc, wb, wbt, valid = marginsclosedloop(L)\n",
        "print('GM:', np.round(GM, 2))\n",
        "print('PM:', np.round(PM / 180 * np.pi, 2), \"rad or\", np.round(PM, 2), \"deg\")\n",
        "print('wb:', np.round(wb, 2))\n",
        "print('wc:', np.round(wc, 2))\n",
        "print('wbt:', np.round(wbt, 4))\n"
      ],
      "outputs": [],
      "execution_count": null
    }
  ],
  "metadata": {
    "anaconda-cloud": {},
    "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.6.1"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 1
}