%% Simulate Car Backing into Parking Space
% Simulate a driving scenario in which a car drives in reverse to back into
% a parking space.

% Copyright 2020 The MathWorks, Inc.

%%
% Create a driving scenario containing a parking lot.
scenario = drivingScenario;
vertices = [0 9; 18 9; 18 -9; 0 -9];
parkingLot(scenario,vertices,ParkingSpace=parkingSpace);

%%
% Create a car and define its trajectory. The car drives forward, stops,
% and then drives in reverse to back into the parking space. As the car
% enters the parking space, it has a yaw orientation angle that is 90
% degrees counterclockwise from where it started.
car = vehicle(scenario,ClassID=1);
waypoints = [9 -5; 9 5; 6 -1.3; 2 -1.3];
speed = [3; 0; -2; 0];
yaw = [90 90 180 180];
smoothTrajectory(car,waypoints,speed,Yaw=yaw)

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