function sfun = slip_fun(VFLx, VFLy, VFRx, VFRy, VRLx, VRLy, VRRx, VRRy, omegaFL, omegaFR, omegaRL, omegaRR)

global Rwf Rwr


%Front left wheel
if omegaFL<0 & VFLx<0 & abs(omegaFL)*Rwf>abs(VFLx)
sFLx = 1 - VFLx/(omegaFL*Rwf);
sFLy = VFLy/abs(omegaFL*Rwf);
elseif omegaFL<0 & VFLx<0 & abs(omegaFL)*Rwf<abs(VFLx)
sFLx = -1 + (omegaFL*Rwf)/VFLx;
sFLy = VFLy/abs(VFLx);
elseif omegaFL>0 & VFLx>0 & abs(omegaFL)*Rwf>abs(VFLx)
sFLx = -1 + VFLx/(omegaFL*Rwf);
sFLy = VFLy/abs(omegaFL*Rwf);
elseif omegaFL>0 & VFLx>0 & abs(omegaFL)*Rwf<abs(VFLx)
sFLx = 1 - (omegaFL*Rwf)/VFLx;
sFLy = VFLy/abs(VFLx);
elseif omegaFL<0 & VFLx>=0
sFLx = 1;
sFLy = VFLy/abs(omegaFL);
elseif omegaFL>0 & VFLx<=0
sFLx = -1;
sFLy = VFLy/abs(omegaFL);
elseif omegaFL==0 & abs(VFLx)>0;
sFLx = sign(VFLx);
sFLy = VFLy/abs(VFLx);
elseif abs(omegaFL)*Rwf==abs(VFLx) & abs(VFLx)>0
sFLx = 0;
sFLy = VFLy/abs(VFLx);
elseif omegaFL==0 & VFLx == 0;
    sFLx = 0;
    sFLy = 0;
end

sFL = sqrt(sFLx^2 + sFLy^2);

%Front right wheel
if omegaFR<0 & VFRx<0 & abs(omegaFR)*Rwf>abs(VFRx)
sFRx = 1 - VFRx/(omegaFR*Rwf);
sFRy = VFRy/abs(omegaFR*Rwf);
elseif omegaFR<0 & VFRx<0 & abs(omegaFR)*Rwf<abs(VFRx)
sFRx = -1 + (omegaFR*Rwf)/VFRx;
sFRy = VFRy/abs(VFRx);
elseif omegaFR>0 & VFRx>0 & abs(omegaFR)*Rwf>abs(VFRx)
sFRx = -1 + VFRx/(omegaFR*Rwf);
sFRy = VFRy/abs(omegaFR*Rwf);
elseif omegaFR>0 & VFRx>0 & abs(omegaFR)*Rwf<abs(VFRx)
sFRx = 1 - (omegaFR*Rwf)/VFRx;
sFRy = VFRy/abs(VFRx);
elseif omegaFR<0 & VFRx>=0
sFRx = 1;
sFRy = VFRy/abs(omegaFR);
elseif omegaFR>0 & VFRx<=0
sFRx = -1;
sFRy = VFRy/abs(omegaFR);
elseif omegaFR==0 & abs(VFRx)>0;
sFRx = sign(VFRx);
sFRy = VFRy/abs(VFRx);
elseif abs(omegaFR)*Rwf==abs(VFRx) & abs(VFRx)>0
sFRx = 0;
sFRy = VFRy/abs(VFRx);
elseif omegaFR==0 & VFRx == 0;
    sFRx = 0;
    sFRy = 0;
end

sFR = sqrt(sFRx^2 + sFRy^2);


%Rear left wheel
if omegaRL<0 & VRLx<0 & abs(omegaRL)*Rwr>abs(VRLx)
sRLx = 1 - VRLx/(omegaRL*Rwr);
sRLy = VRLy/abs(omegaRL*Rwr);
elseif omegaRL<0 & VRLx<0 & abs(omegaRL)*Rwr<abs(VRLx)
sRLx = -1 + (omegaRL*Rwr)/VRLx;
sRLy = VRLy/abs(VRLx);
elseif omegaRL>0 & VRLx>0 & abs(omegaRL)*Rwr>abs(VRLx)
sRLx = -1 + VRLx/(omegaRL*Rwr);
sRLy = VRLy/abs(omegaRL*Rwr);
elseif omegaRL>0 & VRLx>0 & abs(omegaRL)*Rwr<abs(VRLx)
sRLx = 1 - (omegaRL*Rwr)/VRLx;
sRLy = VRLy/abs(VRLx);
elseif omegaRL<0 & VRLx>=0
sRLx = 1;
sRLy = VRLy/abs(omegaRL);
elseif omegaRL>0 & VRLx<=0
sRLx = -1;
sRLy = VRLy/abs(omegaRL);
elseif omegaRL==0 & abs(VRLx)>0;
sRLx = sign(VRLx);
sRLy = VRLy/abs(VRLx);
elseif abs(omegaRL)*Rwr==abs(VRLx) & abs(VRLx)>0
sRLx = 0;
sRLy = VRLy/abs(VRLx);
elseif omegaRL==0 & VRLx == 0;
    sRLx = 0;
    sRLy = 0;
end

sRL = sqrt(sRLx^2 + sRLy^2);

%Rear right wheel
if omegaRR<0 & VRRx<0 & abs(omegaRR)*Rwr>abs(VRRx)
sRRx = 1 - VRRx/(omegaRR*Rwr);
sRRy = VRRy/abs(omegaRR*Rwr);
elseif omegaRR<0 & VRRx<0 & abs(omegaRR)*Rwr<abs(VRRx)
sRRx = -1 + (omegaRR*Rwr)/VRRx;
sRRy = VRRy/abs(VRRx);
elseif omegaRR>0 & VRRx>0 & abs(omegaRR)*Rwr>abs(VRRx)
sRRx = -1 + VRRx/(omegaRR*Rwr);
sRRy = VRRy/abs(omegaRR*Rwr);
elseif omegaRR>0 & VRRx>0 & abs(omegaRR)*Rwr<abs(VRRx)
sRRx = 1 - (omegaRR*Rwr)/VRRx;
sRRy = VRRy/abs(VRRx);
elseif omegaRR<0 & VRRx>=0
sRRx = 1;
sRRy = VRRy/abs(omegaRR);
elseif omegaRR>0 & VRRx<=0
sRRx = -1;
sRRy = VRRy/abs(omegaRR);
elseif omegaRR==0 & abs(VRRx)>0;
sRRx = sign(VRRx);
sRRy = VRRy/abs(VRRx);
elseif abs(omegaRR)*Rwr==abs(VRRx) & abs(VRRx)>0
sRRx = 0;
sRRy = VRRy/abs(VRRx);
elseif omegaRR==0 & VRRx == 0;
    sRRx = 0;
    sRRy = 0;
end

sRR = sqrt(sRRx^2 + sRRy^2);

sfun = [sFLx sFLy sFL sFRx sFRy sFR sRLx sRLy sRL sRRx sRRy sRR]';
