%% Plot Ackermann Drive Vehicle in Simulink
% This example shows how to plot the position of an Ackermann Kinematic Model block and change it's vehicle velocity and steering angular velocity in real-time.
% Open the Simulink model.

open_system("plotAckermannDriveSimulinkModel.slx");

%
%% Ackermann Kinematic Block
% The Ackermann Kinematic Model block parameters are the default values, but it is important to note two parameters for this example, the Vehicle speed range and Maximum steering angle. Both parameters limit the motion of the vehicle. The lower bound of the Vehicle speed range parameter is set to -inf and the upper bound is set to inf, so the vehicle velocity can be any real value you set. The Maximum steering angle is set to pi/4, so there's a max turning radius that the vehicle can achieve.
%
%% Vehicle and Steering Velocity
% The Ackermann Kinematic Model block takes two inputs, vehicle velocity and steering angular velocity. This model uses Slider Gain blocks to change the inputs.
%
% These values can be any real values within the parameter constraints set in the Ackermann Kinematic Model block.
%
%% Graphing the Output
% Using a demux block, the x and y signals of the state output connect to a XY Graph block. The signals of stateDot and the other two signals of state connect to Display blocks.
%
%
%% Run the Model
% Set the model run time to inf.
% Click Play to run the model. The graph will appear and you can see the path of the vehicle.
% Open the Slider Gain blocks and adjust the values of the blocks to see their affects on the path of the vehicle.
% Adjust the graph limits as needed.
% Observe the Steering Angle display as you adjust the value of the Steering Gain.
%
% Copyright 2019 The MathWorks, Inc.