function [sl,sm,sr]=detectobs(sr,sObs)

%%% This function returns the distances from the center of the vehicle
%%% to the nearest object's boundary from three sensors:
%%%     sl - sensor left (-30 deg)
%%%     sm - sensor middle (0 deg)
%%%     sr - sensor right (30 deg)

%%% It assumes sensors of a +/-15 deg range from their orientation
%%%  and a range of 100 pixels.
%%% Please let us know if you modify these settings.


px=sr.xr;
py=sr.yr;
pang=sr.ar;
rr=sr.rr;

xo=sObs.xo;
yo=sObs.yo;
r=sObs.ro;


Dmax=100;
Vo=complex(xo-px,yo-py);
Do=abs(Vo)-r-rr;

Aaux=asin(r./abs(Vo))/pi*180;
 

Ao=angle(Vo)-pang;
[X,Y]=pol2cart(Ao,ones(size(Ao)));
[Ao,R]=cart2pol(X,Y);
Ao=Ao/pi*180;

u=(Ao<=(45+Aaux))&(Ao>=(15-Aaux));
if any(u)
   sl=min(Do(u));
   sl=min(sl,Dmax);
else
   sl=Dmax;
end

u=(Ao<=(15+Aaux))&(Ao>=(-15-Aaux));
if any(u)
   sm=min(Do(u));
   sm=min(sm,Dmax);
else
   sm=Dmax;
end

u=(Ao<=(-15+Aaux))&(Ao>=(-45-Aaux));

if any(u)
   sr=min(Do(u));
   sr=min(sr,Dmax);
else
   sr=Dmax;
end



