% two_dof.m - illustration of controller with 2DOF
% KJA, 2012

aminit;					% initialize FBS macros

tstop = 10; t = 0:0.1:tstop;
wc = 1; zc = 0.707; a = 0; b = 1;
% wc = 1; zc = 0.5; a = 0.5;
kp = (2*zc*wc-a)/b;
ki = wc^2/b;
Str = {'b-', 'b--', 'b:'}; jjj = 1;

for beta = [0 0.5 1],
  Gyr = tf([kp*b*beta ki*b], [1 2*zc*wc wc^2]);
  y = step(Gyr, t);
  Gur = tf([conv([kp*beta ki], [1 a])], [1 2*zc*wc wc^2]);
  u = step(Gur, t);

  figure(1); subplot(321)
  str = Str{jjj}; jjj = jjj+1;
  pl = plot(t, y, str);
  set(pl,  'LineWidth',  AM_data_linewidth);
  amaxis([0 tstop 0 1.5]);
  hold on;

  figure(2); subplot(321)
  pl = plot(t, u, str);
  set(pl,  'LineWidth',  AM_data_linewidth);
  amaxis([0 tstop -0.2 1.5]);
  hold on;
end

figure(1)
subplot(321)
xlabel('t'); ylabel('y');
pl = line([0 tstop], [1 1]);
set(pl,  'LineWidth',  AM_ref_linewidth);
amprint('two-dof-y.eps')

figure(2)
subplot(321)
xlabel('t'); ylabel('u');
amprint('two-dof-u.eps')

