% cruise_linsim.m - simulation of linear model with PI control
% kja 060727

aminit;
cruise_lin               %Get parameters of linear model

z0=1;w0=0.5;tmax=15;
t=0:0.1:tmax;

%Sweep over parameter bsp
for bp=[0 0.5 1],
  %Compute controller parameters
  k=(a+2*z0*w0)/b;
  ki=w0^2/b;

  %Compute v and throttle u
  den=[1 2*z0*w0 w0^2];
  v=step([bp*b*k b*ki],den,t);
  u=step(conv([bp*k ki],[1 -a]),den,t);

  %Plot
  subplot(321); hold on
  plot(t, v_e + v, 'b', 'Linewidth', AM_data_linewidth);

  subplot(323); hold on;
  plot(t, u_e + u, 'b','Linewidth', AM_data_linewidth);
end

subplot(321)
amaxis([0 tmax v_e v_e+1.3]); box on;
ylabel('v');
arcarrow([3.6, v_e+0.3], [0.4 v_e+0.8], 10, 0.5);
amtext(4.25, v_e+0.3, 'b');

subplot(323)
amaxis([0 tmax 0 u_e+0.8]); box on;
xlabel('t');
ylabel('throttle');
arcarrow([2.0 u_e+0.3], [0.7 u_e-0.03], 20);
amtext(2.4, u_e+0.325, 'b');

amprint('cruise-spweight-step.eps');
