%% Restart Driving Scenario Simulation
% Create a driving scenario in which a vehicle travels down a straight, 25-meter road at 20 meters per second. Plot the scenario.

scenario = drivingScenario('SampleTime',0.1);

roadcenters= [0 0 0; 25 0 0];
road(scenario,roadcenters)

v = vehicle(scenario,'ClassID',1);

waypoints = [5 0 0; 20 0 0];
speed = 20; % m/s
trajectory(v,waypoints,speed)

plot(scenario)

%
% Run the simulation and display the location of the vehicle at each time step.

while advance(scenario)
    fprintf('Vehicle location: %0.2f meters at t = %0.0f ms\n', ...
            v.Position(1), ...
            scenario.SimulationTime * 1000)
end

%
% Restart the simulation. Increase the sample time and rerun the simulation.

restart(scenario);
scenario.SampleTime = 0.2;

while advance(scenario)
    fprintf('Vehicle location: %0.2f meters at t = %0.0f ms\n', ...
            v.Position(1), ...
            scenario.SimulationTime * 1000)
end

%
% Copyright 2018 The MathWorks, Inc.