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

function delta = steer_fun(t)

global maxsteer toef toer


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


if t<=0 
    udelta = var_entrada (22);

elseif t>0 && t<=1
    udelta = var_entrada (23); 
    
elseif t>1 && t<=2
    udelta = var_entrada (24);
    
elseif t>2 && t<=3
    udelta = var_entrada (25);
    
elseif t>3 && t<=4
    udelta = var_entrada (26);
    
elseif t>4 && t<=5
    udelta = var_entrada (27); 

elseif t>5 && t<=6
    udelta = var_entrada (28);
    
elseif t>6 && t<=7
    udelta = var_entrada (29);
    
elseif t>7 && t<=8
    udelta = var_entrada (30);  

elseif t>8 && t<=9
    udelta = var_entrada (31);
    
elseif t>9 && t<=10
    udelta = var_entrada (32);    
        
end    


% udelta = 0 si és una recta
% Criteris de signe udelta >0 gira en un sentit, udelta <0 en l'altre
  
delta = maxsteer*udelta*pi/180;
deltaFL = delta - toef;
deltaFR = delta + toef;
deltaRL = -toer;
deltaRR = toer;

delta = [deltaFL deltaFR deltaRL deltaRR]';
