%% Simulate Vehicle with Trajectory of Varying Speeds

% Copyright 2018 The MathWorks, Inc.

%%
% Create a driving scenario and add a curved two-lane road to it.
scenario = drivingScenario('SampleTime',0.05);
roadcenters = [5 0; 30 10; 35 25];
lspec = lanespec(2);
road(scenario,roadcenters,'Lanes',lspec);
%%
% Add a vehicle to the scenario. Set a trajectory in which the vehicle
% drives around the curve at varying speeds.
v = vehicle(scenario,'ClassID',1);
waypoints = [6 2; 18 4; 25 7; 28 10; 31 15; 33 22];
speeds = [30 10 5 5 10 30];
trajectory(v,waypoints,speeds)
%%
% Plot the scenario and run the simulation. Observe how the vehicle slows
% down as it drives along the curve.
plot(scenario,'Waypoints','on','RoadCenters','on')
while advance(scenario)
    pause(0.1)
end