Autonomous Robot Problem

Hello… I have an arduino mega and a robot that I want to go straight and when the robot comes across an obstacle in the front ,to the right and to the left ,robot stop for 0.6 seconds and then compute the distances
from right and left.
If the distance from right is bigger than left,then robot turn right for 0,6 second and then robot go forward again.
Else if the distance from leftis bigger than right,then robot turn leftfor 0,6 second and then robot go forward again.
But my problem is that the robot goes forward for 0.5 sec and then stops for ever and I do not why…

Here is my code to understand what I mean:

const int IN_1_back_left = 5;
const int IN_2_back_left = 6;
const int PWM_back_left = 9;
const int IN_1_back_right = 2;
const int IN_2_back_right = 3;
const int PWM_back_right = 4;

boolean enable_forward = true;
boolean enable_stop;
boolean enable_right;
boolean enable_left;
boolean enable_rotate_AUTO;

const int Trig_pin_front = 28;
const int Echo_pin_front = 26;
const int Trig_pin_right = 30;
const int Echo_pin_right = 29;
const int Trig_pin_left = 32;
const int Echo_pin_left = 31;

long duration_front , duration_right , duration_left;
float distance_front , distance_right , distance_left;

unsigned long presentMillis = 0;


void setup()
{
  pinMode(Echo_pin_front , INPUT);
  pinMode(Trig_pin_front , OUTPUT);
  pinMode(Echo_pin_right , INPUT);
  pinMode(Trig_pin_right , OUTPUT);
  pinMode(Echo_pin_left , INPUT);
  pinMode(Trig_pin_left , OUTPUT);
  analogWrite(PWM_back_left , 255);
  analogWrite(PWM_back_right , 255);

  pinMode(PWM_back_left, OUTPUT);
  pinMode(PWM_back_right, OUTPUT);

  pinMode(IN_1_back_left, OUTPUT);
  pinMode(IN_2_back_left, OUTPUT);
  pinMode(IN_1_back_right, OUTPUT);
  pinMode(IN_2_back_right, OUTPUT);
}


void ultrasonic_sensor_forward()
{
  digitalWrite(Trig_pin_front , HIGH);           //ο πομπός διαβάζει τον υπέρηχο (ON)
  delayMicroseconds(11);                   //αναμονη για 11*(10^6) sec =11 μsec.
  digitalWrite(Trig_pin_front , LOW);            //ο πομπός δεν δεχεται κανένα μήνυμα(υπέρηχο) (OFF)

  duration_front = pulseIn(Echo_pin_front , HIGH);     //επιστροφή τιμής "period"
  distance_front = duration_front * 0.034 / 2;         //υπολογισμός απόστασης αισθητήρα - εμποδίου
}


void ultrasonic_sensor_right()
{
  digitalWrite(Trig_pin_right , HIGH);           //ο πομπός διαβάζει τον υπέρηχο (ON)
  delayMicroseconds(11);                   //αναμονη για 11*(10^6) sec =11 μsec.
  digitalWrite(Trig_pin_right , LOW);            //ο πομπός δεν δεχεται κανένα μήνυμα(υπέρηχο) (OFF)

  duration_right = pulseIn(Echo_pin_right , HIGH);     //επιστροφή τιμής "period"
  distance_right = duration_right * 0.034 / 2;         //υπολογισμός απόστασης αισθητήρα - εμποδίου
}


void ultrasonic_sensor_left()
{
  digitalWrite(Trig_pin_left , HIGH);           //ο πομπός διαβάζει τον υπέρηχο (ON)
  delayMicroseconds(11);                   //αναμονη για 11*(10^6) sec =11 μsec.
  digitalWrite(Trig_pin_left , LOW);            //ο πομπός δεν δεχεται κανένα μήνυμα(υπέρηχο) (OFF)

  duration_left = pulseIn(Echo_pin_left , HIGH);     //επιστροφή τιμής "period"
  distance_left = duration_left * 0.034 / 2;         //υπολογισμός απόστασης αισθητήρα - εμποδίου
}



void FORWARD()
{
  digitalWrite(IN_1_back_left , HIGH);      //fordward
  digitalWrite(IN_2_back_left , LOW);
  digitalWrite(IN_1_back_right , HIGH);
  digitalWrite(IN_2_back_right , LOW);


}


void BACKWARD()
{
  digitalWrite(IN_1_back_left , LOW);       //backward
  digitalWrite(IN_2_back_left , HIGH);
  digitalWrite(IN_1_back_right , LOW);
  digitalWrite(IN_2_back_right , HIGH);


}


void STOP()
{
  digitalWrite(IN_1_back_left , LOW);       //stop
  digitalWrite(IN_2_back_left , LOW);
  digitalWrite(IN_1_back_right , LOW);
  digitalWrite(IN_2_back_right , LOW);


}


void RIGHT()
{
  digitalWrite(IN_1_back_left , HIGH);      //right
  digitalWrite(IN_2_back_left , LOW);
  digitalWrite(IN_1_back_right , LOW);
  digitalWrite(IN_2_back_right , HIGH);


}


void LEFT()
{
  digitalWrite(IN_1_back_left , LOW);      //left
  digitalWrite(IN_2_back_left , HIGH);
  digitalWrite(IN_1_back_right , HIGH);
  digitalWrite(IN_2_back_right , LOW);


}


void loop()
{
  unsigned long currentMillis = millis();

  ultrasonic_sensor_forward();
  ultrasonic_sensor_right();
  ultrasonic_sensor_left();

  if (enable_forward)                  //GO FORWARD
  {
    FORWARD();
    if (distance_front <= 10)        //IF DISTANCE <= 10 ,THEN STOP FOR 0,6 SEC AND THEN GO TO THE 
                                                  SECOND IF STATEMENT
    {
      enable_forward = false;
      enable_stop = true;
    }
  }

  if (enable_stop)
  {
    if (currentMillis - presentMillis >= 600)
    {
      STOP();
      enable_stop = false;
      enable_rotate_AUTO = true;
    }
  }
  if (enable_rotate_AUTO)
  {
    if (currentMillis - presentMillis >= 1200)
    {
      presentMillis = currentMillis;
      if (distance_right > distance_left)          //IF DISTANCE FROM RIGHT IS HIGHER THAN LEFT,THEN 
                                                                   TURN RIGHT FOR 0,6 SEC AND THEN FO FORWARD
      {
        RIGHT();
        enable_forward = true;
        enable_rotate_AUTO = false;
      }
      else if (distance_right < distance_left)   //IF DISTANCE FROM LEFT IS HIGHER THAN RIGHT,THEN 
                                                                  TURN LEFT FOR 0,6 SEC AND THEN FO FORWARD
      {
        LEFT();
        enable_forward = true;
        enable_rotate_AUTO = false;
      }
      presentMillis = currentMillis;                //RESET TIMER
    }
  }
}

I want to do it with millis function (not delay)

Thanks…

Without any reporting of the distances, you are in the dark as to what is going on and will not be able to trouble shoot the failure or your logic.

You have got to get some serial output or lcd display of the distances as reported from the ultrasonic sensor code.

For example if distance_left and distance_right are both still 0 because of an sensor issue, you will never reset enable_forward to true and the robot will stay stopped.