%EX_4_12 simulates the performance of the boundary layer controller
%connected to the vehicle model.  The script
%uses the VEH_BLA55 file

%   last modified by S. H. Zak on November 20, 2002

clear
clc
tspan=[0 4];
x_0=[0 0 0 0 0 0 0 0]';
[t,x]=ode23s('VEH_BLA5',tspan,x_0);
subplot(2,1,1)
plot(t,x(:,4))
axis([0 4 0 5])
set(gca,'Fontsize',12)
grid
xlabel('Time (sec)','Fontsize',12)
title('Actual output in Example 4.12.','Fontsize',12)
hold on
plot(t,4*(t>=1))
subplot(2,1,2)
plot(t,x(:,8))
axis([0 4 0 5])
set(gca,'Fontsize',12)
grid
xlabel('Time (sec)','Fontsize',12)
title('Desired output in Example 4.12.','Fontsize',12)
hold on
plot(t,4*(t>=1))
eta=-0.1653;
a=.5;
r=4*(t>=1);
rho=abs(0.0329*x(:,1)+2.2854*x(:,2)+0.2429*x(:,3)-0.1653*x(:,4))+abs(r*eta);
f=0.1571*(x(:,1)-x(:,5))+26.9931*(x(:,2)-x(:,6))+6.3324*(x(:,3)-x(:,7))-3.025*(x(:,4)-x(:,8));
u=-rho*(1/(2*a)).*(abs(f+a)-abs(f-a));
figure
plot(t,u)
set(gca,'Fontsize',12)
grid
xlabel('Time (sec)','Fontsize',12)
ylabel('{\it u}','Fontsize',12)
title('Controller action in Example 4.12.','Fontsize',12)
figure
par=-3:0.001:3;
sat='(1/(2*a))*(abs(par+a)-abs(par-a))';
plot(par,eval(sat))
axis([-3 3 -1.5 1.5])
grid
set(gca,'Fontsize',12)
xlabel('{\it x}','Fontsize',12)
title('Graph of the linear saturating function used in the controller construction.','Fontsize',12)