Skip to content

Commit 25729d3

Browse files
authored
Merge pull request #1 from python-control/master
Actualización del upstream
2 parents 58c7f85 + 7b07af3 commit 25729d3

44 files changed

Lines changed: 11459 additions & 1871 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ build.log
1212
.coverage
1313
doc/_build
1414
doc/generated
15+
examples/.ipynb_checkpoints/
16+
.settings/org.eclipse.core.resources.prefs
17+
.pydevproject
18+
.project
19+
Untitled*.ipynb
20+
*.idea/

.travis.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
sudo: false
12
language: python
3+
4+
cache:
5+
apt: true
6+
pip: true
7+
directories:
8+
- $HOME/.cache/pip
9+
- $HOME/.local
10+
211
python:
312
- "2.7"
413
- "3.3"
@@ -10,9 +19,9 @@ before_install:
1019
- sh -e /etc/init.d/xvfb start
1120
# use miniconda to install numpy/scipy, to avoid lengthy build from source
1221
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
13-
wget http://repo.continuum.io/miniconda/Miniconda-3.4.2-Linux-x86_64.sh -O miniconda.sh;
22+
wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
1423
else
15-
wget http://repo.continuum.io/miniconda/Miniconda3-3.4.2-Linux-x86_64.sh -O miniconda.sh;
24+
wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
1625
fi
1726
- bash miniconda.sh -b -p $HOME/miniconda
1827
- export PATH="$HOME/miniconda/bin:$PATH"
@@ -25,9 +34,9 @@ before_install:
2534

2635
# Install packages
2736
install:
37+
- conda install slycot
2838
- conda build conda-recipe
2939
- conda install control --use-local
30-
- conda install slycot
3140
- pip install coveralls
3241

3342
# command to run tests

LICENSE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) 2009-2016 by California Institute of Technology
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions
6+
are met:
7+
8+
1. Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder(s) nor the names of its
16+
contributors may be used to endorse or promote products derived
17+
from this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23+
COPYRIGHT HOLDERS OR THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30+
OF THE POSSIBILITY OF SUCH DAMAGE.

README.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,24 @@ correctly. After installation, run::
8787

8888
python setup.py test
8989

90+
License
91+
-------
92+
93+
This is free software released under the terms of `the BSD 3-Clause
94+
License <http://opensource.org/licenses/BSD-3-Clause>`_. There is no
95+
warranty; not even for merchantability or fitness for a particular
96+
purpose. Consult LICENSE for copying conditions.
97+
98+
When code is modified or re-distributed, the LICENSE file should
99+
accompany the code or any subset of it, however small. As an
100+
alternative, the LICENSE text can be copied within files, if so
101+
desired.
102+
90103
Contributing
91104
------------
92105

93106
Your contributions are welcome! Simply fork the GitHub repository and send a
94107
`pull request`_.
95108

96109
.. _pull request: https://github.com/python-control/python-control/pulls
110+

control/__init__.py

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,26 @@
4545
"""
4646

4747
# Import functions from within the control system library
48-
# Should probably only import the exact functions we use...
49-
from .bdalg import series, parallel, negate, feedback
50-
from .delay import pade
51-
from .dtime import sample_system
52-
from .freqplot import bode_plot, nyquist_plot, gangof4_plot
53-
from .freqplot import bode, nyquist, gangof4
54-
from .lti import issiso, timebase, timebaseEqual, isdtime, isctime
55-
from .margins import stability_margins, phase_crossover_frequencies
56-
from .mateqn import lyap, dlyap, care, dare
57-
from .modelsimp import hsvd, modred, balred, era, markov, minreal
58-
from .nichols import nichols_plot, nichols
59-
from .phaseplot import phase_plot, box_grid
60-
from .pzmap import pzmap
61-
from .rlocus import root_locus
62-
from .statefbk import place, lqr, ctrb, obsv, gram, acker
63-
from .statesp import StateSpace
64-
from .timeresp import forced_response, initial_response, step_response, \
65-
impulse_response
66-
from .xferfcn import TransferFunction
48+
# Note: the functions we use are specified as __all__ variables in the modules
49+
from .bdalg import *
50+
from .delay import *
51+
from .dtime import *
52+
from .freqplot import *
53+
from .lti import *
54+
from .margins import *
55+
from .mateqn import *
56+
from .modelsimp import *
57+
from .nichols import *
58+
from .phaseplot import *
59+
from .pzmap import *
60+
from .rlocus import *
61+
from .statefbk import *
62+
from .statesp import *
63+
from .timeresp import *
64+
from .xferfcn import *
6765
from .ctrlutil import *
68-
from .frdata import FRD
69-
from .canonical import canonical_form, reachable_form
66+
from .frdata import *
67+
from .canonical import *
7068

7169
# Exceptions
7270
from .exception import *
@@ -77,22 +75,6 @@
7775
except ImportError:
7876
__version__ = "dev"
7977

80-
# Import some of the more common (and benign) MATLAB shortcuts
81-
# By default, don't import conflicting commands here
82-
#! TODO (RMM, 4 Nov 2012): remove MATLAB dependencies from __init__.py
83-
#!
84-
#! Eventually, all functionality should be in modules *other* than matlab.
85-
#! This will allow inclusion of the matlab module to set up a different set
86-
#! of defaults from the main package. At that point, the matlab module will
87-
#! allow provide compatibility with MATLAB but no package functionality.
88-
#!
89-
from .matlab import ss, tf, ss2tf, tf2ss, drss
90-
from .matlab import pole, zero, evalfr, freqresp, dcgain
91-
from .matlab import nichols, rlocus, margin
92-
# bode and nyquist come directly from freqplot.py
93-
from .matlab import step, impulse, initial, lsim
94-
from .matlab import ssdata, tfdata
95-
9678
# The following is to use Numpy's testing framework
9779
# Tests go under directory tests/, benchmarks under directory benchmarks/
9880
from numpy.testing import Tester

control/bdalg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
from . import statesp as ss
5959
from . import frdata as frd
6060

61+
__all__ = ['series', 'parallel', 'negate', 'feedback', 'append', 'connect']
62+
6163
def series(sys1, sys2):
6264
"""Return the series connection sys2 * sys1 for --> sys1 --> sys2 -->.
6365

control/canonical.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from numpy import zeros, shape, poly
1010
from numpy.linalg import inv
1111

12+
__all__ = ['canonical_form', 'reachable_form']
1213

1314
def canonical_form(xsys, form='reachable'):
1415
"""Convert a system into canonical form

control/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
bode_dB = False # Bode plot magnitude units
1212
bode_deg = True # Bode Plot phase units
1313
bode_Hz = False # Bode plot frequency units
14+
bode_number_of_samples = None # Bode plot number of samples
15+
bode_feature_periphery_decade = 1.0 # Bode plot feature periphery in decades
1416

1517
# Set defaults to match MATLAB
1618
def use_matlab_defaults():

control/delay.py

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
# -*-coding: utf-8-*-
12
#! TODO: add module docstring
23
# delay.py - functions involving time delays
34
#
45
# Author: Sawyer Fuller
56
# Date: 26 Aug 2010
6-
#
7+
#
78
# This file contains functions for implementing time delays (currently
89
# only the pade() function).
910
#
@@ -16,16 +17,16 @@
1617
#
1718
# 1. Redistributions of source code must retain the above copyright
1819
# notice, this list of conditions and the following disclaimer.
19-
#
20+
#
2021
# 2. Redistributions in binary form must reproduce the above copyright
2122
# notice, this list of conditions and the following disclaimer in the
2223
# documentation and/or other materials provided with the distribution.
23-
#
24+
#
2425
# 3. Neither the name of the California Institute of Technology nor
2526
# the names of its contributors may be used to endorse or promote
2627
# products derived from this software without specific prior
2728
# written permission.
28-
#
29+
#
2930
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3031
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3132
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
@@ -38,48 +39,76 @@
3839
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3940
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4041
# SUCH DAMAGE.
41-
#
42+
#
4243
# $Id$
4344

44-
# Python 3 compatability (needs to go here)
45-
from __future__ import print_function
45+
from __future__ import division
46+
47+
__all__ = ['pade']
4648

47-
def pade(T, n=1):
48-
"""
49+
def pade(T, n=1, numdeg=None):
50+
"""
4951
Create a linear system that approximates a delay.
50-
52+
5153
Return the numerator and denominator coefficients of the Pade approximation.
52-
54+
5355
Parameters
5456
----------
5557
T : number
5658
time delay
57-
n : integer
58-
order of approximation
59-
59+
n : positive integer
60+
degree of denominator of approximation
61+
numdeg: integer, or None (the default)
62+
If None, numerator degree equals denominator degree
63+
If >= 0, specifies degree of numerator
64+
If < 0, numerator degree is n+numdeg
65+
6066
Returns
61-
-------
67+
-------
6268
num, den : array
6369
Polynomial coefficients of the delay model, in descending powers of s.
64-
70+
6571
Notes
6672
-----
67-
Based on an algorithm in Golub and van Loan, "Matrix Computation" 3rd.
68-
Ed. pp. 572-574.
73+
Based on:
74+
1. Algorithm 11.3.1 in Golub and van Loan, "Matrix Computation" 3rd.
75+
Ed. pp. 572-574
76+
2. M. Vajta, "Some remarks on Padé-approximations",
77+
3rd TEMPUS-INTCOM Symposium
6978
"""
79+
if numdeg is None:
80+
numdeg = n
81+
elif numdeg < 0:
82+
numdeg += n
83+
84+
if not T >= 0:
85+
raise ValueError("require T >= 0")
86+
if not n >= 0:
87+
raise ValueError("require n >= 0")
88+
if not (0 <= numdeg <= n):
89+
raise ValueError("require 0 <= numdeg <= n")
90+
7091
if T == 0:
7192
num = [1,]
7293
den = [1,]
7394
else:
74-
num = [0. for i in range(n+1)]
95+
num = [0. for i in range(numdeg+1)]
7596
num[-1] = 1.
97+
cn = 1.
98+
for k in range(1, numdeg+1):
99+
# derived from Gloub and van Loan eq. for Dpq(z) on p. 572
100+
# this accumulative style follows Alg 11.3.1
101+
cn *= -T * (numdeg - k + 1)/(numdeg + n - k + 1)/k
102+
num[numdeg-k] = cn
103+
76104
den = [0. for i in range(n+1)]
77105
den[-1] = 1.
78-
c = 1.
106+
cd = 1.
79107
for k in range(1, n+1):
80-
c = T * c * (n - k + 1)/(2 * n - k + 1)/k
81-
num[n - k] = c * (-1)**k
82-
den[n - k] = c
108+
# see cn above
109+
cd *= T * (n - k + 1)/(numdeg + n - k + 1)/k
110+
den[n-k] = cd
111+
83112
num = [coeff/den[0] for coeff in num]
84113
den = [coeff/den[0] for coeff in den]
85-
return num, den
114+
return num, den

control/dtime.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
"""
4848

4949
from .lti import isctime
50+
from .statesp import StateSpace, _convertToStateSpace
51+
52+
__all__ = ['sample_system', 'c2d']
5053

5154
# Sample a continuous time system
5255
def sample_system(sysc, Ts, method='zoh', alpha=None):
@@ -85,3 +88,30 @@ def sample_system(sysc, Ts, method='zoh', alpha=None):
8588
raise ValueError("First argument must be continuous time system")
8689

8790
return sysc.sample(Ts, method, alpha)
91+
92+
93+
def c2d(sysc, Ts, method='zoh'):
94+
'''
95+
Return a discrete-time system
96+
97+
Parameters
98+
----------
99+
sysc: LTI (StateSpace or TransferFunction), continuous
100+
System to be converted
101+
102+
Ts: number
103+
Sample time for the conversion
104+
105+
method: string, optional
106+
Method to be applied,
107+
'zoh' Zero-order hold on the inputs (default)
108+
'foh' First-order hold, currently not implemented
109+
'impulse' Impulse-invariant discretization, currently not implemented
110+
'tustin' Bilinear (Tustin) approximation, only SISO
111+
'matched' Matched pole-zero method, only SISO
112+
'''
113+
# Call the sample_system() function to do the work
114+
sysd = sample_system(sysc, Ts, method)
115+
if isinstance(sysc, StateSpace) and not isinstance(sysd, StateSpace):
116+
return _convertToStateSpace(sysd)
117+
return sysd

0 commit comments

Comments
 (0)