% Code to plot simulation results from sscfluids_power_steering
%% Plot Description:
%
% The plots below show the amount of assistance the power steering system
% provides to the driver as the wheel is turned.  The greater the
% difference in the cylinder chamber pressures, the more assistance that
% is provided.

% Copyright 2015-2017 The MathWorks, Inc.

% Generate simulation results if they don't exist
if ~exist('simlog_sscfluids_power_steering', 'var')
    sim('sscfluids_power_steering')
end

% Reuse figure if it exists, else create new figure
if ~exist('h1_sscfluids_power_steering', 'var') || ...
        ~isgraphics(h1_sscfluids_power_steering, 'figure')
    h1_sscfluids_power_steering = figure('Name', 'sscfluids_power_steering');
end
figure(h1_sscfluids_power_steering)
clf(h1_sscfluids_power_steering)

% Get simulation results
simlog_t = simlog_sscfluids_power_steering.Cylinder.A.p.series.time;
simlog_cylpA = simlog_sscfluids_power_steering.Cylinder.A.p.series.values('Pa');
simlog_cylpB = simlog_sscfluids_power_steering.Cylinder.B.p.series.values('Pa');
simlog_whlphi = simlog_sscfluids_power_steering.Steering_Angle.Motion_Sensor.phi.series.values('deg');

% Plot results
simlog_handles(1) = subplot(2, 1, 1);
plot(simlog_t, simlog_cylpA, 'LineWidth', 1)
hold on
plot(simlog_t, simlog_cylpB, 'LineWidth', 1)
hold off
grid on
title('Cylinder Pressure')
ylabel('Pressure (Pa)')
legend({'Side A','Side B'},'Location','Best');

simlog_handles(2) = subplot(2, 1, 2);
plot(simlog_t, simlog_whlphi, 'LineWidth', 1)
grid on
title('Steering Wheel Angle')
ylabel('Angle (deg)')
xlabel('Time (s)')

linkaxes(simlog_handles, 'x')

% Remove temporary variables
clear simlog_t simlog_cylpA simlog_cylpB simlog_whlphi simlog_handles
