%% Experiment 8.1
%% Name: Elise Heim
%% Objectives
% To verify the effect of open-loop poles and zeros upon the shape of the root locus. To verify the root locus as a tool for estimating the effect of open-loop gain upon the transient response of closed-loop systems.
%% Minimum Required Software Packages
% MATLAB, Simulink, and the Control System Toolbox.
%
%
%% Prelab
%% Problem 1
% Sketch two possibilities for the root locus of a unity negative-feedback system with the open-loop pole-zero configuration shown in Figure P8.21
%
% Answer:
%
%
%% Problem 2
% If the open-loop system of Prelab 1 is G(s) = \frac{K(s+1.5)}{s(s+0.5)(s+10)}, estimate the precent overshoot at the following values of gain, K: 20, 50, 85, 200, 700.
% Answer:
% 20:
% % OS = 18%
%
% 50:
% % OS = 20.4%
%
% 85:
% % OS = 25.9%
%
% 200:
% % OS = 39.3%
%
% 700:
% % OS = 59.7%
%
%
%
%
%
%% Lab
%
%% Problem 1
% Using MATLAB's SISO Design Tool, set up a negative unity feedback system with G(s) = \frac{K(s+6)}{s(s+0.5)(s+10)} to produce a root locus. For convenience, set up the zero at -6 using SISO Design Tool’s compensator function by simply dragging a zero to -6 on the resulting root locus. Print the root locus for the zero at -6. Move the zero to the following locations and print out a root locus at each location: -2, -1.5, -1.37, and -1.2.

nOG = tf([1 6], [1 10.5 6 6])
% sisotool(nOG)


n2 = tf([1 2], [1 10.5 6 2])
n15 = tf([1 1.5], [1 10.5 6 1.5])
n137 = tf([1 1.37], [1 10.5 6 1.37])
n12 = tf([1 1.2], [1 10.5 6 1.2])

% sisotool(n2);
% sisotool(n15);
% sisotool(n137);
% sisotool(n12);

% Original function:
%
%
% -2:
%
%
% -1.5:
%
%
% -1.37:
%
%
% -1.2:
%
%
%% Problem 2
% Using MATLAB's SISO Design Tool, set up a negative unity feedback system with G(s) = \frac{K(s+1.5)}{s(s+0.5)(s+10)} to produce a root locus. Open the LTI Viewer for SISO Design Tool to show step responses. Using the values of K specified in Prelab 2, record the percent overshoot and settling time and print the root loci and step response for each value of K.
% K: 20, 50, 85, 200, 700

n2OG = tf([1 1.5], [1 10.5 6 0])
n20 = tf([20 30], [1 10.5 25 30])
n50 = tf([50 75], [1 10.5 55 75])
n85 = tf([85 127.5], [1 10.5 90 127.5])
n200 = tf([200 300], [1 10.5 205 300])
n700 = tf([700 1050], [1 10.5 705 1050])

% 
% second = stepinfo(n20)
% third = stepinfo(n50)
% forth = stepinfo(n85)
% fifth = stepinfo(n200)
% sixth = stepinfo(n700)

sisotool(nOG);
% sisotool(n20);
% sisotool(n50);
% sisotool(n85);
% sisotool(n200);
% sisotool(n700);

% Original:
%
% 20:
% % OS = 18.4064
%
%
% 50:
% % OS = 20.3710
%
%
% 85:
% % OS = 25.9262
%
%
% 200:
% % OS = 39.3819
%
% 700:
% % OS = 59.7344
%
%
%
%
%% Postlab
%
%% Problem 1
% Discuss your findings from Prelab 1 and Lab 1. What conclusions can you draw?
% Lab 1 shows that the locations of the asymptotes in Pre-Lab 1 can be shown for different values of k with the help of Matlab.
%
%% Problem 2
% Make a table comparing percent overshoot and settling time from your calculations in Prelab 2 and your experimental values found in Lab 2. Discuss the reasons for any discrepancies. What conclustions can you draw?
%
%
% The calculated and experimental values of percent overshoot are very similar, which implies that there is not significant error.
%