function exampleHelperPlayBackInDS(egoPoses)
%exampleHelperPlayBackInDS A helper function used to visualize
% the navigation DS

% Inputs
%    -egoPoses:
%       Logged egoPoses from the Optimal Trajectory generation for urban Driving example

% This is a helper script for example purposes and may be removed or
% modified in the future.

% Copyright 2019 The MathWorks, Inc.

%% plots the ego vehicle navigation by advancing the simulation. 
% Gets the scenario and egoActor information from the urbanScenario
% function
[ds, egoActor] =  exampleHelperUrbanScenario();

% Initializes the figure and gets the axes to plot the chase plot and
% scenario plot in the same window.
hFigure = figure('units','normalized','outerposition',[0 0 1 1]);
hPanel1 = uipanel(hFigure,'Units','Normalized','Position',[0 0 1/2 1],...
    'Title','scenario Plot');
hPanel2 = uipanel(hFigure,'Units','Normalized','Position',[1/2 0 1/2 1],...
    'Title','Chase plot');
hAxes1 = axes('Parent',hPanel1);
hAxes2 = axes('Parent',hPanel2);

% plot the chase plot
chasePlot(egoActor,'Parent',hAxes2);

% plot the driving scenario.
plot(ds, 'Parent', hAxes1);

% Advance the simulation and plots, so that the ego actor navigates 
% in the scenario
while(advance(ds))
    [~, idx] = min(abs((egoPoses(:,4)) - ds.SimulationTime));
    egoActor.Position = [egoPoses(idx,1) egoPoses(idx,2) 0];
    egoActor.Yaw = rad2deg(egoPoses(idx,3));
end
end