Control Systems Library for Python

From Murray Wiki
Jump to navigationJump to search

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.

Status updates:

Architecture notes

I'm trying to sort out the best object structure to use for control system objects. There is already an LTI class in the signal processing module of SciPY, so I might be able to build on that (and hence get those systems for free). Ideally, I'd like to allow for time delay in the linear systems representation, since these come up a lot in my group's research.

Here's some rough thoughts on a possible object structure:

  • Option 1: build off of the 'signal.lti' object structure. This has the advantage of being compatible with existing 'signal' package functions. The signal.lti class currently represents systems simultaneously in transfer function, state space and "pzk" forms. Not may functions written for it yet, though.
  • Option 2: emulate the MATLAB systems structure. This uses separate classes for transfer functions, state space, "pzk" and frequency response data (frd) forms. There is also a state space format for delay systems, which seems quite useful.
  • Option 3: new structure that allows nonlinear computations and other general objects
    • One possibility here is to represent everything in the python-control library in state space and leave transfer functions for the signal library
    • Would like to do this in a way that keeps track of the state + dynamics + delays and then allow linear systems as a special case, with functions like 'trim', 'linmod', etc to determine linearizations
    • Composition, feedback, etc can work by creating composite functions corresponding to series, parallel, feedback interconnections (need to think about this)

Installation instructions

I'm using the IPython environment, with SciPy extensions for scientific computing plus the matplotlib extensions (which enables MATLAB-like plotting). I am doing all of my playing on OS X, using fink.


Here's what I had to do to get the basic setup that I am using.

  1. Install SciPy - I did this using fink. Have to use the main/unstable tree.
  2. Install matplotlib - Need this for plotting
  3. Install ipython - interactive python interface

Small snippet of code for testing if everything is installed

from scipy import *
from matlibplot import *
a = zeros(1000)
b = fft(a)
show()                 # Not needed if you use ipython -pylab


Standard python package installation:

 python install

To see if things are working, you can run the script (using ipython -pylab). It should generate a step repsonse, Bode plot and Nyquist plot for a simple second order linear system.


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


  • Properties: ctrb, obsv, pole, zero
  • Frequency plots: bode, nyquist, rlocus, pzmap
  • Simulations: iosim, lsim, step, impulse, initial
  • Margins: margin


  • Basic controllers: pid, lead, lag, leadlag
  • State space: place, lqr, kalman, estim, reg

Related documentation

Python documentation

  • - main web site for SciPy
  • PyRo - Python Robotics library (might be nice to be compatible with this

Related packages

  • SLICOT - Fortran 77 implementations of numerical algorithms for computations in systems and control theory
    • python wrapper - Numpy wrapper of the control and systems library SLICOT
    • python info - Message giving information on making SLICOT available in python
  • Octave Control Systems Toolbox - documentation for the Octave implementation (not sure what code is used for computing results)
  • - Python Module for System Dynamics and Controls by Ryan Krauss

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: 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 control-0.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 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