function xprime=Cascade(t,X) 
global dyndata NI U tend
%Cascade controller

indmat


[D,e1] = Controller_PI(X(im_mt+NI),dyndata.x_nom(im_mt),dyndata.u_nom(12),X(1),1,1001,0,1);
[B,e2] = Controller_PI(X(im_mr+NI),dyndata.x_nom(im_mr),dyndata.u_nom(13),X(2),1,1001,0,1);

au=1;
% 

[RV,e3] = Controller_PI(X(im_T2(3)+NI),dyndata.x_nom(im_T2(3)),dyndata.u_nom(6),X(3),-0.014*au,80,0,1);
% 
[TTT,e7] = Controller_PI(X(im_xS1(2)+NI),dyndata.x_nom(im_xS1(2)),dyndata.x_nom(im_T7(2)),X(7),  19*au,40,dyndata.x_nom(im_T7(2))-20,dyndata.x_nom(im_T7(2))+20);
[S1,e4] = Controller_PI(X(im_T7(2)+NI),TTT,dyndata.u_nom(3),X(4),  -0.0054795*au,40,0,1);
 
[TTT,e8] = Controller_PI(X(im_xS2(3)+NI),dyndata.x_nom(im_xS2(3)),dyndata.x_nom(im_T6(2)),X(8),  ...
    40*au,100,dyndata.x_nom(im_T6(2))-20,dyndata.x_nom(im_T6(2))+20);
[S2,e5] = Controller_PI(X(im_T6(2)+NI),TTT,dyndata.u_nom(4),X(5), -0.0072308*au,47,0,1);


[TTT,e9] = Controller_PI(X(im_xt(1)+NI),dyndata.x_nom(im_xt(1)),dyndata.x_nom(im_T3(2)),X(9),  36*au,140,dyndata.x_nom(im_T3(2))-20,dyndata.x_nom(im_T3(2))+20);
[L,e6] = Controller_PI(X(im_T3(2)+NI),TTT,dyndata.u_nom(1),X(6),0.0072562*au,40,0,50);


if t==0 || t==tend
U=[U; [t;L;dyndata.u_nom(2);S1;S2;dyndata.u_nom(5);RV;dyndata.u_nom(7:11);D;B]'];
end

xprime=Kaibel_dxdt(t,[L;dyndata.u_nom(2);S1;S2;dyndata.u_nom(5);RV;dyndata.u_nom(7:11);D;B;X(NI+1:end)]);
xprime=[e1;e2;e3;e4;e5;e6;e7;e8;e9;xprime];