%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Labskelett för laboration 1c %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% $Revision: 1.4 $
% $Date: 2005/08/18 14:05:37 $

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     Sätter upp motordata     %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

V_D  = 2.290e-3; % Slagvolym för hela motorn
V_im = 2e-3;     % Uppskattad volym hos insugningsröret.

PI_bl = 1.85;
n_r = 2;
R   = 280;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%    Sätter upp fordonsdata    %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

VehicleMass = 1520; % kg
WheelRadius = 0.3;  % m

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Läs in motordata från lab 1a %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

load EngineMap


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%                              %%%
%%% Anpassningar av delmodeller  %%%
%%%                              %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%       Gaspedal till            %%
%% luftmassflödesmodellsanpassning%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

p_amb = 1.01e5;

T_im = mean(EngineMap.T_i);
C_pedal  = V_D/(n_r*R*T_im)*PI_bl*p_amb;
% Jämför förslaget på pedalmodell under 
% laborationstips i laborationskompendiet.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     Beräknat rull-  och      %%%
%%%        luftmotstånd          %%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
F = [0 410 1050]';
v = [0 80 160]';
A = [[1;1;1] v v.^2];
x = A\F;
c_fr1 = x(1);
c_fr2 = x(2);
c_fr3 = x(3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Läser in data för körcykeln  %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

init_drivecycle;

% Inlästa data för europeiska körcykeln:
% DrivingScenario : Matris ur vilken nedanstående information extraherats
% S : Referenshastighet [km/h]
% U : Kopplingens läge 
% G : Vald växel [0-5]
% T : Tidsvektor [s]                  

% Bildar vektorer till förarmodellen
Clutch = [T U];
Gear   = [T max(G,1)];
Speed  = [T S];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ---------------------------------------- %
% Efterbehandling när simuleringen är klar %
% ---------------------------------------- %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     Light-Off beräkning      %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% lightOff =


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%      Beräkna emissioner      %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Argument till calcEmissions
%%  tout      : Tidsvektor från simulink
%%  lambda    : Kontinerligt lambda
%%  Distance  : Körd sträcka i meter
%%  dmacAct   : Luftmassflöde till cylindern i kg/s
%%  dmfAct    : Bränsleflöde till cylinder i kg/s
%%  lightOff  : Tid i sekunder tills light-Off

% calcEmissions(tout, lambda, Distance, dmacAct, dmfcAct, lightOff);

% Beräkna bränsleförbrukningen
% fuelCons = 
  
% disp(sprintf('Bränsleförbrukning: %1.2f [l/(10 mil)]',fuelCons))


