% FILE: rootLocusNxtMotorWheel1_0b_021119.m
% DATE: 02/11/19 13:08
% AUTH: P.Oh
% DESC: Root Locus plot for the NXT Motor/Wheel with lag compensator
% VERS: 1.0a - Root Locus (uses System ID model)
%       1.0b - lag compensator (see nxtMotorNotes021119.pptx
% REFS: http://ctms.engin.umich.edu/CTMS/index.php?example=CruiseControl&section=ControlRootLocus
%       rootLocusNxtMotorWheel1_0a_020619.m
%       rootLocusIntuitive3_0a_012319a.m

% The plant transfer function resulting from 01/31/19 Matlab System ID 

%               64.31                                  9.2 * 6.998
%   Gp(s) = ------------ or more explicitly  Gp(s) = --------------- where kDC = 9.2
%             (s+6.998)                                 (s+6.998)


% Define Plant TF

gpTfNum = [64.31];
gpTfDen = [1 6.998];

gpTf = tf(gpTfNum, gpTfDen)

% Define (Lag) Compensator TF

%              (s+0.3)   
%   Gc(s) = ------------
%             (s+0.03) 

glagTfNum = [1 0.3];
glagTfDen = [1 0.03];

glagTf = tf(glagTfNum, glagTfDen);

gTf = glagTf * gpTf; % let gTf be the variable to use for TF we want plotted

handleRootLocusPlot = rlocusplot(gTf);
plotOptions = getoptions(handleRootLocusPlot);
plotOptions.Title.String = 'RL for NXT Motor/Wheel with Lag Compensation';
plotOptions.XLim = [-2 0];
plotOptions.YLim = [-0.2 0.2];
setoptions(handleRootLocusPlot, plotOptions);

% rlocfind allows one to use mouse to identify gains and poles
%[K, P] = rlocfind(gTf)
