%##########################################################################
function [actions,PHASE]=cruise(data)
%##########################################################################
run Constants;
DTK=90;
Vtarget=100;
Htarget=2000;

ias      = data(IAS);
tas      = data(TAS)*1.94384;
roll     = data(ROLL);
track    = data(TRACK);
altitude = data(ALTITUDE)*3.28;
pitch    = data(PITCH);

% LATERAL GUIDANCE --------------------------------------------------------
% GUIDANCE LOOP
error_h=DTK-track;
DROLL=computeRoll(error_h,0.01,tas, -20, 20);

% CONTROL LOOP
error_r=DROLL-roll;
ailerons=controlP(error_r, 0.05, -1, 1);

% VERTICAL GUIDANCE -------------------------------------------------------
% GUIDANCE LOOP
error_a=Htarget-altitude;
DPITCH=computePitch(error_a, 1, tas,-15, 15);

% CONTROL LOOP
error_p=DPITCH-pitch;
elevators=controlP(error_p, 0.001, -1, 1);

% SET ACTIONS--------------------------------------------------------------
actions(AILERONS)=ailerons;   % Ailerons
actions(ELEVATORS)=elevators; % Elevators
actions(RUDDER)=0;            % Rudder
actions(THROTTLE)=0.6;       % Throttle
actions(PARKBRAKE)=0;         % Parkbrake
actions(FLAPS)=0.0;           % Flaps

% SET NEXT FLIGHT PHASE----------------------------------------------------
PHASE=4;

end