Skip to content
Prev Previous commit
Next Next commit
Updated for Python 3
  • Loading branch information
billtubbs committed May 19, 2019
commit bac4d87cf0883ef0740195fa99fde891fd47bfb2
10 changes: 7 additions & 3 deletions examples/secord-matlab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# secord.py - demonstrate some standard MATLAB commands
# secord.py - demonstrate some standard MATLAB commands
# RMM, 25 May 09

from matplotlib.pyplot import * # Grab MATLAB plotting functions
Expand All @@ -13,21 +13,25 @@
A = [[0, 1.], [-k/m, -b/m]]
B = [[0], [1/m]]
C = [[1., 0]]
sys = ss(A, B, C, 0);
sys = ss(A, B, C, 0)

# Step response for the system
figure(1)
yout, T = step(sys)
plot(T.T, yout.T)
show()

# Bode plot for the system
figure(2)
mag,phase,om = bode(sys, logspace(-2, 2),Plot=True)
mag, phase, om = bode(sys, logspace(-2, 2), Plot=True)
show()

# Nyquist plot for the system
figure(3)
nyquist(sys, logspace(-2, 2))
show()

# Root lcous plut for the system
figure(4)
rlocus(sys)
show()
20 changes: 11 additions & 9 deletions examples/type2_type3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from matplotlib.pyplot import * # Grab MATLAB plotting functions
from control.matlab import * # MATLAB-like functions
from scipy import pi
integrator = tf( [0, 1], [1, 0] ) # 1/s
integrator = tf([0, 1], [1, 0]) # 1/s

# Parameters defining the system
J = 1.0
Expand All @@ -28,16 +28,18 @@

# System Transfer Functions
# tricky because the disturbance (base motion) is coupled in by friction
closed_loop_type2 = feedback(C_type2*feedback(P,friction),gyro)
disturbance_rejection_type2 = P*friction/(1.+P*friction+P*C_type2)
closed_loop_type3 = feedback(C_type3*feedback(P,friction),gyro)
disturbance_rejection_type3 = P*friction/(1.+P*friction+P*C_type3)
closed_loop_type2 = feedback(C_type2*feedback(P, friction), gyro)
disturbance_rejection_type2 = P*friction/(1. + P*friction+P*C_type2)
closed_loop_type3 = feedback(C_type3*feedback(P, friction), gyro)
disturbance_rejection_type3 = P*friction/(1. + P*friction + P*C_type3)

# Bode plot for the system
figure(1)
bode(closed_loop_type2, logspace(0,2)*2*pi, dB=True, Hz=True) # blue
bode(closed_loop_type3, logspace(0,2)*2*pi, dB=True, Hz=True) # green
bode(closed_loop_type2, logspace(0, 2)*2*pi, dB=True, Hz=True) # blue
bode(closed_loop_type3, logspace(0, 2)*2*pi, dB=True, Hz=True) # green
show()

figure(2)
bode(disturbance_rejection_type2, logspace(0,2)*2*pi, Hz=True) # blue
bode(disturbance_rejection_type3, logspace(0,2)*2*pi, Hz=True) # green
bode(disturbance_rejection_type2, logspace(0, 2)*2*pi, Hz=True) # blue
bode(disturbance_rejection_type3, logspace(0, 2)*2*pi, Hz=True) # green
show()