Page 576 - Mechatronics with Experiments
P. 576
JWST499-Cetinkunt
JWST499-c07
562 MECHATRONICS Printer: Yet to Come October 9, 2014 8:41 254mm×178mm
t_sample = 0.001 ;
z=zeros(8,1);
z(1) = p_p ;
z(2) = i_v ;
z(3) = x_v ;
z(4) = xdot_v ;
z(5) = p_a ;
z(6) = p_b ;
z(7) = y ;
z(8) = ydot ;
% y_out = [ Q_p Q_v Q_r p_p p_a p_b i_cmd x_v∗10ˆ3 y_d y ];
y_out = [ 0.0 0.0 0.0 p_p p_a p_b 0.0 0.0 0.2 0.2 ];
for (t=t_0: t_sample:t_f)
% Solve ODEs...
t_span=[t,t+t_sample] ;
i_cmd = EH_Servo_PID_Controller(t) ;
[T,z1] = ode45(‘EH_Servo_Dynamics’,t_span, z);
[m,n]=size(z1);
z(:)=[z1(m,:)] ;
t
y_out=[y_out ;
Q_p Q_v Q_r z(1) z(5) z(6) i_cmd z(3)∗100 y_d z(7) ];
end
[m,n]=size(y_out);
t_inc = (t_f-t_0)/m ;
tout=t_0:t_inc:t_f-t_inc;
tout = tout’ ;
figure(1) ;
subplot(2,2,1) ;
plot(tout, y_out(:,1), ‘k’,tout, y_out(:,2), ‘b’,tout, y_out(:,3), ‘m’);
xlabel(‘Time (sec)’) ; ylabel(‘Flow rate (mˆ3/sec)’) ;
legend(‘Q_p’,‘Q_v’, ‘Q_r’);
subplot(2,2,2) ;
plot(tout, y_out(:,4), ‘k’,tout, y_out(:,5), ‘b’,tout, y_out(:,6), ‘g’);
xlabel(‘Time (sec)’) ; ylabel(‘Pressure [Pa]’) ;
legend(‘p_p’,‘p_a’,‘p_b’);
subplot(2,2,3) ;
plot(tout, y_out(:,7), ‘k’,tout, y_out(:,8), ‘b’);
xlabel(‘Time (sec)’) ; ylabel(‘Valve currentcmd and spool position’) ;
legend(‘i_cmd’,‘x_v’);
subplot(2,2,4) ;
plot(tout, y_out(:,9), ‘k’,tout, y_out(:,10), ‘b’);
xlabel(‘Time (sec)’) ; ylabel(‘Cylinder position: cmd and mea.’) ;
legend(‘y_d’,‘y’);