Help with a project !

Hi !
i'm working on a "scout" function (going around without hitting something) for my robot, wich uses 2 360° servomotors as wheels motors.
When it finds an obstacle, it has to calculate where there aren't. the problem is that i can't let him turn left and right because it turns in one direction forever. How can i solve this ? For example it Could be fine if the servos stop after 1 or 2 seconds .
Here's the code :

void Scout(){
int DistanzaCorpo=0, DistanzaTesta=0, DistanzaSinistra=0, DistanzaDestra=0;
DistanzaCorpo = average_value(100, Sensore_Corpo);
while (DistanzaCorpo > DistanzaLimite) {
DistanzaCorpo = average_value(100, Sensore_Corpo);
if (dato=='e') {
DistanzaSinistra = average_value(100, Sensore_Testa);
DistanzaDestra = average_value(100, Sensore_Corpo);
if (DistanzaSinistra >= DistanzaDestra && DistanzaSinistra>15) {
else if (DistanzaDestra >= DistanzaSinistra && DistanzaDestra>15) {
else {

Why are you reading from the Serial port within the function?

You need to post a complete program so we can see the code for all the subsidiary functions.

It would also be useful to have an English language guide to what te code is trying to do.