%% Speed Cruise Control System Using Simulink(R) and Stateflow(R)
% 
%   Copyright 2007-2013 The MathWorks, Inc.
%
% This model shows the code generated for a Cruise Control
% Controller subsystem. Simulate the model. Click on the scope to observe "Target" and "Actual" speed. 

mdl = 'plcdemo_cruise_control';
evalc('open_system(mdl)');
evalc('sim(mdl)');

%%
% Open up the "Controller" subsystem. Notice that this model uses a Triggered Stateflow(R) Chart
% to do the "Enable" and "Setpoint" calculation. It uses a discrete PID Controller to compute the
% "Throttle Command".  
open_system('plcdemo_cruise_control/Controller');

%%
% You can generate PLC Structured Text code for this subsystem by 
% right-clicking on the subsystem block and select 
% PLC Code -> Generate Code for Subsystem
% Alternatively, you can use the following command
% generatedFiles = plcgeneratecode('plcdemo_cruise_control/Controller');

%%
% After the code generation, the Diagnostic Viewer window 
% is displayed with hyperlinks to the generated code files.
% You can open the generated files by clicking on the links.
