function [A,B,C,D] = pfcblock_utilGetDTModelHasLagForMPCNoSpacingCtrl(Ts,Vx,Ag,Bg,Cg,lag)
%#codegen
%
% Get discrete state-space model for Adaptive MPC. Called by the "Path
% Following Control System" Block. This function is called when "Spacing
% control" is disabled.

% Inputs:
%   Ts:                mask variable for sample time
%   Vx:                mask inport for longitudinal velocity
%   Ag,Bg,Cg:          continuous vehicle model
%   lag:               lumped lag in the model

% Outputs:
%   A,B,C,D:           discrete time model for MPC

%   Author: Meng Xia, Rong Chen
%   Copyright 2017-2021 The MathWorks, Inc.


%% Augment vehicle model to MPC model (lag free)
NumEgoStates = size(Bg,1); % number of states in vehicle model
[As,Bs,Cs,Ds] = pfcblock_utilAugmentVehicleMdlNoSpacingCtrl(Ag,Bg,Cg,Vx);
%% Add lag dynamics (Gz: 3*3 model)
% lag dynamics Gl
Al = -1/lag*eye(3);
Bl = 1/lag*eye(3);
Cl = eye(3);
Dl = zeros(3);
Az = [As,zeros(NumEgoStates+2,3);Bl*Cs,Al];
Bz = [Bs;Bl*Ds];
Cz = [Dl*Cs,Cl];
Dz = Dl*Ds;
%% Discretize model with sample time Ts
[A, B] = adasblocks_utilDicretizeModel(Az, Bz, Ts);
C = Cz;
D = Dz;
