%% Schedule Simulink Algorithms by Using Stateflow
% This model shows how you can schedule a Simulink(R) algorithm using
% Stateflow(R).

% Copyright 2009-2019 The MathWorks, Inc.

clear
close all
bdclose all

model = 'sf_slscheduler';

open_system(model);
r = sfroot;
m = r.find('-isa', 'Stateflow.Machine', 'Name', model);

c = m.find('-isa', 'Stateflow.Chart', 'Name', 'Chart');
c.Visible = 0;

% close all scopes
close_system(find_system(gcs, 'BlockType', 'Scope'));

%% 
% The Stateflow chart in this model consists of a Simulink algorithm which
% runs at different rates at different times in the simulation. Stateflow
% is ideally suited to designing the transition logic which determines when
% these rate transitions happen. The Simulink algorithm on the other hand
% is used for the actual data processing. The chart merely passes inputs
% and outputs to the Simulink subsystem. For the purposes of this example,
% the Simulink algorithm adds the input to the output each time the chart
% calls it.

c.Visible = 1;

%% 
% Upon running the simulation, we see the counter counting at varying
% rates:

evalc('sim(gcs)');
open_system('sf_slscheduler/Scope');

%% 

bdclose all;
clear
close all;
