Go Down

Topic: maze solver (Read 568 times) previous topic - next topic

fermar1

hi
I want to make a maze solver robot, i completed the mechanical and electronical parts but i have somme problems with the code and i need help its actualy works but not perfectly
here is my code if you have any suggestions please help me   :)  :)  :)  :)  thank you

#define VITESSE 343
int emetteur[3]={8,10,12};//le trig et l'echo de l'ultrason
int recepteur[3]={9,11,13};
unsigned long temps[3];
float distance[3];// la distance mesurée par l'ultrason
const int enable1=3;//PIN qui sert a controle la vitesse
const int in1=2;// deux PIN pour la direction
const int in2=4;
const int enable2=5;
const int in3=6;
const int in4=7;
void setup(){
   pinMode(in1,OUTPUT);// on definit tous les PIN des moteurs
  pinMode(in2,OUTPUT);// comme des sorties
  pinMode(enable2,OUTPUT);
  pinMode(in3,OUTPUT);
  pinMode(in4,OUTPUT);
  pinMode(enable1,OUTPUT);
  for (int i=0;i<3;i++){
    pinMode(emetteur,OUTPUT);// le trig comme sortie
    pinMode(recepteur,INPUT);// l'echo comme entrée
  }
Serial.begin(9600);// l'objet Seri
}
void loop(){
 lecture();
 compare();
}
void compare(){
if (distance[0]>17 && distance[1]>8 && distance[2]>8){
    forward();
  }
  else if(distance[0]>17 && distance[1]<=distance[2]){
    gauche();
  }
  else if(distance[0]>17  &&distance[2]<=distance[1]){
  droite();
  }
 
else if (distance[0]<=17 && (distance[2]<distance[1])){
 
  droite_complet();
}
else if (distance[0]<=17 && (distance[2]>distance[1])){
   
   gauche_complet();
}
else {
Stop();
}
}
void lecture(){ // fonction de lecture des données
  digitalWrite(emetteur[0],HIGH);
  delayMicroseconds(10);
  digitalWrite(emetteur[0],LOW);
  temps[0]=pulseIn(recepteur[0],HIGH,10000);
   distance[0]=(temps[0]/2000000.0)*VITESSE*100;
   if (distance[0]==0){
   distance[0]=50;
   }
   Serial.print(distance[0]);
   Serial.print("    ");
  digitalWrite(emetteur[1],HIGH);
  delayMicroseconds(10);
  digitalWrite(emetteur[1],LOW);
  temps[1]=pulseIn(recepteur[1],HIGH,10000);
   distance[1]=(temps[1]/2000000.0)*VITESSE*100;
   if (distance[1]==0){
   distance[1]=50;
   }
   Serial.print(distance[1]);
   Serial.print("    ");
   digitalWrite(emetteur[2],HIGH);
  delayMicroseconds(10);
  digitalWrite(emetteur[2],LOW);
  temps[2]=pulseIn(recepteur[2],HIGH,10000);
   distance[2]=(temps[2]/2000000.0)*VITESSE*100;
   if (distance[2]==0){
   distance[2]=60;
   }
   Serial.print(distance[2]);
   Serial.print("    ");
   Serial.println("");
}
void forward(){
  digitalWrite(in1,HIGH);
    digitalWrite(in2,LOW);
    analogWrite(enable1,90);
    digitalWrite(in3,HIGH);
    digitalWrite(in4,LOW);
    analogWrite(enable2,120);

}
void droite(){
  digitalWrite(in1,HIGH);
    digitalWrite(in2,LOW);
    analogWrite(enable1,80);
    digitalWrite(in3,HIGH);
    digitalWrite(in4,LOW);
    analogWrite(enable2,180);
 
  }
  void droite_complet(){
  digitalWrite(in1,LOW);
    digitalWrite(in2,HIGH);
    analogWrite(enable1,160);
    digitalWrite(in3,HIGH);
    digitalWrite(in4,LOW);
    analogWrite(enable2,160);
    delay(500);
  }

  void gauche_complet(){
 digitalWrite(in1,HIGH);
    digitalWrite(in2,LOW);
    analogWrite(enable1,160);
    digitalWrite(in3,LOW);
    digitalWrite(in4,HIGH);
    analogWrite(enable2,160);
    delay(500);
 
    }

  void gauche(){
   digitalWrite(in1,HIGH);
    digitalWrite(in2,LOW);
    analogWrite(enable1,130);
    digitalWrite(in3,HIGH);
    digitalWrite(in4,LOW);
    analogWrite(enable2,100);
    }
    void Stop(){
    digitalWrite(in1,HIGH);
    digitalWrite(in2,HIGH);
    analogWrite(enable1,0);
    digitalWrite(in3,HIGH);
    digitalWrite(in4,HIGH);
    analogWrite(enable2,0);
    }

AWOL

The compiler doesn't like italics.
Please edit your post and add the [code][/code] tags you left out.

PaulS

The code you posted does something. You left out what it does.

You have some expectations about what the code should do. You left those out, too.

Go Up