%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 4 Corners Model With Suspension Simulation
% THROTTLE BRAKE INPUT - by Dr. Efstathios Velenis & Bernat Carreras
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function T = accbrk_fun(t, omegaFL, omegaFR, omegaRL, omegaRR)

global BrkConstF BrkConstR AccConstF AccConstR

% Importació variables
type exp.txt;
fileID = fopen('exp.txt','r');
formatSpec = '%f';
sizeA = [Inf 1];
var_entrada = fscanf(fileID,formatSpec)
fclose(fileID);


% Acceleració / Frenada
 
if t<=0 
    uaccbrk = var_entrada (11); %valor en % de l'accelerador

elseif t>0 && t<=1
    uaccbrk = var_entrada (12); 
    
elseif t>1 && t<=2
    uaccbrk = var_entrada (13);
    
elseif t>2 && t<=3
    uaccbrk = var_entrada (14);
    
elseif t>3 && t<=4
    uaccbrk = var_entrada (15);
    
elseif t>4 && t<=5
    uaccbrk = var_entrada (16);

elseif t>5 && t<=6
    uaccbrk = var_entrada (17);
    
elseif t>6 && t<=7
    uaccbrk = var_entrada (18);
    
elseif t>7 && t<=8
    uaccbrk = var_entrada (19);  

elseif t>8 && t<=9
    uaccbrk = var_entrada (20);
    
elseif t>9 && t<=10
    uaccbrk = var_entrada (21);  
        
end    


%Criteris de signe per la funció uaccbrk; >0 frena, <0 accelera
if uaccbrk >=0
    TFL = -uaccbrk*BrkConstF;
    TFR = -uaccbrk*BrkConstF;
    TRL = -uaccbrk*BrkConstR;
    TRR = -uaccbrk*BrkConstR;
elseif uaccbrk<0
    TFL = -uaccbrk*AccConstF;
    TFR = -uaccbrk*AccConstF;
    TRL = -uaccbrk*AccConstR;
    TRR = -uaccbrk*AccConstR;
end

T = [TFL TFR TRL TRR]';
