

Line 1: 
Line 1: 
 {{righttoc}}
  <table width="100%"> 
 This page collects some notes on a control systems library for Python. The plan is to create an alternative to the MATLAB Control System Toolbox™ that can be used in courses and for research. This page collects information about the toolbox, in preparation for actually writing some code. If you stumble across this page and know of a similar package or would like to contribute, let me know.
  <tr><td align=center> 
  <font color='blue' size='+2'>Python Control Systems Library (pythoncontrol)</font></td></tr> 
  </table> __NOTOC__ 

 

 Status updates:
  <br> 
 * 31 May 2010: '''I have moved the wiki for pythoncontrol to SourceForge:''' http://pythoncontrol.sourceforge.net   { style="float: right" width=30% border=1 
 * 29 May 2010: Release of [http://www.cds.caltech.edu/~murray/software/control0.3a.tar.gz control0.3a.tar.gz]. Block diagram algebra for SISO state space systems is now implemented. New options in bode() for setting units to dB and Hz.    
 * 4 Jan 2010: Moved the subversion repository to SourceForge; Gunnar Ristroph is now helping out with the development.
   
 * 2 Oct 2009: Kristian Soltesz at the Department of Automatic Control in Lund is working on developing a wrapper for SLICOT and also sponsoring some masters projects to develop pythonbased control systems tools.
  ==== Announcements ==== 
 * 10 Oct 2009: Release of [http://www.cds.caltech.edu/~murray/software/control0.2.tar.gz control0.2.tar.gz]. Support block diagram algebra on SISO transfer functions plus Nyquist and Bode plots for state space and transfer function objects. Very rough.   * The pythoncontrol user documentation has been shifted from SourceForge to MurrayWiki at Caltech. Developer documentation remains on [http://pythoncontrol.sf.net SourceForge]. 
 * 10 Oct 2009: Set up a sourceforge project for the library: http://sourceforge.net/projects/pythoncontrol. Nothing downloaded yet, but might use this for shared development at some point.   * Version 0.5a has been released: [http://sourceforge.net/mailarchive/message.php?msg_id=27912588 release notes], [http://sourceforge.net/projects/pythoncontrol/files/ file download] 
 * 30 May 2009: Test release of [http://www.cds.caltech.edu/~murray/software/control0.1.tar.gz control0.1.tar.gz] just to see if the pieces are there   } 
  The Python Control Systems Library, pythoncontrol, is a python package that implements basic operations for analysis and design of feedback control systems. 
  * [http://pythoncontrol.sourceforge.net/manual0.5a User manual]  Sphinx documentation for the pythoncontrol package 
  * [[pythoncontrol/Download]]  download and install the latest release of the package 
  * [[pythoncontrol/Example: Vertical takeoff and landing aircraft]]  demonstration of package capabilities 
  * [https://lists.sourceforge.net/lists/listinfo/pythoncontrolannounce Announcements mailing list]  sign up to receive announcements about pythoncontrol 
  * [[pythoncontrol/Developer assignments]]  a list of who is working on what 
  * [https://sourceforge.net/projects/pythoncontrol/ Project description page]  summary of all project information (SourceForge) 

 

 == Architecture notes ==   === Project Overview === 

 

 The current plan for the library is to implement single input, single output (SISO) transfer functions based on the signal.lti class in scipy, but use a separate class structure for state space objects, which will support multiinput, multioutput (MIMO) systems. There are a couple of reasons for this choice:   The pythoncontrol 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 functionality required to work through the examples in the textbook ''[http://www.cds.caltech.edu/~murray/amwiki Feedback Systems]'' by Åström and Murray. A MATLAB compatibility package (control.matlab) is available that provides functions corresponding to the commands available in the MATLAB Control Systems Toolbox. 
 * The current LTI support in scipy only allows single input, multiple output systems. Hence it will not be possible to share any MIMO functionality with the signal library. Since there are very few uses of SIMO systems in controls, only SISO systems will be supported using the signal.lti object structure.
 
 * As a first cut, I plan to focus on statespace computations and so it makes sense to go ahead and put MIMO functionality here for now. At a later date, it may make sense to add MIMO transfer functions (creating a new class).
 

 

 == Installation instructions ==
  Here are some of the basic functions that are (or will be) available in the package: 
   * Linear input/output systems in state space and frequency domain (transfer functions) 
 I'm using the [http://ipython.scipy.org/moin/ IPython] environment, with [http://scipy.org SciPy] extensions for scientific computing plus the [http://matplotlib.sourceforge.net/ matplotlib] extensions (which enables MATLABlike plotting). I am doing all of my development on OS X, using fink.
  * Block diagram algebra: serial, parallel and feedback interconnections 
   * Time response: initial, step, impulse (using the scipy.signal package) 
 === Prerequisites ===
  * Frequency response: Bode and Nyquist plots 
 Here's what I had to do to get the basic setup that I am using.
  * Control analysis: stability, reachability, observability, stability margins 
 # Install SciPy  I did this using fink. Have to use the main/unstable tree.
  * Control design: eigenvalue placement, linear quadratic regulator 
 # Install matplotlib  Need this for plotting. Also requires the main/unstable tree.
  * Estimator design: linear quadratic estimator (Kalman filter) 
 # Install ipython  interactive python interface. For python 2.5, I had to use the main/unstable tree.
 
  
 Small snippet of code for testing if everything is installed
 
 from scipy import *
 
 from matlibplot import *
 
 a = zeros(1000)
 
 a[:100]=1
 
 b = fft(a)
 
 plot(abs(b))
 
 show() # Not needed if you use ipython pylab
 
  
 === pythoncontrol ===
 
 Standard python package installation:
 
  
 python setup.py install
 
  
 To see if things are working, you can run the script [http://www.cds.caltech.edu/~murray/software/pythoncontrol/examples/secordmatlab.py secordmatlab.py] (using ipython pylab). It should generate a step repsonse, Bode plot and Nyquist plot for a simple second order linear system.
 
  
 === slycot ===
 
  
 Notes
 
 * To compile for 64 bit architecture, use LDFLAGS="arch x86_64" FFLAGS="arch x86_64"
 
  
 == Functionality ==
 
  
 This section contains a list of the functions that I plan to implement in the first few passes through the library. This is mainly based on the functions that we use in CDS 110ab at Caltech, plus a few other functions that I think students are likely to wait to see for one reason or another.
 
  
 === Constructing systems ===
 
 * Basic constructors: ss(A, B, C, D), tf2ss, zpk2ss, iosys(f, h)
 
 * Interconnections: series (*), parallel (+), feedback  
  
 === Analysis ===
 
 * Properties: ctrb, obsv, pole, zero  
 * Frequency plots: bode, nyquist, rlocus, pzmap
 
 * Simulations: iosim, lsim, step, impulse, initial
 
 * Margins: margin
 
  
 === Synthesis ===
 
 * Basic controllers: pid, lead, lag, leadlag
 
 * State space: place, lqr, kalman, estim, reg
 
  
 == Related documentation ==
 
  
 === Python documentation ===
 
 * [http://www.scipy.org/ SciPy.org]  main web site for SciPy
 
 ** [http://ipython.scipy.org/moin/ IPython]  enhanced shell for python
 
 ** [http://matplotlib.sourceforge.net/ matplotlib]  2D plotting for python
 
 * [http://www.pyrorobotics.org PyRo]  Python Robotics library (might be nice to be compatible with this
 
  
 === Related packages ===
 
 * [http://www.slicot.org/ SLICOT]  Fortran 77 implementations of numerical algorithms for computations in systems and control theory
 
 ** [http://github.com/henjo/slicot/tree/master python wrapper]  Numpy wrapper of the control and systems library SLICOT
 
 ** [http://osdir.com/ml/python.scientific.devel/200409/msg00052.html python info]  Message giving information on making SLICOT available in python
 
 * [http://www.gnu.org/software/octave/doc/interpreter/ControlTheory.html Octave Control Systems Toolbox]  documentation for the Octave implementation (not sure what code is used for computing results)
 
 * [http://www.siue.edu/~rkrauss/python_intro.html control.py]  Python Module for System Dynamics and Controls by Ryan Krauss  
 * [http://code.google.com/p/pycontrolsystems/ pycontrolsystems]  python library to study control systems by rhafao (not sure if this is still active)  
  
 == Activity Log ==
 
  
 This is a fairly sporatic account of things I worked on, mainly so I can document problems that I came up against.
 
  
 '''RMM: 10 Oct 09''': release 0.2 for people to play with
 
 * First cut implementation of transfer function operations, including composition and frequency domain plots
 
 * Working on state space representation, including conversion and mixed operations with transfer functions plus frequency domain plots. Only SISO operations for now, and things aren't very complete yet.
 
  
 '''RMM: 28 May 09''': release 0.1 as a demo
 
 * Updated to build off of signal.lti object structure (allows easy step responses)  
 * Put together an example + setup script, etc; available as [http://www.cds.caltech.edu/~murray/software/control0.1.tar.gz control0.1.tar.gz]
 
  
 '''RMM: 28 May 09''': preliminary SLICOT functionality working
 
 * Figured out enough about f2py to get the SLICOT function AB01MD working
 
 * Main issue was sorting out the intent macros; the SLICOT python wrapper example had most of the clues
 
 ** Use 'intent(in,out)' for variables that are both inputs and outputs
 
 ** Use 'depend' to automatically create various arguments that can be derived from matrix inputs (dimensions, etc)  
 * Solve dependencies by adding functions one at a time
 
  
 '''RMM: 27 May 09''': problems with SLICOT
 
 * Having trouble getting f2py working correctly on SLICOT. Errors in compilation
 
 * Backed up to getting a "hello world" example working. Finally got this to work after editing gnu.py in the numpy/distutils source to eliminate the cc_dynamic dependency (specifically enabled for darwin?)
 
 f2py2.5 h hello.pyf m hello *.f
 
 f2py2.5 c m hello *.f *.pyf
 
 * Might have issues with g77 versus gfortran (FORTRAN 90); will probably need to selectively include SLICOT modules and get things working slowly
 