%% Create Trajectory with Varying Speeds

% Copyright 2020 The MathWorks, Inc.

%%
% Create a driving scenario containing a curved two-lane road.
scenario = drivingScenario('SampleTime',0.05);
roadcenters = [0 0; 24.2 27.7; 50 30];
lspec = lanespec(2);
road(scenario,roadcenters,'Lanes',lspec);

%%
% Add a vehicle to the scenario. Set a trajectory in which the vehicle
% slows down as it enters the curve.
v = vehicle(scenario,'ClassID',1);
waypoints = [2.6 1.0; 23.6 24.9; 45.5 28.6];
speed = [9 8 9];
smoothTrajectory(v,waypoints,speed)

%%
% Plot the scenario and run the simulation.
plot(scenario,'Waypoints','on','RoadCenters','on')
while advance(scenario)
    pause(scenario.SampleTime)
end