% Code to plot simulation results for sscfluids_braking_ABS_open_loop
%% Plot Description:
%
% This script shows how to generate the ABS open loop response curves.

% Copyright 2019-2020 The MathWorks, Inc.

%% Parameterize the model

sscfluids_braking_ABS_open_loop_input;

%% Generate new simulation results if they don't exist or if they need to be updated
if ~exist('simlog_sscfluids_braking_ABS_open_loop', 'var') || ...
        pm_simlogNeedsUpdate(simlog_sscfluids_braking_ABS_open_loop)
    sim('sscfluids_braking_ABS_open_loop.slx',0.6)      % Simulating model
end
%% Create figure for the results
if ~exist('h_sscfluids_braking_ABS_open_loop', 'var') || ...
        ~isgraphics(h_sscfluids_braking_ABS_open_loop, 'figure')
    h_sscfluids_braking_ABS_open_loop = figure('Name', 'h_sscfluids_braking_ABS_open_loop');
end

clf(h_sscfluids_braking_ABS_open_loop);


%% Plotting output from Simscape(TM) ABS open loop test bench


p1 = plot(simlog_sscfluids_braking_ABS_open_loop.FCDB.RRW.CP.A.p.series.time,...
    simlog_sscfluids_braking_ABS_open_loop.FCDB.RRW.CP.A.p.series.values,...
    simlog_sscfluids_braking_ABS_open_loop.FCDB.RLW.CP.A.p.series.time,...
    simlog_sscfluids_braking_ABS_open_loop.FCDB.RLW.CP.A.p.series.values,...
    simlog_sscfluids_braking_ABS_open_loop.FCDB.FRW.CP.A.p.series.time,...
    simlog_sscfluids_braking_ABS_open_loop.FCDB.FRW.CP.A.p.series.values,...
    simlog_sscfluids_braking_ABS_open_loop.FCDB.FLW.CP.A.p.series.time,...
    simlog_sscfluids_braking_ABS_open_loop.FCDB.FLW.CP.A.p.series.values);

l1 = legend('Rear right wheel',...
    'Rear left wheel', ...
    'Front right wheel',...
    'Front left wheel');
l1.FontSize = 16;
title('ABS open loop test bench')

xx = xlabel('Time (s)');
yy = ylabel('Caliper disc brake pressure (Pa)');

xx.FontSize = 16;
yy.FontSize = 16;
grid on
p1(1).LineWidth = 1;
p1(2).LineWidth = 1;
p1(3).LineWidth = 1;
p1(4).LineWidth = 1;

% Clearing temporary variables
clear p1 l1 xx yy