%% Define Trajectory of Pedestrian
% Define the trajectory of a pedestrian who takes a sharp right turn at an
% intersection.

% Copyright 2020 The MathWorks, Inc.

%%
% Create a driving scenario. Add road segments that define an intersection.
scenario = drivingScenario;
roadCenters = [0 10; 0 -10];
road(scenario,roadCenters);
road(scenario,flip(roadCenters,2));

%%
% Add a pedestrian actor to the scenario.
pedestrian = actor(scenario, ...
    'ClassID',4, ...
    'Length',0.24, ...
    'Width',0.45, ...
    'Height',1.7, ...
    'Position',[-9 0 0], ...
    'RCSPattern',[-8 -8; -8 -8], ...
    'Mesh', driving.scenario.pedestrianMesh, ...
    'Name','Pedestrian');
 
%%
 % Define the trajectory of the pedestrian. The pedestrian approaches the
 % intersection, pauses briefly, and then take a sharp right turn at the
 % intersection. To define the sharp right turn, specify two waypoints at
 % the intersection that are close together. For these waypoints, specify
 % the yaw orientation angle of the second waypoint at a 90-degree angle
 % from the first waypoint.
waypoints = [-9 0; -0.25 0; 0 -0.25; 0 -9];
speed = [1.5; 0; 0.5; 1.5];
yaw =  [0; 0; -90; -90];
waittime = [0; 0.2; 0; 0];
trajectory(pedestrian,waypoints,speed,waittime,'Yaw', yaw);

%%
% Plot the driving scenario and display the waypoints of the pedestrian.
plot(scenario,'Waypoints','on')
while advance(scenario)
    pause(0.001)
end
