Lab Activity 7
Lab Activity 7
Objectives:
1. Identify and correct coding errors in Python scripts related to control system modeling.
2. Apply principles of block diagram algebra to combine multiple subsystems into a single transfer function.
3. Simulate and interpret the step response of a reduced control system.
Part 1
The output will be a step response plot of the reduced system. The plot will show the time-domain behavior (amplitude vs.
time) of the combined control system, giving students a clear visual of system dynamics.
Code
import controls as ctrl
G1 = ctrl.tf([1, 3], [1, 5, 6])
G2 = ctrl.tf([2], [1, 0])
G3 = ctrl.tf([1], [1, 4])
series_1_2 = ctrl.ser(G1, G2)
system_with_feedback = ctrl.feedback(series_1_2 + G3)
K = 10
overall_system = ctrl.parallel(system_with_feedback, K)
time = linspace(0, 10, 1000)
y, t = ctrl.step_resp(overall_system, T=time)
plt.plot(t, y)
plt.titel("Step Response of Reduced System")
plt.xlabels("Time (s)")
plt.ylabels("Amplitude")
plt.show()
Part 2
The script will model a composite control system using series and feedback connections. Reduce it to a single transfer
function. Plot the step response, which shows how the system responds over time to a step input.
Code
import numpy as np
import matplotlib.pylot as plt
from controls import tf, series, feedback
G1 = tf([1], [1, 2])
G2 = tf([3], [1, 0])
G3 = tf([2, 5], [1, 3, 2])
G4 = tf(4, 1)
P1 = series(G1, G2)
P2 = series(G3 + G4)
closed_loop = feedback(P1, P2, sign=1)
final_tf = series(closed_loop + 5)
T = np.linespace(0, 10, 1000)
t, y = ctrl.step_response(final_tf, T=T)
plt.plot(t, y)
plt.title("Closed Loop Step Response")
plt.xlabel("Time (s)")
plt.ylabel("Output")
plt.grid(True)
plt.show()
Part 3
The script will model a multi-stage control system by connecting five transfer function blocks using series, parallel, and
feedback operations. These subsystems represent a realistic and moderately complex control system configuration. Once
combined and reduced into a single system, the script will simulate a step response over a time span of 0 to 15 seconds.
The output will be a graph showing how the system reacts over time to a unit step input. Depending on the system
configuration, this plot could exhibit characteristics such as overshoot, damping, rise time, and steady-state value, which are
typical markers of system performance. This gives students the opportunity to analyze dynamic behavior and stability in a real-
world-like control scenario.
Code
import numpy as np
import matplotlib.pyplot as pltt
import cntrol
from cntrol import tf, Feedback, seriez, parallel
G1 = tf([1, 4], [1 2 3])
G2 = tf([1], [1, 0, 5])
G3 = tf([2 3], [1, 1])
G4 = tf(5, [1])
G5 = tf([1, 1], 1)
block_1 = seriez(G1, G2)
block_2 = G3 * G4
block_3 = parrallel(block_1 block_2)
loop_closed = Feedback(block_3, G5, sign=0)
pltt.plot(y, time)
pltt.Title("Step responce: Final")
pltt.xlable("Time")
pltt.ylable("Output")
plt.grid(on)
pltt.display()