|
From: <mur...@us...> - 2012-01-08 03:33:48
|
Revision: 181
http://python-control.svn.sourceforge.net/python-control/?rev=181&view=rev
Author: murrayrm
Date: 2012-01-08 03:33:41 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
* Restructured documentation (not completed)
* Added in code from Ryan Krauss for operation when slycot is missing
* Updated version number to 0.5b
* See ChangeLog for a more detailed list of changes
Modified Paths:
--------------
trunk/ChangeLog
trunk/doc/bdalg_strings.rst
trunk/doc/class_strings.rst
trunk/doc/conf.py
trunk/doc/index.rst
trunk/doc/intro.rst
trunk/doc/matlab_strings.rst
trunk/doc/modsimp_strings.rst
trunk/examples/rss-balred.py
trunk/setup.py
trunk/src/statesp.py
trunk/src/xferfcn.py
trunk/tests/slycot_convert_test.py
Added Paths:
-----------
trunk/doc/analysis.rst
trunk/doc/examples.rst
trunk/doc/freqplot.rst
trunk/doc/modules.rst
trunk/doc/synthesis.rst
trunk/doc/timeresp.rst
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/ChangeLog 2012-01-08 03:33:41 UTC (rev 181)
@@ -1,5 +1,59 @@
+2012-01-07 Richard Murray <mu...@ma...>
+
+ * doc/modules.rst: added new sections for analysis, synthesis,
+ frequency plots and time response.
+
+ * doc/index.rst (Contents): added modules and examples.
+
+ * src/xferfcn.py (_convertToTransferFunction): added check for
+ slycot import error. If not present, use signal.lti to perform the
+ conversion. Only works for SISO.
+
+ * src/statesp.py (_convertToStateSpace): added check for slycot
+ import error, to allow basic functionality without the presence of
+ slycot (contributed by Ryan Krauss).
+
+ * tests/slycot_convert_test.py (TestSlycot.testTF): moved slycot
+ import into test function, so that test script still works even if
+ time response is not present.
+
+2011-08-09 Richard Murray <mu...@ma...>
+
+ * src/timeresp.py: fixed doc reference to time-series-convention
+
+2011-08-08 Richard Murray <mu...@ma...>
+
+ * doc/index.rst, doc/modules.rst: Moved MATLAB section into
+ python-control modules file
+
2011-08-07 Richard Murray <mu...@ma...>
+ * doc/conf.py: added autosummary extension
+
+ * doc/timeresp.rst: New file containing listing of functions for
+ time responses (step, initial, etc)
+
+ * doc/freqplot.rst: New file listing functions for frequency
+ plots (bode, nyquist, etc)
+
+ * doc/modules.rst: New file that contains a listing of the major
+ modules in the toolbox
+
+ * doc/index.rst (Contents): Rearranged contents to put modules
+ documentation in a separate section. Also added examples section
+ (not quite ready yet).
+
+2011-08-07 Richard Murray <mu...@ma...>
+
+ * examples/rss-balred.py: reordered outputs from call to matlab.step
+ (missed this the first time around)
+
+ * doc/matlab_strings.rst: Matlab -> MATLAB (proper spelling)
+
+ * setup.py, doc/conf.py: updated version to 0.5b
+
+2011-08-07 Richard Murray <mu...@ma...>
+
* doc/conf.py: Updated version numbers to 0.5a, regenerated
documentation and reposted on web (note that 0.5a tag and source
distribution have this wrong)
Added: trunk/doc/analysis.rst
===================================================================
--- trunk/doc/analysis.rst (rev 0)
+++ trunk/doc/analysis.rst 2012-01-08 03:33:41 UTC (rev 181)
@@ -0,0 +1,2 @@
+Control System Analysis
+***********************
\ No newline at end of file
Modified: trunk/doc/bdalg_strings.rst
===================================================================
--- trunk/doc/bdalg_strings.rst 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/doc/bdalg_strings.rst 2012-01-08 03:33:41 UTC (rev 181)
@@ -1,7 +1,7 @@
-Block Diagram Algebra Routines
-******************************
+Block Diagram Algebra
+*********************
-The Block Diagram Algebra Module
-================================
+.. toctree::
+
.. automodule:: bdalg
:members:
Modified: trunk/doc/class_strings.rst
===================================================================
--- trunk/doc/class_strings.rst 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/doc/class_strings.rst 2012-01-08 03:33:41 UTC (rev 181)
@@ -1,12 +1,12 @@
Python-Control Classes
**********************
-The State Space Module
-======================
+State Space Class
+=================
.. automodule:: statesp
:members:
-The Transfer Function Module
-============================
+Transfer Function Class
+=======================
.. automodule:: xferfcn
- :members:
\ No newline at end of file
+ :members:
Modified: trunk/doc/conf.py
===================================================================
--- trunk/doc/conf.py 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/doc/conf.py 2012-01-08 03:33:41 UTC (rev 181)
@@ -34,7 +34,8 @@
# ``sphinx.ext.viewcode`` : Include highlighted source code in the
# documentation
extensions = ['sphinx.ext.autodoc', 'numpydoc', 'sphinx.ext.pngmath',
- 'sphinx.ext.intersphinx', 'sphinx.ext.todo']
+ 'sphinx.ext.intersphinx', 'sphinx.ext.todo',
+ 'sphinx.ext.autosummary']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
@@ -49,7 +50,7 @@
master_doc = 'index'
# General information about the project.
-project = u'Python Control'
+project = u'Python Control Systems Library'
copyright = u'2011, Richard M. Murray et al.'
# The version info for the project you're documenting, acts as replacement for
@@ -57,9 +58,9 @@
# built documents.
#
# The short X.Y version.
-version = '0.5a'
+version = '0.5b'
# The full version, including alpha/beta/rc tags.
-release = '0.5a'
+release = '0.5b'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@@ -99,7 +100,7 @@
#should be linked to in this documentation.
intersphinx_mapping = \
{'scipy':('http://docs.scipy.org/doc/scipy/reference/', None),
- 'numpy':('http://docs.scipy.org/doc/numpy/reference/', None)}
+ 'numpy':('http://docs.scipy.org/doc/numpy', None)}
#If this is True, todo and todolist produce output, else they produce nothing.
#The default is False.
Added: trunk/doc/examples.rst
===================================================================
--- trunk/doc/examples.rst (rev 0)
+++ trunk/doc/examples.rst 2012-01-08 03:33:41 UTC (rev 181)
@@ -0,0 +1,2 @@
+Examples
+********
Added: trunk/doc/freqplot.rst
===================================================================
--- trunk/doc/freqplot.rst (rev 0)
+++ trunk/doc/freqplot.rst 2012-01-08 03:33:41 UTC (rev 181)
@@ -0,0 +1,15 @@
+Frequency Domain Plotting
+*************************
+
+.. toctree::
+
+Plotting routines
+=================
+.. autofunction:: freqplot.bode_plot
+.. autofunction:: freqplot.nyquist_plot
+.. autofunction:: freqplot.gangof4_plot
+.. autofunction:: nichols.nichols_plot
+
+Utility functions
+=================
+.. autofunction:: freqplot.default_frequency_range
Modified: trunk/doc/index.rst
===================================================================
--- trunk/doc/index.rst 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/doc/index.rst 2012-01-08 03:33:41 UTC (rev 181)
@@ -3,18 +3,23 @@
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
-Welcome to Python-Control's documentation!
-==========================================
+Python Control User's Manual
+============================
+Welcome to the Python Control Systems Library (python-control) User's
+Manual. This manual describes the python-control package, including
+all of the functions defined in the package and examples showing how
+to use the package.
+
Contents:
.. toctree::
+ :maxdepth: 2
intro
class_strings
- modsimp_strings
- matlab_strings
- bdalg_strings
+ modules
+ examples
Indices and tables
==================
Modified: trunk/doc/intro.rst
===================================================================
--- trunk/doc/intro.rst 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/doc/intro.rst 2012-01-08 03:33:41 UTC (rev 181)
@@ -2,8 +2,14 @@
Introduction
============
-Welcome to the Python-Control project.
+Welcome to the Python Control Systems Toolbox (python-control) User's
+Manual. This manual contains information on using the python-control
+package, including documentation for all functions in the package and
+examples illustrating their use.
+Overview of the Toolbox
+-----------------------
+
The python-control package is a set of python classes and functions
that implement common operations for the analysis and design of
feedback control systems. The initial goal is to implement all of the
@@ -39,15 +45,22 @@
Getting Started
---------------
1. Download latest release from http://sf.net/projects/python-control/files.
+
2. Untar the source code in a temporary directory and run 'python setup.py
install' to build and install the code
-3. To see if things are working correctly, run ipython -pylab and run the
- script 'examples/secord-matlab.py'. This should generate a set response,
- Bode plot and Nyquist plot for a simple second order system.
+
+3. To see if things are working correctly, run ipython -pylab and run
+ the script 'examples/secord-matlab.py'. This should generate a
+ step response, Bode plot and Nyquist plot for a simple second order
+ system.
+
4. To see the commands that are available, run the following commands in
ipython::
+
>>> import control
>>> ?control.matlab
+
5. If you want to have a MATLAB-like environment for running the control
toolbox, use::
+
>>> from control.matlab import *
Modified: trunk/doc/matlab_strings.rst
===================================================================
--- trunk/doc/matlab_strings.rst 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/doc/matlab_strings.rst 2012-01-08 03:33:41 UTC (rev 181)
@@ -1,8 +1,6 @@
-Matlab-like Routines
-********************
+MATLAB Compatibility Module
+***************************
-The Matlab Module
-=================
.. automodule:: matlab
:members:
Modified: trunk/doc/modsimp_strings.rst
===================================================================
--- trunk/doc/modsimp_strings.rst 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/doc/modsimp_strings.rst 2012-01-08 03:33:41 UTC (rev 181)
@@ -1,7 +1,5 @@
Model Simplification Tools
**************************
-The modelsimp Module
-====================
.. automodule:: modelsimp
:members:
Added: trunk/doc/modules.rst
===================================================================
--- trunk/doc/modules.rst (rev 0)
+++ trunk/doc/modules.rst 2012-01-08 03:33:41 UTC (rev 181)
@@ -0,0 +1,12 @@
+Python-Control Modules
+**********************
+
+.. toctree::
+
+ bdalg_strings
+ analysis
+ freqplot
+ timeresp
+ synthesis
+ modsimp_strings
+ matlab_strings
Added: trunk/doc/synthesis.rst
===================================================================
--- trunk/doc/synthesis.rst (rev 0)
+++ trunk/doc/synthesis.rst 2012-01-08 03:33:41 UTC (rev 181)
@@ -0,0 +1,2 @@
+Control System Synthesis
+************************
\ No newline at end of file
Added: trunk/doc/timeresp.rst
===================================================================
--- trunk/doc/timeresp.rst (rev 0)
+++ trunk/doc/timeresp.rst 2012-01-08 03:33:41 UTC (rev 181)
@@ -0,0 +1,8 @@
+Time Domain Simulation
+**********************
+
+.. automodule:: timeresp
+ :members:
+
+.. autofunction:: phaseplot.phase_plot
+.. autofunction:: phaseplot.box_grid
Modified: trunk/examples/rss-balred.py
===================================================================
--- trunk/examples/rss-balred.py 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/examples/rss-balred.py 2012-01-08 03:33:41 UTC (rev 181)
@@ -26,8 +26,8 @@
# Comparison of the step responses of the full and reduced systems
plt.figure(1)
-t, y = mt.step(fsys)
-tr, yr = mt.step(rsys)
+y, t = mt.step(fsys)
+yr, tr = mt.step(rsys)
plt.plot(t.T, y.T)
plt.hold(True)
plt.plot(tr.T, yr.T)
Modified: trunk/setup.py
===================================================================
--- trunk/setup.py 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/setup.py 2012-01-08 03:33:41 UTC (rev 181)
@@ -4,7 +4,7 @@
from setuptools import setup
setup(name = 'control',
- version = '0.5a',
+ version = '0.5b',
description = 'Python Control Systems Library',
author = 'Richard Murray',
author_email = 'mu...@cd...',
Modified: trunk/src/statesp.py
===================================================================
--- trunk/src/statesp.py 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/src/statesp.py 2012-01-08 03:33:41 UTC (rev 181)
@@ -75,7 +75,7 @@
from numpy import all, angle, any, array, asarray, concatenate, cos, delete, \
dot, empty, exp, eye, matrix, ones, pi, poly, poly1d, roots, shape, sin, \
- zeros
+ zeros, squeeze
from numpy.random import rand, randn
from numpy.linalg import inv, det, solve
from numpy.linalg.linalg import LinAlgError
@@ -459,28 +459,37 @@
# Already a state space system; just return it
return sys
elif isinstance(sys, xferfcn.TransferFunction):
- from slycot import td04ad
- if len(kw):
- raise TypeError("If sys is a TransferFunction, _convertToStateSpace \
-cannot take keywords.")
+ try:
+ from slycot import td04ad
+ if len(kw):
+ raise TypeError("If sys is a TransferFunction, _convertToStateSpace \
+ cannot take keywords.")
- # Change the numerator and denominator arrays so that the transfer
- # function matrix has a common denominator.
- num, den = sys._common_den()
- # Make a list of the orders of the denominator polynomials.
- index = [len(den) - 1 for i in range(sys.outputs)]
- # Repeat the common denominator along the rows.
- den = array([den for i in range(sys.outputs)])
- # TODO: transfer function to state space conversion is still buggy!
- #print num
- #print shape(num)
- ssout = td04ad('R',sys.inputs, sys.outputs, index, den, num,tol=0.0)
-
- states = ssout[0]
- return StateSpace(ssout[1][:states, :states],
- ssout[2][:states, :sys.inputs],
- ssout[3][:sys.outputs, :states],
- ssout[4])
+ # Change the numerator and denominator arrays so that the transfer
+ # function matrix has a common denominator.
+ num, den = sys._common_den()
+ # Make a list of the orders of the denominator polynomials.
+ index = [len(den) - 1 for i in range(sys.outputs)]
+ # Repeat the common denominator along the rows.
+ den = array([den for i in range(sys.outputs)])
+ # TODO: transfer function to state space conversion is still buggy!
+ #print num
+ #print shape(num)
+ ssout = td04ad('R',sys.inputs, sys.outputs, index, den, num,tol=0.0)
+
+ states = ssout[0]
+ return StateSpace(ssout[1][:states, :states],
+ ssout[2][:states, :sys.inputs],
+ ssout[3][:sys.outputs, :states],
+ ssout[4])
+ except ImportError:
+ lti_sys = lti(squeeze(sys.num), squeeze(sys.den))#<-- do we want to squeeze first
+ # and check dimenations? I think
+ # this will fail if num and den aren't 1-D
+ # after the squeeze
+ return StateSpace(lti_sys.A, lti_sys.B, lti_sys.C, lti_sys.D)
+
+
elif isinstance(sys, (int, long, float, complex)):
if "inputs" in kw:
inputs = kw["inputs"]
@@ -627,8 +636,8 @@
If ``sys`` is already a SISO system, it will be returned unaltered.
- Parameters:
-
+ Parameters
+ ----------
sys: StateSpace
Linear (MIMO) system that should be converted.
input: int
Modified: trunk/src/xferfcn.py
===================================================================
--- trunk/src/xferfcn.py 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/src/xferfcn.py 2012-01-08 03:33:41 UTC (rev 181)
@@ -76,7 +76,7 @@
# External function declarations
from numpy import angle, any, array, empty, finfo, insert, ndarray, ones, \
- polyadd, polymul, polyval, roots, sort, sqrt, zeros
+ polyadd, polymul, polyval, roots, sort, sqrt, zeros, squeeze
from scipy.signal import lti
from copy import deepcopy
from lti import Lti
@@ -767,27 +767,39 @@
return sys
elif isinstance(sys, statesp.StateSpace):
- from slycot import tb04ad
- if len(kw):
- raise TypeError("If sys is a StateSpace, _convertToTransferFunction \
-cannot take keywords.")
+ try:
+ from slycot import tb04ad
+ if len(kw):
+ raise TypeError("If sys is a StateSpace, \
+ _convertToTransferFunction cannot take keywords.")
- # Use Slycot to make the transformation
- # Make sure to convert system matrices to numpy arrays
- tfout = tb04ad(sys.states, sys.inputs, sys.outputs, array(sys.A),
- array(sys.B), array(sys.C), array(sys.D), tol1=0.0)
+ # Use Slycot to make the transformation
+ # Make sure to convert system matrices to numpy arrays
+ tfout = tb04ad(sys.states, sys.inputs, sys.outputs, array(sys.A),
+ array(sys.B), array(sys.C), array(sys.D), tol1=0.0)
- # Preallocate outputs.
- num = [[[] for j in range(sys.inputs)] for i in range(sys.outputs)]
- den = [[[] for j in range(sys.inputs)] for i in range(sys.outputs)]
+ # Preallocate outputs.
+ num = [[[] for j in range(sys.inputs)] for i in range(sys.outputs)]
+ den = [[[] for j in range(sys.inputs)] for i in range(sys.outputs)]
- for i in range(sys.outputs):
- for j in range(sys.inputs):
- num[i][j] = list(tfout[6][i, j, :])
- # Each transfer function matrix row has a common denominator.
- den[i][j] = list(tfout[5][i, :])
- # print num
- # print den
+ for i in range(sys.outputs):
+ for j in range(sys.inputs):
+ num[i][j] = list(tfout[6][i, j, :])
+ # Each transfer function matrix row has a common denominator.
+ den[i][j] = list(tfout[5][i, :])
+ # print num
+ # print den
+ except ImportError:
+ # If slycot is not available, use signal.lti (SISO only)
+ if (sys.inputs != 1 or sys.outputs != 1):
+ raise TypeError("No support for MIMO without slycot")
+
+ lti_sys = lti(sys.A, sys.B, sys.C, sys.D)
+ num = squeeze(lti_sys.num)
+ den = squeeze(lti_sys.den)
+ print num
+ print den
+
return TransferFunction(num, den)
elif isinstance(sys, (int, long, float, complex)):
if "inputs" in kw:
Modified: trunk/tests/slycot_convert_test.py
===================================================================
--- trunk/tests/slycot_convert_test.py 2012-01-08 02:57:46 UTC (rev 180)
+++ trunk/tests/slycot_convert_test.py 2012-01-08 03:33:41 UTC (rev 181)
@@ -5,7 +5,6 @@
import unittest
import numpy as np
-from slycot import tb04ad, td04ad
import control.matlab as matlab
class TestSlycot(unittest.TestCase):
@@ -30,6 +29,7 @@
""" Directly tests the functions tb04ad and td04ad through direct comparison of transfer function coefficients.
Similar to convert_test, but tests at a lower level.
"""
+ from slycot import tb04ad, td04ad
for states in range(1, self.maxStates):
for inputs in range(1, self.maxI+1):
for outputs in range(1, self.maxO+1):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|