I'm not entirely clear on your setup.
You have a sharp IR as your only sensor, right? I see you included scan_angle, but you have no code to move the sensor . . .
I'd do something like:
IR=get_sensor_value();
//control robot
if (IR > thresh && scan_angle > 410)//sees something on left
turn_right();
else if (IR > thresh && scan_angle < 390)//sees something on right
turn_left();
else if (IR > thresh)//sees something in front
go reverse();//it will oscillate at the threshold here
//control scanner
if (IR < thresh)//doesn't see anything
rotate_left();
else //sees something
rotate_right();
Its a little bit more complicated than this, and you'll have oscillation issues for sure so you'll have to play around with it.