%% Engine Timing With Closed Loop Control 
% 
% This demonstration shows how to use Triggered Subsystems to model engine 
% timing, including a feedback controller. Different subsystems in the diagram 
% model the mathematical representation of various automotive systems, including 
% the following:
% 
% * Throttle & Manifold 
% * Compression 
% * Combustion 
% * Vehicle Dynamics 
% * Valve Timing 
% * Controller 
% 
% The valve timing subsystem generates a signal that triggers the Controller and 
% Compression subsystems twice per revolution of the crank (calculated from the 
% crank speed.) A speed set point (in rpm) from the Step block drives the simulation. 
% The controller calculates the necessary throttle angle based on the desired rpm 
% and the crank speed that is calculated by the vehicle dynamics. After you run 
% the simulation, the Scopes show the engine speed and the throttle angle 
% compared to the load torque. 
% 
% A detailed review of the equations used in this design can be found in 
% the white paper <http://www.mathworks.com/mason/tag/proxy.html?dataid=229&fileid=559 
% Using Simulink and Stateflow for Automotive Examples.> Please note
% that this paper is based on an older version of Simulink and does not 
% use all the newest block diagramming features in the current version 
% of Simulink.

bdclose all


close all


open_system('sldemo_enginewc')
sim('sldemo_enginewc')

%% 

bdclose all


close all
