%
%  closed loop driver-- examine the response of the plant by itself
%
%  put in the saturation limits for the ECP 210  or 205 systems
%
  saturation_level = 1000/2546; % ECP 205
  saturation_level = 1000/2196; % ECP 210 
%  
%  now load the plant model
%
  load state_model_1dof_205
% load state_model_1dof_model210
%
%  we want the output to be the two states
%
  C = eye(2,2);
%
%  convert to a Matlab state space (ss) model
%
  Hc = ss(A,B,C,D);
%
%  set the final time for the simulation
%
  Tf = 5.0;  % seconds
%  
%  set the amplitude and final time
%
%  Amp = 1 * (pi/180); %the input, in radians, for model 205 
  Amp = 0.1; % the input, in cm for model 210
%
%
%  set the sample interval
%
   Ts = 0.05;
   Tsr = 0.01;
%  
%  discretize the state space model using a zero order hold, then get
%  the state variable model back
%
  Hd = c2d(Hc,Ts,'zoh');
  [G,H,C,D] = ssdata(Hd);
  
  Hdr = c2d(Hc,Tsr,'zoh');
  [Gr,Hr,Cr,Dr] = ssdata(Hdr); 
%
%  now simulate the system
%
  sim('DT_openloop_ripple');
%
%  plot the results
%
  figure
  orient landscape % plot sideways
  subplot(2,1,1); plot(m_time,m_x,'d',m_timer,m_xr,'.'); legend('Slow','Fast'); grid; ylabel('Position (cm)');
  subplot(2,1,2); plot(m_time,m_x_dot,'d',m_timer,m_x_dotr,'.'); legend('Slow','Fast'); grid; ylabel('Velocity (cm/sec)');
    