% Code to plot simulation results from sdl_braking_caliper_disk_brake
%% Plot Description:
%
% This script shows how to generate the compliance or piston volume-pressure curve 
% for a caliper disk  brake which is parameterized to meet the capacity of a selected
% commerical tandem master cylinder. 
%

% Copyright 2019 The MathWorks, Inc.

%% Parameterize the model

sdl_braking_caliper_disk_brake_input;

%% Create figure for the results
if ~exist('h_sdl_braking_caliper_disk_brake', 'var')||...
        ~isgraphics(h_sdl_braking_caliper_disk_brake, 'figure') 
    h_sdl_braking_caliper_disk_brake = figure('Name', 'h_sdl_braking_caliper_disk_brake');
end

clf(h_sdl_braking_caliper_disk_brake);

%% Load the model and simulate to generate brake curve 

sim('sdl_braking_caliper_disk_brake.slx',simT)

% Plotting output from Simscape(TM) caliper disk brake model 

I1=subplot(2,1,1);
plot(1e9*(simlog_sdl_braking_caliper_disk_brake.FCDB.FLW.CP.chosen_converter.volume.series.values+...
    simlog_sdl_braking_caliper_disk_brake.FCDB.FLW.CP1.chosen_converter.volume.series.values-2*fcdb.deadV),...
    simlog_sdl_braking_caliper_disk_brake.FCDB.FLW.CP.chosen_converter.pressure_chamber.series.values,':',...
    1e9*(simlog_sdl_braking_caliper_disk_brake.FCDB.FRW.CP.chosen_converter.volume.series.values+...
    simlog_sdl_braking_caliper_disk_brake.FCDB.FRW.CP1.chosen_converter.volume.series.values-2*fcdb.deadV),...
    simlog_sdl_braking_caliper_disk_brake.FCDB.FRW.CP.chosen_converter.pressure_chamber.series.values,'--')
I2=xlabel('Swept volume (mm^3)');
I3=ylabel('Piston pressure (Pa)');
I4=title('Front caliper disk brake compliance curve');
I5=legend('Front left brake','Front right brake','location','best');
I1.Children(1).LineWidth=2;
I1.Children(2).LineWidth=2;
I2.FontSize=10;
I3.FontSize=10;
I4.FontSize=10;
I5.FontSize=10;
grid on

p5=subplot(2,1,2);
plot(1e9*(simlog_sdl_braking_caliper_disk_brake.FCDB.RLW.CP.chosen_converter.volume.series.values+...
    simlog_sdl_braking_caliper_disk_brake.FCDB.RLW.CP1.chosen_converter.volume.series.values-2*fcdb.deadV),...
    simlog_sdl_braking_caliper_disk_brake.FCDB.RLW.CP.chosen_converter.pressure_chamber.series.values,':',...
    1e9*(simlog_sdl_braking_caliper_disk_brake.FCDB.RRW.CP.chosen_converter.volume.series.values+...
    simlog_sdl_braking_caliper_disk_brake.FCDB.RRW.CP1.chosen_converter.volume.series.values-2*fcdb.deadV),...
    simlog_sdl_braking_caliper_disk_brake.FCDB.RRW.CP.chosen_converter.pressure_chamber.series.values,'--')
p6=legend('Rear left brake','Rear right brake','location','best');
grid on
p7=xlabel('Swept volume (mm^3)');
p8=ylabel('Piston pressure (Pa)');
p9=title('Rear caliper disk brake compliance curve');
p5.Children(1).LineWidth=2;
p5.Children(2).LineWidth=2;
p6.FontSize=10;
p7.FontSize=10;
p8.FontSize=10;
p9.FontSize=10;

clear I1 I2 I3 I4 I5 p5 p6 p7 p8 p9


